Skip to content

Commit a97c769

Browse files
committed
Updated nested endpoint tests to cover more use cases. #40.
1 parent 549cd8b commit a97c769

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,21 @@ describe('DS.create(resourceName, attrs[, options])', function () {
177177
});
178178

179179
$httpBackend.flush();
180+
181+
$httpBackend.expectPOST('http://test.angular-cache.com/comment').respond(200, testComment2);
182+
183+
DS.create('comment', {
184+
content: 'test',
185+
parentKey: 4
186+
}, {
187+
nested: false
188+
}).then(function (comment) {
189+
assert.deepEqual(comment, testComment2);
190+
assert.deepEqual(comment, DS.get('comment', 6));
191+
}, function () {
192+
fail('Should not have failed!');
193+
});
194+
195+
$httpBackend.flush();
180196
});
181197
});

test/integration/datastore/async_methods/destroy.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,19 @@ describe('DS.destroy(resourceName, id)', function () {
8080
});
8181

8282
$httpBackend.flush();
83+
84+
$httpBackend.expectDELETE('http://test.angular-cache.com/comment/6').respond(204);
85+
86+
DS.inject('comment', testComment2);
87+
88+
DS.destroy('comment', 6, {
89+
nested: false
90+
}).then(function () {
91+
}, function (err) {
92+
console.log(err);
93+
fail('Should not have failed!');
94+
});
95+
96+
$httpBackend.flush();
8397
});
8498
});

test/integration/datastore/async_methods/destroyAll.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,20 @@ describe('DS.destroyAll(resourceName, params[, options]): ', function () {
102102
});
103103

104104
$httpBackend.flush();
105+
106+
$httpBackend.expectDELETE('http://test.angular-cache.com/comment?content=test').respond(204);
107+
108+
DS.destroyAll('comment', {
109+
content: 'test'
110+
}, {
111+
parentKey: 4,
112+
nested: false
113+
}).then(function () {
114+
}, function (err) {
115+
console.log(err);
116+
fail('Should not have failed!');
117+
});
118+
119+
$httpBackend.flush();
105120
});
106121
});

test/integration/datastore/async_methods/find.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,19 @@ describe('DS.find(resourceName, id[, options]): ', function () {
144144
});
145145

146146
$httpBackend.flush();
147+
148+
$httpBackend.expectGET('http://test.angular-cache.com/comment/5').respond(200, testComment);
149+
150+
DS.find('comment', 5, {
151+
nested: false,
152+
bypassCache: true
153+
}).then(function (comment) {
154+
assert.deepEqual(comment, testComment);
155+
assert.deepEqual(comment, DS.get('comment', 5));
156+
}, function () {
157+
fail('Should not have failed!');
158+
});
159+
160+
$httpBackend.flush();
147161
});
148162
});

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

+21
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,26 @@ describe('DS.findAll(resourceName, params[, options]): ', function () {
280280
});
281281

282282
$httpBackend.flush();
283+
284+
DS.ejectAll('comment');
285+
286+
$httpBackend.expectGET('http://test.angular-cache.com/comment?content=test').respond(200, [testComment, testComment2]);
287+
288+
DS.findAll('comment', {
289+
content: 'test'
290+
}, {
291+
parentKey: 4,
292+
bypassCache: true,
293+
nested: false
294+
}).then(function (comments) {
295+
assert.deepEqual(comments, [testComment, testComment2]);
296+
assert.deepEqual(comments, DS.filter('comment', {
297+
content: 'test'
298+
}));
299+
}, function () {
300+
fail('Should not have failed!');
301+
});
302+
303+
$httpBackend.flush();
283304
});
284305
});

test/integration/datastore/async_methods/update.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,23 @@ describe('DS.update(resourceName, id, attrs[, options])', function () {
131131
});
132132

133133
$httpBackend.flush();
134+
135+
$httpBackend.expectPUT('http://test.angular-cache.com/comment/6').respond(200, testComment2);
136+
137+
DS.inject('comment', testComment2);
138+
139+
DS.update('comment', 6, {
140+
content: 'stuff'
141+
}, {
142+
parentKey: 4,
143+
nested: false
144+
}).then(function (comment) {
145+
assert.deepEqual(comment, testComment2);
146+
assert.deepEqual(comment, DS.get('comment', 6));
147+
}, function () {
148+
fail('Should not have failed!');
149+
});
150+
151+
$httpBackend.flush();
134152
});
135153
});

test/integration/datastore/async_methods/updateAll.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,30 @@ describe('DS.updateAll(resourceName, attrs, params[, options])', function () {
149149
});
150150

151151
$httpBackend.flush();
152+
153+
DS.ejectAll('comment');
154+
155+
$httpBackend.expectPUT('http://test.angular-cache.com/comment?content=test').respond(200, [testComment, testComment2]);
156+
157+
DS.inject('comment', testComment2);
158+
159+
DS.updateAll('comment', {
160+
content: 'stuff'
161+
}, {
162+
content: 'test'
163+
}, {
164+
parentKey: 4,
165+
nested: false
166+
}).then(function (comments) {
167+
assert.deepEqual(comments, [testComment, testComment2]);
168+
assert.deepEqual(comments, DS.filter('comment', {
169+
content: 'stuff',
170+
sort: 'id'
171+
}));
172+
}, function () {
173+
fail('Should not have failed!');
174+
});
175+
176+
$httpBackend.flush();
152177
});
153178
});

0 commit comments

Comments
 (0)