-
Notifications
You must be signed in to change notification settings - Fork 76
/
index.test.js
47 lines (36 loc) · 1.66 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
describe('DS.get(resourceName, id[, options])', function () {
var errorPrefix = 'DS.get(resourceName, id[, options]): ';
it('should throw an error when method pre-conditions are not met', function (done) {
assert.throw(function () {
DS.get('does not exist', {});
}, DS.errors.RuntimeError, errorPrefix + 'does not exist is not a registered resource!');
angular.forEach(TYPES_EXCEPT_STRING_OR_NUMBER, function (key) {
assert.throw(function () {
DS.get('post', key);
}, DS.errors.IllegalArgumentError, errorPrefix + 'id: Must be a string or a number!');
});
angular.forEach(TYPES_EXCEPT_OBJECT, function (key) {
if (key) {
assert.throw(function () {
DS.get('post', 5, key);
}, DS.errors.IllegalArgumentError, errorPrefix + 'options: Must be an object!');
}
});
done();
});
it('should return undefined if the query has never been made before', function (done) {
assert.isUndefined(DS.get('post', 5), 'should be undefined');
done();
});
it('should return undefined and send the query to the server if the query has never been made before and loadFromServer is set to true', function (done) {
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(200, p1);
assert.isUndefined(DS.get('post', 5, { loadFromServer: true }), 'should be undefined');
// There should only be one GET request, so this should have no effect.
assert.isUndefined(DS.get('post', 5, { loadFromServer: true }), 'should be undefined');
$httpBackend.flush();
assert.deepEqual(DS.get('post', 5), p1, 'p1 should now be in the store');
assert.isNumber(DS.lastModified('post', 5));
assert.isNumber(DS.lastSaved('post', 5));
done();
});
});