Skip to content

Commit de3996b

Browse files
committed
Some test fixes.
1 parent 147c4f6 commit de3996b

File tree

7 files changed

+87
-47
lines changed

7 files changed

+87
-47
lines changed

test/integration/datastore/DSCacheFactory.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('DSCacheFactory integration', function () {
88

99
it('should get an item from the server and delete when using DSCacheFactory in passive mode', function (done) {
1010
DS.defineResource({
11-
name: 'comment',
11+
name: 'Comment',
1212
endpoint: '/comments',
1313
deleteOnExpire: 'passive',
1414
maxAge: 20
@@ -19,7 +19,7 @@ describe('DSCacheFactory integration', function () {
1919
text: 'test'
2020
});
2121

22-
DS.find('comment', 5).then(function (comment) {
22+
DS.find('Comment', 5).then(function (comment) {
2323
assert.deepEqual(comment, {
2424
id: 5,
2525
text: 'test'
@@ -31,15 +31,15 @@ describe('DSCacheFactory integration', function () {
3131

3232
$httpBackend.flush();
3333

34-
assert.deepEqual(DS.get('comment', 5), {
34+
assert.deepEqual(DS.get('Comment', 5), {
3535
id: 5,
3636
text: 'test'
3737
}, 'The comment is now in the store');
38-
assert.isNumber(DS.lastModified('comment', 5));
39-
assert.isNumber(DS.lastSaved('comment', 5));
38+
assert.isNumber(DS.lastModified('Comment', 5));
39+
assert.isNumber(DS.lastSaved('Comment', 5));
4040

4141
setTimeout(function () {
42-
assert.isUndefined(DS.get('comment', 5));
42+
assert.isUndefined(DS.get('Comment', 5));
4343

4444
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
4545
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
@@ -51,7 +51,7 @@ describe('DSCacheFactory integration', function () {
5151
});
5252
it('should get an item from the server and delete when using DSCacheFactory in aggressive mode', function (done) {
5353
DS.defineResource({
54-
name: 'comment',
54+
name: 'Comment',
5555
endpoint: '/comments',
5656
deleteOnExpire: 'aggressive',
5757
recycleFreq: 10,
@@ -63,7 +63,7 @@ describe('DSCacheFactory integration', function () {
6363
text: 'test'
6464
});
6565

66-
DS.find('comment', 5).then(function (comment) {
66+
DS.find('Comment', 5).then(function (comment) {
6767
assert.deepEqual(comment, {
6868
id: 5,
6969
text: 'test'
@@ -75,15 +75,15 @@ describe('DSCacheFactory integration', function () {
7575

7676
$httpBackend.flush();
7777

78-
assert.deepEqual(DS.get('comment', 5), {
78+
assert.deepEqual(DS.get('Comment', 5), {
7979
id: 5,
8080
text: 'test'
8181
}, 'The comment is now in the store');
82-
assert.isNumber(DS.lastModified('comment', 5));
83-
assert.isNumber(DS.lastSaved('comment', 5));
82+
assert.isNumber(DS.lastModified('Comment', 5));
83+
assert.isNumber(DS.lastSaved('Comment', 5));
8484

8585
setTimeout(function () {
86-
assert.isUndefined(DS.get('comment', 5));
86+
assert.isUndefined(DS.get('Comment', 5));
8787

8888
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
8989
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');

test/integration/datastore/async_methods/create.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,44 @@ describe('DS.create(resourceName, attrs[, options])', function () {
4040
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
4141
assert.deepEqual(DS.get('post', 5), p1);
4242
});
43+
it('should create an item that includes relations, save them to the server and inject the results', function () {
44+
var payload = {
45+
id: 99,
46+
name: 'Sally',
47+
profile: {
48+
id: 999,
49+
userId: 99,
50+
51+
}
52+
};
53+
54+
$httpBackend.expectPOST('http://test.angular-cache.com/user').respond(200, payload);
55+
56+
DS.create('user', {
57+
name: 'Sally',
58+
profile: {
59+
60+
}
61+
}).then(function (user) {
62+
assert.deepEqual(user, payload, 'user should have been created');
63+
}, function (err) {
64+
console.error(err.stack);
65+
fail('should not have rejected');
66+
});
67+
68+
$httpBackend.flush();
69+
70+
assert.equal(lifecycle.beforeCreate.callCount, 1, 'beforeCreate should have been called twice');
71+
assert.equal(lifecycle.afterCreate.callCount, 1, 'afterCreate should have been called twice');
72+
assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called twice');
73+
assert.equal(lifecycle.afterInject.callCount, 2, 'afterInject should have been called twice');
74+
assert.equal(lifecycle.serialize.callCount, 1, 'serialize should have been called');
75+
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
76+
assert.deepEqual(DS.get('user', 99), payload);
77+
assert.deepEqual(DS.get('profile', 999), {
78+
id: 999,
79+
userId: 99,
80+
81+
});
82+
});
4383
});

test/integration/datastore/async_methods/findAll.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('DS.findAll(resourceName, params[, options]): ', function () {
175175
};
176176

177177
DS.defineResource({
178-
name: 'user',
178+
name: 'person',
179179
endpoint: 'users',
180180
methods: {
181181
fullName: function () {
@@ -186,13 +186,13 @@ describe('DS.findAll(resourceName, params[, options]): ', function () {
186186

187187
$httpBackend.expectGET(/http:\/\/test\.angular-cache\.com\/users\??/).respond(200, [u1, u2]);
188188

189-
DS.findAll('user').then(function (data) {
189+
DS.findAll('person').then(function (data) {
190190
assert.deepEqual(data, [
191-
DSUtils.deepMixIn(new DS.definitions.user[DS.definitions.user.class](), u1),
192-
DSUtils.deepMixIn(new DS.definitions.user[DS.definitions.user.class](), u2)
191+
DSUtils.deepMixIn(new DS.definitions.person[DS.definitions.person.class](), u1),
192+
DSUtils.deepMixIn(new DS.definitions.person[DS.definitions.person.class](), u2)
193193
]);
194-
angular.forEach(data, function (user) {
195-
assert.isTrue(user instanceof DS.definitions.user[DS.definitions.user.class], 'should be an instance of User');
194+
angular.forEach(data, function (person) {
195+
assert.isTrue(person instanceof DS.definitions.person[DS.definitions.person.class], 'should be an instance of User');
196196
});
197197
}, function (err) {
198198
console.error(err.message);
@@ -201,9 +201,9 @@ describe('DS.findAll(resourceName, params[, options]): ', function () {
201201

202202
$httpBackend.flush();
203203

204-
assert.deepEqual(DS.filter('user'), [
205-
DSUtils.deepMixIn(new DS.definitions.user[DS.definitions.user.class](), u1),
206-
DSUtils.deepMixIn(new DS.definitions.user[DS.definitions.user.class](), u2)
204+
assert.deepEqual(DS.filter('person'), [
205+
DSUtils.deepMixIn(new DS.definitions.person[DS.definitions.person.class](), u1),
206+
DSUtils.deepMixIn(new DS.definitions.person[DS.definitions.person.class](), u2)
207207
], 'The users are now in the store');
208208

209209
assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called');

test/integration/datastore/cacheFactory.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ describe('$cacheFactory integration', function () {
44

55
it('should use $cacheFactory when DSCacheFactory is not available', function (done) {
66
DS.defineResource({
7-
name: 'comment',
7+
name: 'Comment',
88
endpoint: '/comments',
99
deleteOnExpire: 'passive',
1010
maxAge: 20
1111
});
1212

13-
var cache = DS.cacheFactory.get('DS.comment');
13+
var cache = DS.cacheFactory.get('DS.Comment');
1414

1515
assert.equal(typeof DS.cacheFactory.touch, 'undefined', 'should not be using DSCacheFactory');
1616

@@ -19,7 +19,7 @@ describe('$cacheFactory integration', function () {
1919
text: 'test'
2020
});
2121

22-
DS.find('comment', 5).then(function (comment) {
22+
DS.find('Comment', 5).then(function (comment) {
2323
assert.deepEqual(comment, {
2424
id: 5,
2525
text: 'test'
@@ -32,12 +32,12 @@ describe('$cacheFactory integration', function () {
3232

3333
$httpBackend.flush();
3434

35-
assert.deepEqual(DS.get('comment', 5), {
35+
assert.deepEqual(DS.get('Comment', 5), {
3636
id: 5,
3737
text: 'test'
3838
}, 'The comment is now in the store');
39-
assert.isNumber(DS.lastModified('comment', 5));
40-
assert.isNumber(DS.lastSaved('comment', 5));
39+
assert.isNumber(DS.lastModified('Comment', 5));
40+
assert.isNumber(DS.lastSaved('Comment', 5));
4141

4242
setTimeout(function () {
4343
assert.deepEqual(cache.get(5), {

test/integration/datastore/sync_methods/defineResource.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ describe('DS.defineResource(definition)', function () {
5656
};
5757

5858
DS.defineResource({
59-
name: 'comment',
59+
name: 'Comment',
6060
baseUrl: 'hello/',
6161
validate: test.validate
6262
});
6363

6464
assert.doesNotThrow(function () {
65-
assert.isUndefined(DS.get('comment', 5), 'should be undefined');
65+
assert.isUndefined(DS.get('Comment', 5), 'should be undefined');
6666
});
6767

6868
// Should override global baseUrl
69-
$httpBackend.expectGET('hello/comment/1').respond(200, { name: 'Sally', id: 1 });
69+
$httpBackend.expectGET('hello/Comment/1').respond(200, { name: 'Sally', id: 1 });
7070

71-
assert.isUndefined(DS.get('comment', 1, { loadFromServer: true }), 'should be undefined');
71+
assert.isUndefined(DS.get('Comment', 1, { loadFromServer: true }), 'should be undefined');
7272

7373
$httpBackend.flush();
7474

75-
assert.deepEqual(DS.get('comment', 1), { name: 'Sally', id: 1 });
75+
assert.deepEqual(DS.get('Comment', 1), { name: 'Sally', id: 1 });
7676

77-
$httpBackend.expectPOST('hello/comment').respond(200, { name: 'John', id: 2 });
77+
$httpBackend.expectPOST('hello/Comment').respond(200, { name: 'John', id: 2 });
7878

79-
DS.create('comment', { name: 'John' }).then(function (comment) {
79+
DS.create('Comment', { name: 'John' }).then(function (comment) {
8080
assert.deepEqual(comment, { name: 'John', id: 2 });
8181
});
8282

@@ -87,31 +87,31 @@ describe('DS.defineResource(definition)', function () {
8787
});
8888
it('should allow custom behavior to be applied to resources', function () {
8989
DS.defineResource({
90-
name: 'user',
90+
name: 'person',
9191
methods: {
9292
fullName: function () {
9393
return this.first + ' ' + this.last;
9494
}
9595
}
9696
});
9797

98-
DS.inject('user', {
98+
DS.inject('person', {
9999
first: 'John',
100100
last: 'Anderson',
101101
id: 1
102102
});
103103

104-
var user = DS.get('user', 1);
104+
var user = DS.get('person', 1);
105105

106106
assert.deepEqual(JSON.stringify(user), JSON.stringify({
107107
first: 'John',
108108
last: 'Anderson',
109109
id: 1
110110
}));
111111
assert.equal(user.fullName(), 'John Anderson');
112-
assert.isTrue(user instanceof DS.definitions.user[DS.definitions.user.class]);
113-
assert.equal(DS.definitions.user.class, 'User');
114-
assert.equal(DS.definitions.user[DS.definitions.user.class].name, 'User');
112+
assert.isTrue(user instanceof DS.definitions.person[DS.definitions.person.class]);
113+
assert.equal(DS.definitions.person.class, 'Person');
114+
assert.equal(DS.definitions.person[DS.definitions.person.class].name, 'Person');
115115
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
116116
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
117117
});

test/integration/datastore/sync_methods/filter.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ describe('DS.filter(resourceName[, params][, options])', function () {
324324
});
325325
it('should allow custom filter function', function () {
326326
DS.defineResource({
327-
name: 'comment',
327+
name: 'Comment',
328328
filter: function (collection, resourceName, params, options) {
329329
var filtered = collection;
330330
var where = params.where;
@@ -335,10 +335,10 @@ describe('DS.filter(resourceName[, params][, options])', function () {
335335
}
336336
});
337337
assert.doesNotThrow(function () {
338-
DS.inject('comment', p1);
339-
DS.inject('comment', p2);
340-
DS.inject('comment', p3);
341-
DS.inject('comment', p4);
338+
DS.inject('Comment', p1);
339+
DS.inject('Comment', p2);
340+
DS.inject('Comment', p3);
341+
DS.inject('Comment', p4);
342342
}, Error, 'should not throw an error');
343343

344344
var params = {
@@ -352,6 +352,6 @@ describe('DS.filter(resourceName[, params][, options])', function () {
352352
}
353353
};
354354

355-
assert.deepEqual(DS.filter('comment', params), [p1, p2], 'should keep p1 and p2');
355+
assert.deepEqual(DS.filter('Comment', params), [p1, p2], 'should keep p1 and p2');
356356
});
357357
});

test/integration/datastore/sync_methods/inject.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('DS.inject(resourceName, attrs[, options])', function () {
6565
assert.deepEqual(DS.get('post', 7), p3);
6666
assert.deepEqual(DS.get('post', 8), p4);
6767
});
68-
it.only('should inject relations', function () {
68+
it('should inject relations', function () {
6969
// can inject items without relations
7070
DS.inject('user', user1);
7171
DS.inject('organization', organization2);

0 commit comments

Comments
 (0)