Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9124870

Browse files
committed
Added unit test for ngResource.hasBody.
1 parent be8aeeb commit 9124870

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/ngResource/resourceSpec.js

+37
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,43 @@ describe('basic usage', function() {
9797
$httpBackend.flush();
9898
});
9999

100+
it('should include a request body when calling custom delete with hasBody is true', function() {
101+
var condition = {at: "2038-01-19 03:14:08"}
102+
$httpBackend.expect('DELETE', '/fooresource', condition).respond({});
103+
104+
var r = $resource('/fooresource', {}, {
105+
delete: {method: 'DELETE', hasBody: true}
106+
});
107+
108+
var deleteResponse = r.delete(condition);
109+
110+
$httpBackend.flush();
111+
112+
expect(deleteResponse.$resolved).toBe(true);
113+
});
114+
115+
it('should expect a body if hasBody is true', function() {
116+
var username = "yathos";
117+
var loginRequest = {name: username, password: "Smile"};
118+
var user = {id: 1, name: username};
119+
120+
$httpBackend.expect('LOGIN', '/user/me', loginRequest).respond(user);
121+
122+
$httpBackend.expect('LOGOUT', '/user/me', null).respond(null);
123+
124+
var UserService = $resource('/user/me', {}, {
125+
login: {method: 'LOGIN', hasBody: true},
126+
logout: {method: 'LOGOUT', hasBody: false}
127+
});
128+
129+
var loginResponse = UserService.login(loginRequest);
130+
var logoutResponse = UserService.logout();
131+
132+
$httpBackend.flush();
133+
134+
expect(loginResponse.id).toBe(user.id);
135+
expect(logoutResponse.$resolved).toBe(true);
136+
});
100137

101138
it('should build resource', function() {
102139
expect(typeof CreditCard).toBe('function');

0 commit comments

Comments
 (0)