Skip to content

Commit b02201a

Browse files
committed
test: actions with $limit work properly
It was asserted in #345 that select is not working. This adds tests for `query.$select` on the `find` action with and without pagination. The tests are passing without any further changes, so we’ll need to investigate more.
1 parent faa8554 commit b02201a

File tree

2 files changed

+109
-44
lines changed

2 files changed

+109
-44
lines changed

test/service-module/service-module.actions.test.ts

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,36 @@ describe('Service Module - Actions', () => {
191191

192192
actions.find
193193
.call({ $store: store }, { query: { $limit: 1 } })
194+
.then(response => {
195+
const returnedRecord = JSON.parse(JSON.stringify(response[0]))
196+
assert(response.length === 1, 'only one record was returned')
197+
assert.deepEqual(
198+
returnedRecord,
199+
{ id: 0, description: 'Do the first', isComplete: false },
200+
'the first record was returned'
201+
)
202+
done()
203+
})
204+
})
205+
206+
it('find with $select', done => {
207+
const { makeServicePlugin, Todo } = makeContext()
208+
const store = new Vuex.Store<RootState>({
209+
plugins: [
210+
makeServicePlugin({
211+
servicePath: 'my-todos',
212+
Model: Todo,
213+
service: feathersClient.service('my-todos')
214+
})
215+
]
216+
})
217+
const actions = mapActions('my-todos', ['find'])
218+
219+
actions.find
220+
.call(
221+
{ $store: store },
222+
{ query: { $limit: 1, $select: ['id', 'description'] } }
223+
)
194224
.then(response => {
195225
const returnedRecord = JSON.parse(JSON.stringify(response[0]))
196226
assert(response.length === 1, 'only one record was returned')
@@ -223,7 +253,7 @@ describe('Service Module - Actions', () => {
223253
assert(response.length === 1, 'one record was returned')
224254
assert.deepEqual(
225255
returnedRecord,
226-
{ id: 9, description: 'Do the tenth' },
256+
{ id: 9, description: 'Do the tenth', isComplete: false },
227257
'the tenth record was returned'
228258
)
229259
done()
@@ -250,7 +280,7 @@ describe('Service Module - Actions', () => {
250280
assert(response.length === 1, 'one record was returned')
251281
assert.deepEqual(
252282
returnedRecord,
253-
{ id: 8, description: 'Do the ninth' },
283+
{ id: 8, description: 'Do the ninth', isComplete: false },
254284
'the ninth record was returned'
255285
)
256286
done()
@@ -274,6 +304,39 @@ describe('Service Module - Actions', () => {
274304

275305
actions.find
276306
.call({ $store: store }, { query: { $limit: 1 } })
307+
.then(response => {
308+
const returnedRecord = JSON.parse(JSON.stringify(response.data[0]))
309+
assert(response.data.length === 1, 'only one record was returned')
310+
assert.deepEqual(
311+
returnedRecord,
312+
{ id: 0, description: 'Do the first', isComplete: false },
313+
'the first record was returned'
314+
)
315+
assert(response.limit === 1, 'limit was correct')
316+
assert(response.skip === 0, 'skip was correct')
317+
assert(response.total === 10, 'total was correct')
318+
done()
319+
})
320+
})
321+
322+
it('find with $select', done => {
323+
const { makeServicePlugin, Task } = makeContext()
324+
const store = new Vuex.Store<RootState>({
325+
plugins: [
326+
makeServicePlugin({
327+
servicePath: 'my-tasks',
328+
Model: Task,
329+
service: feathersClient.service('my-tasks')
330+
})
331+
]
332+
})
333+
const actions = mapActions('my-tasks', ['find'])
334+
335+
actions.find
336+
.call(
337+
{ $store: store },
338+
{ query: { $limit: 1, $select: ['id', 'description'] } }
339+
)
277340
.then(response => {
278341
const returnedRecord = JSON.parse(JSON.stringify(response.data[0]))
279342
assert(response.data.length === 1, 'only one record was returned')
@@ -309,7 +372,7 @@ describe('Service Module - Actions', () => {
309372
assert(response.data.length === 1, 'only one record was returned')
310373
assert.deepEqual(
311374
returnedRecord,
312-
{ id: 9, description: 'Do the tenth' },
375+
{ id: 9, description: 'Do the tenth', isComplete: false },
313376
'the tenth record was returned'
314377
)
315378
assert(response.limit === 10, 'limit was correct')
@@ -339,7 +402,7 @@ describe('Service Module - Actions', () => {
339402
assert(response.data.length === 1, 'only one record was returned')
340403
assert.deepEqual(
341404
returnedRecord,
342-
{ id: 8, description: 'Do the ninth' },
405+
{ id: 8, description: 'Do the ninth', isComplete: false },
343406
'the ninth record was returned'
344407
)
345408
assert(response.limit === 1, 'limit was correct')
@@ -401,9 +464,7 @@ describe('Service Module - Actions', () => {
401464
const qid = 'component-name'
402465

403466
actions.find.call({ $store: store }, { query: {}, qid }).then(() => {
404-
const qidPaginationState = store.state[
405-
'my-tasks'
406-
].pagination[qid]
467+
const qidPaginationState = store.state['my-tasks'].pagination[qid]
407468
assert(qidPaginationState, 'got pagination state for qid')
408469
done()
409470
})
@@ -499,7 +560,7 @@ describe('Service Module - Actions', () => {
499560
service: feathersClient.service('no-ids'),
500561
idField: '_id',
501562
actions: {
502-
afterFind({ }, response) {
563+
afterFind({}, response) {
503564
assert(
504565
response.data.length === 10,
505566
'records were still returned'
@@ -551,7 +612,7 @@ describe('Service Module - Actions', () => {
551612
})
552613
})
553614

554-
describe('Get', function () {
615+
describe('Get', function() {
555616
it('updates store list state on service success', async () => {
556617
const { makeServicePlugin, Todo } = makeContext()
557618
const store = new Vuex.Store<RootState>({
@@ -577,7 +638,7 @@ describe('Service Module - Actions', () => {
577638
assert(todoState.isGetPending === false, 'isGetPending is set to false')
578639

579640
let expectedKeyedById: NumberedList = {
580-
0: { id: 0, description: 'Do the first' }
641+
0: { id: 0, description: 'Do the first', isComplete: false }
581642
}
582643
assert.deepEqual(
583644
JSON.parse(JSON.stringify(todoState.keyedById)),
@@ -587,22 +648,26 @@ describe('Service Module - Actions', () => {
587648
// Make a request with the array syntax that allows passing params
588649
const response2 = await actions.get.call({ $store: store }, [1, {}])
589650
expectedKeyedById = {
590-
0: { id: 0, description: 'Do the first' },
591-
1: { id: 1, description: 'Do the second' }
651+
0: { id: 0, description: 'Do the first', isComplete: false },
652+
1: { id: 1, description: 'Do the second', isComplete: false }
592653
}
593654
assert(response2.description === 'Do the second')
594655
assert.deepEqual(
595656
JSON.parse(JSON.stringify(todoState.keyedById)),
596657
expectedKeyedById
597658
)
598659

599-
// Edit the first record in the store so the data is different.
600-
// Make a request for the first record again, and it should be updated.
660+
// Edit the first record in the store so the data is different.
661+
// Make a request for the first record again, and it should be updated.
601662
const clone1 = todo1.clone()
602663
clone1.description = 'MODIFIED IN THE VUEX STORE'
603664
clone1.commit()
604665

605-
assert.strictEqual(todoState.keyedById[0].description, clone1.description, 'the store instance was updated')
666+
assert.strictEqual(
667+
todoState.keyedById[0].description,
668+
clone1.description,
669+
'the store instance was updated'
670+
)
606671

607672
const response3 = await actions.get.call({ $store: store }, [0, {}])
608673
const todo0 = Todo.getFromStore(0)
@@ -638,7 +703,7 @@ describe('Service Module - Actions', () => {
638703
assert(todoState.errorOnGet === null, 'there was no errorOnGet')
639704
assert(todoState.isGetPending === false, 'isGetPending is set to false')
640705
let expectedKeyedById: NumberedList = {
641-
0: { id: 0, description: 'Do the first' }
706+
0: { id: 0, description: 'Do the first', isComplete: false }
642707
}
643708
assert.deepEqual(
644709
JSON.parse(JSON.stringify(todoState.keyedById)),
@@ -648,8 +713,8 @@ describe('Service Module - Actions', () => {
648713
// Make a request with the array syntax that allows passing params
649714
actions.get.call({ $store: store }, [1, {}]).then(response2 => {
650715
expectedKeyedById = {
651-
0: { id: 0, description: 'Do the first' },
652-
1: { id: 1, description: 'Do the second' }
716+
0: { id: 0, description: 'Do the first', isComplete: false },
717+
1: { id: 1, description: 'Do the second', isComplete: false }
653718
}
654719
assert(response2.description === 'Do the second')
655720
assert.deepEqual(
@@ -659,15 +724,15 @@ describe('Service Module - Actions', () => {
659724

660725
// Make a request to an existing record and return the existing data first, then update `keyedById`
661726
todoState.keyedById = {
662-
0: { id: 0, description: 'Do the FIRST' }, // twist the data to see difference
663-
1: { id: 1, description: 'Do the second' }
727+
0: { id: 0, description: 'Do the FIRST', isComplete: false }, // twist the data to see difference
728+
1: { id: 1, description: 'Do the second', isComplete: false }
664729
}
665730
actions.get
666731
.call({ $store: store }, [0, { skipRequestIfExists: true }])
667732
.then(response3 => {
668733
expectedKeyedById = {
669-
0: { id: 0, description: 'Do the FIRST' },
670-
1: { id: 1, description: 'Do the second' }
734+
0: { id: 0, description: 'Do the FIRST', isComplete: false },
735+
1: { id: 1, description: 'Do the second', isComplete: false }
671736
}
672737
assert(response3.description === 'Do the FIRST')
673738
assert.deepEqual(
@@ -678,8 +743,8 @@ describe('Service Module - Actions', () => {
678743
// The remote data will never arriive
679744
setTimeout(() => {
680745
expectedKeyedById = {
681-
0: { id: 0, description: 'Do the FIRST' },
682-
1: { id: 1, description: 'Do the second' }
746+
0: { id: 0, description: 'Do the FIRST', isComplete: false },
747+
1: { id: 1, description: 'Do the second', isComplete: false }
683748
}
684749
assert.deepEqual(
685750
JSON.parse(JSON.stringify(todoState.keyedById)),

test/test-utils.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ export function assertGetter(item, prop, value) {
1515

1616
export const makeStore = () => {
1717
return {
18-
0: { id: 0, description: 'Do the first' },
19-
1: { id: 1, description: 'Do the second' },
20-
2: { id: 2, description: 'Do the third' },
21-
3: { id: 3, description: 'Do the fourth' },
22-
4: { id: 4, description: 'Do the fifth' },
23-
5: { id: 5, description: 'Do the sixth' },
24-
6: { id: 6, description: 'Do the seventh' },
25-
7: { id: 7, description: 'Do the eighth' },
26-
8: { id: 8, description: 'Do the ninth' },
27-
9: { id: 9, description: 'Do the tenth' }
18+
0: { id: 0, description: 'Do the first', isComplete: false },
19+
1: { id: 1, description: 'Do the second', isComplete: false },
20+
2: { id: 2, description: 'Do the third', isComplete: false },
21+
3: { id: 3, description: 'Do the fourth', isComplete: false },
22+
4: { id: 4, description: 'Do the fifth', isComplete: false },
23+
5: { id: 5, description: 'Do the sixth', isComplete: false },
24+
6: { id: 6, description: 'Do the seventh', isComplete: false },
25+
7: { id: 7, description: 'Do the eighth', isComplete: false },
26+
8: { id: 8, description: 'Do the ninth', isComplete: false },
27+
9: { id: 9, description: 'Do the tenth', isComplete: false }
2828
}
2929
}
3030

3131
export const makeStoreWithAtypicalIds = () => {
3232
return {
33-
0: { someId: 0, description: 'Do the first' },
34-
1: { someId: 1, description: 'Do the second' },
35-
2: { someId: 2, description: 'Do the third' },
36-
3: { someId: 3, description: 'Do the fourth' },
37-
4: { someId: 4, description: 'Do the fifth' },
38-
5: { someId: 5, description: 'Do the sixth' },
39-
6: { someId: 6, description: 'Do the seventh' },
40-
7: { someId: 7, description: 'Do the eighth' },
41-
8: { someId: 8, description: 'Do the ninth' },
42-
9: { someId: 9, description: 'Do the tenth' }
33+
0: { someId: 0, description: 'Do the first', isComplete: false },
34+
1: { someId: 1, description: 'Do the second', isComplete: false },
35+
2: { someId: 2, description: 'Do the third', isComplete: false },
36+
3: { someId: 3, description: 'Do the fourth', isComplete: false },
37+
4: { someId: 4, description: 'Do the fifth', isComplete: false },
38+
5: { someId: 5, description: 'Do the sixth', isComplete: false },
39+
6: { someId: 6, description: 'Do the seventh', isComplete: false },
40+
7: { someId: 7, description: 'Do the eighth', isComplete: false },
41+
8: { someId: 8, description: 'Do the ninth', isComplete: false },
42+
9: { someId: 9, description: 'Do the tenth', isComplete: false }
4343
}
4444
}

0 commit comments

Comments
 (0)