backend_srv-specs.js 851 B

123456789101112131415161718192021222324252627282930313233
  1. define([
  2. 'app/core/config',
  3. 'app/core/services/backend_srv'
  4. ], function() {
  5. 'use strict';
  6. describe('backend_srv', function() {
  7. var _backendSrv;
  8. var _http;
  9. var _httpBackend;
  10. beforeEach(module('grafana.core'));
  11. beforeEach(module('grafana.services'));
  12. beforeEach(inject(function ($httpBackend, $http, backendSrv) {
  13. _httpBackend = $httpBackend;
  14. _http = $http;
  15. _backendSrv = backendSrv;
  16. }));
  17. describe('when handling errors', function() {
  18. it('should return the http status code', function(done) {
  19. _httpBackend.whenGET('gateway-error').respond(502);
  20. _backendSrv.datasourceRequest({
  21. url: 'gateway-error'
  22. }).catch(function(err) {
  23. expect(err.status).to.be(502);
  24. done();
  25. });
  26. _httpBackend.flush();
  27. });
  28. });
  29. });
  30. });