Skip to content

Commit 02643b8

Browse files
authored
make tests for id 0
1 parent c81cf2a commit 02643b8

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

test/service-module/getters.test.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ const options = {
88
autoRemove: false
99
}
1010

11-
const { find, list } = makeServiceGetters('todos', options)
11+
const { find, list, current } = makeServiceGetters('todos', options)
1212
const { addItems } = makeServiceMutations('todos', options)
1313

1414
describe('Service Module - Getters', function () {
1515
beforeEach(function () {
1616
const state = makeServiceState('todos', options)
1717
this.items = [
18+
{ _id: 0, otherField: true, test: true },
1819
{ _id: 1, otherField: true, test: true },
1920
{
2021
_id: 2,
@@ -35,6 +36,7 @@ describe('Service Module - Getters', function () {
3536
}
3637
]
3738
addItems(state, this.items)
39+
state.currentId = 0
3840
this.state = state
3941
})
4042

@@ -45,6 +47,13 @@ describe('Service Module - Getters', function () {
4547
assert.deepEqual(results, items, 'the list was correct')
4648
})
4749

50+
it('current with id 0', function () {
51+
const { state, items } = this
52+
const result = current(state)
53+
54+
assert.deepEqual(result, items[0], 'current was correct')
55+
})
56+
4857
it('find', function () {
4958
const { state, items } = this
5059
const params = { query: {} }
@@ -53,7 +62,7 @@ describe('Service Module - Getters', function () {
5362
assert.deepEqual(results.data, items, 'the list was correct')
5463
assert(results.limit === 0, 'limit was correct')
5564
assert(results.skip === 0, 'skip was correct')
56-
assert(results.total === 3, 'total was correct')
65+
assert(results.total === 4, 'total was correct')
5766
})
5867

5968
it('find with query', function () {
@@ -63,6 +72,7 @@ describe('Service Module - Getters', function () {
6372

6473
assert(results.data.length === 1, 'the length was correct')
6574
assert(results.data[0]._id === 3, 'the correct record was returned')
75+
6676
assert(results.limit === 0, 'limit was correct')
6777
assert(results.skip === 0, 'skip was correct')
6878
assert(results.total === 1, 'total was correct')
@@ -148,23 +158,23 @@ describe('Service Module - Getters', function () {
148158
const results = find(state)(params)
149159

150160
assert(results.data.length === 1, 'the length was correct')
151-
assert(results.data[0]._id === 1, 'the correct record was returned')
161+
assert(results.data[0]._id === 0, 'the correct record was returned')
152162
assert(results.limit === 1, 'limit was correct')
153163
assert(results.skip === 0, 'skip was correct')
154-
assert(results.total === 3, 'total was correct')
164+
assert(results.total === 4, 'total was correct')
155165
})
156166

157167
it('find with skip', function () {
158168
const { state } = this
159169
const params = { query: { $skip: 1 } }
160170
const results = find(state)(params)
161171

162-
assert(results.data.length === 2, 'the length was correct')
163-
assert(results.data[0]._id === 2, 'the correct record was returned')
164-
assert(results.data[1]._id === 3, 'the correct record was returned')
172+
assert(results.data.length === 3, 'the length was correct')
173+
assert(results.data[0]._id === 1, 'the correct record was returned')
174+
assert(results.data[1]._id === 2, 'the correct record was returned')
165175
assert(results.limit === 0, 'limit was correct')
166176
assert(results.skip === 1, 'skip was correct')
167-
assert(results.total === 3, 'total was correct')
177+
assert(results.total === 4, 'total was correct')
168178
})
169179

170180
it('find with limit and skip', function () {
@@ -173,24 +183,24 @@ describe('Service Module - Getters', function () {
173183
const results = find(state)(params)
174184

175185
assert(results.data.length === 1, 'the length was correct')
176-
assert(results.data[0]._id === 2, 'the correct record was returned')
186+
assert(results.data[0]._id === 1, 'the correct record was returned')
177187
assert(results.limit === 1, 'limit was correct')
178188
assert(results.skip === 1, 'skip was correct')
179-
assert(results.total === 3, 'total was correct')
189+
assert(results.total === 4, 'total was correct')
180190
})
181191

182192
it('find with select', function () {
183193
const { state } = this
184194
const params = { query: { $select: ['otherField'] } }
185195
const results = find(state)(params)
186196

187-
assert(results.data.length === 3, 'the length was correct')
197+
assert(results.data.length === 4, 'the length was correct')
188198
results.data.forEach(result => {
189199
assert(Object.keys(result).length === 1, 'only one field was returned')
190200
assert(result.otherField, 'the correct field was returned')
191201
})
192202
assert(results.limit === 0, 'limit was correct')
193203
assert(results.skip === 0, 'skip was correct')
194-
assert(results.total === 3, 'total was correct')
204+
assert(results.total === 4, 'total was correct')
195205
})
196206
})

0 commit comments

Comments
 (0)