-
Notifications
You must be signed in to change notification settings - Fork 76
/
index.test.js
62 lines (48 loc) · 2.07 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
describe('DS.refresh(resourceName, id[, options]): ', function () {
var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
it('should throw an error when method pre-conditions are not met', function (done) {
assert.throws(function () {
DS.refresh('does not exist', 5);
}, DS.errors.RuntimeError, errorPrefix + 'does not exist is not a registered resource!');
angular.forEach(TYPES_EXCEPT_STRING_OR_NUMBER, function (key) {
assert.throws(function () {
DS.refresh('post', key);
}, DS.errors.IllegalArgumentError, errorPrefix + 'id: Must be a string or a number!');
});
angular.forEach(TYPES_EXCEPT_OBJECT, function (key) {
if (key) {
assert.throws(function () {
DS.refresh('post', 5, key);
}, DS.errors.IllegalArgumentError, errorPrefix + 'options: Must be an object!');
}
});
done();
});
it('should get an item from the server', function (done) {
// Should do nothing because the data isn't in the store
assert.isFalse(DS.refresh('post', 5));
assert.isUndefined(DS.get('post', 5), 'The post should not be in the store yet');
DS.inject('post', p1);
assert.deepEqual(DS.get('post', 5), p1, 'The post is now in the store');
var initialLastModified = DS.lastModified('post', 5);
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(200, { author: 'John', age: 31, id: 5 });
// Should refresh the item that's in the store
DS.refresh('post', 5).then(function (post) {
assert.deepEqual(post, { author: 'John', age: 31, id: 5 });
}, function (err) {
console.error(err.stack);
fail('Should not have rejected!');
});
// Should have no effect because the request is already pending
DS.refresh('post', 5).then(function (post) {
assert.deepEqual(post, { author: 'John', age: 31, id: 5 });
}, function (err) {
console.error(err.stack);
fail('Should not have rejected!');
});
$httpBackend.flush();
assert.deepEqual(DS.get('post', 5), { author: 'John', age: 31, id: 5 }, 'The post has been refreshed');
assert.notEqual(DS.lastModified('post', 5), initialLastModified);
done();
});
});