-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdestroy.spec.js
45 lines (35 loc) · 2.17 KB
/
destroy.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
describe('DSJsonApiAdapter.destroy(resourceConfig, id, options)', function () {
it('should make a DELETE request, with 200 OK response, see : http://jsonapi.org/format/#crud-deleting', function () {
var _this = this;
setTimeout(function () {
assert.equal(1, _this.requests.length);
assert.equal(_this.requests[0].url, 'api/posts/1');
assert.equal(_this.requests[0].method, 'DELETE');
assert.isDefined(_this.requests[0].requestHeaders);
assert.notInclude(_this.requests[0].requestHeaders['Content-Type'], 'application/vnd.api+json', 'Contains json api content-type header');
// see : http://jsonapi.org/format/#crud-deleting deleting and returning a 200 result!
var responseData = new DSJsonApiAdapter.JsonApi.JsonApiRequest()
.WithMeta('Destroy', 'Ok');
delete responseData.data;
var response = DSUtils.toJson(responseData);
_this.requests[0].respond(200, { 'Content-Type': 'application/vnd.api+json' }, response);
}, 30);
return dsHttpAdapter.destroy(Post, 1).then(function (data) {
assert.equal(data, null, 'post should have been deleted');
});
});
it('should make a DELETE request, with 204 OK NoContent response', function () {
var _this = this;
setTimeout(function () {
assert.equal(1, _this.requests.length);
assert.equal(_this.requests[0].url, 'api2/posts/1');
assert.equal(_this.requests[0].method, 'DELETE');
assert.isDefined(_this.requests[0].requestHeaders);
assert.notInclude(_this.requests[0].requestHeaders['Content-Type'], 'application/vnd.api+json', 'Contains json api content-type header');
_this.requests[0].respond(204, { 'Content-Type': 'application/vnd.api+json' });
}, 30);
return dsHttpAdapter.destroy(Post, 1, { basePath: 'api2' }).then(function (data) {
assert.equal(data, null, 'post should have been deleted, correct response when server returns "Ok NoContent(204)" response');
});
});
});