-
Notifications
You must be signed in to change notification settings - Fork 76
/
index.test.js
45 lines (37 loc) · 1.51 KB
/
index.test.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('DS.destroy(resourceName, id)', function () {
var errorPrefix = 'DS.destroy(resourceName, id): ';
it('should throw an error when method pre-conditions are not met', function (done) {
DS.destroy('does not exist', 5).then(function () {
fail('should have rejected');
}, function (err) {
assert.isTrue(err instanceof DS.errors.RuntimeError);
assert.equal(err.message, errorPrefix + 'does not exist is not a registered resource!');
});
angular.forEach(TYPES_EXCEPT_STRING_OR_NUMBER, function (key) {
DS.destroy('post', key).then(function () {
fail('should have rejected');
}, function (err) {
assert.isTrue(err instanceof DS.errors.IllegalArgumentError);
assert.equal(err.message, errorPrefix + 'id: Must be a string or a number!');
});
});
done();
});
it('should delete an item from the data store', function (done) {
$httpBackend.expectDELETE('http://test.angular-cache.com/posts/5').respond(200, 5);
DS.inject('post', p1);
DS.destroy('post', 5).then(function (id) {
assert.equal(id, 5, 'post 5 should have been deleted');
}, function (err) {
console.error(err.stack);
fail('should not have rejected');
});
$httpBackend.flush();
assert.equal(lifecycle.beforeDestroy.callCount, 1, 'beforeDestroy should have been called');
assert.equal(lifecycle.afterDestroy.callCount, 1, 'afterDestroy should have been called');
assert.isUndefined(DS.get('post', 5));
assert.equal(DS.lastModified('post', 5), 0);
assert.equal(DS.lastSaved('post', 5), 0);
done();
});
});