Repository URL to install this package:
|
Version:
1.0.4 ▾
|
describe("API", function() {
beforeEach(module('angularGobox'));
var API, $rootScope, http;
beforeEach(inject(function(_API_, _$rootScope_, $httpBackend) {
API = _API_;
$rootScope = _$rootScope_;
http = $httpBackend;
}));
afterEach(function() {
http.verifyNoOutstandingExpectation();
http.verifyNoOutstandingRequest();
});
it("makes a GET request", function() {
http.expectGET('/api/v1/test/').respond();
API.get('/test/');
http.flush();
});
it("makes a GET request with params", function() {
http.expectGET('/api/v1/test/?thing=value').respond();
API.get('/test/', { thing: 'value' });
http.flush();
});
it('makes a POST request with params', function() {
var params = { thing: 'value' };
http.expectPOST('/api/v1/test/', params).respond();
API.post('/test/', params);
http.flush();
});
it('makes a PUT request with params', function() {
var params = { thing: 'value' };
http.expectPUT('/api/v1/test/', params).respond();
API.put('/test/', params);
http.flush();
});
it('makes a PATCH request with params', function() {
var params = { thing: 'value' };
http.expectPATCH('/api/v1/test/', params).respond();
API.patch('/test/', params);
http.flush();
});
it('makes a DELETE request with params', function() {
http.expectDELETE('/api/v1/test/').respond();
API.delete('/test/');
http.flush();
});
describe("token", function() {
it("sends an Authorization header with token", function() {
http.expectGET('/api/v1/test/', {
'Authorization': 'Token TOKEN',
'Accept': 'application/json'
}).respond();
API.token = 'TOKEN';
API.get('/test/');
http.flush();
});
});
describe('authorize', function() {
it("sends a post request for a token", function() {
var username = 'customer@example.com';
var password = '1234';
http.expectPOST('/api/v1/api-token-auth/', {
username: username,
password: password
}).respond({
token: 'RETURNED_TOKEN'
});
API.authorize(username, password);
http.flush();
expect(API.token).toEqual('RETURNED_TOKEN');
});
});
});