@@ -8,13 +8,14 @@ const options = {
8
8
autoRemove : false
9
9
}
10
10
11
- const { find, list } = makeServiceGetters ( 'todos' , options )
11
+ const { find, list, current } = makeServiceGetters ( 'todos' , options )
12
12
const { addItems } = makeServiceMutations ( 'todos' , options )
13
13
14
14
describe ( 'Service Module - Getters' , function ( ) {
15
15
beforeEach ( function ( ) {
16
16
const state = makeServiceState ( 'todos' , options )
17
17
this . items = [
18
+ { _id : 0 , otherField : true , test : true } ,
18
19
{ _id : 1 , otherField : true , test : true } ,
19
20
{
20
21
_id : 2 ,
@@ -35,6 +36,7 @@ describe('Service Module - Getters', function () {
35
36
}
36
37
]
37
38
addItems ( state , this . items )
39
+ state . currentId = 0
38
40
this . state = state
39
41
} )
40
42
@@ -45,6 +47,13 @@ describe('Service Module - Getters', function () {
45
47
assert . deepEqual ( results , items , 'the list was correct' )
46
48
} )
47
49
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
+
48
57
it ( 'find' , function ( ) {
49
58
const { state, items } = this
50
59
const params = { query : { } }
@@ -53,7 +62,7 @@ describe('Service Module - Getters', function () {
53
62
assert . deepEqual ( results . data , items , 'the list was correct' )
54
63
assert ( results . limit === 0 , 'limit was correct' )
55
64
assert ( results . skip === 0 , 'skip was correct' )
56
- assert ( results . total === 3 , 'total was correct' )
65
+ assert ( results . total === 4 , 'total was correct' )
57
66
} )
58
67
59
68
it ( 'find with query' , function ( ) {
@@ -148,23 +157,23 @@ describe('Service Module - Getters', function () {
148
157
const results = find ( state ) ( params )
149
158
150
159
assert ( results . data . length === 1 , 'the length was correct' )
151
- assert ( results . data [ 0 ] . _id === 1 , 'the correct record was returned' )
160
+ assert ( results . data [ 0 ] . _id === 0 , 'the correct record was returned' )
152
161
assert ( results . limit === 1 , 'limit was correct' )
153
162
assert ( results . skip === 0 , 'skip was correct' )
154
- assert ( results . total === 3 , 'total was correct' )
163
+ assert ( results . total === 4 , 'total was correct' )
155
164
} )
156
165
157
166
it ( 'find with skip' , function ( ) {
158
167
const { state } = this
159
168
const params = { query : { $skip : 1 } }
160
169
const results = find ( state ) ( params )
161
170
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' )
171
+ assert ( results . data . length === 3 , 'the length was correct' )
172
+ assert ( results . data [ 0 ] . _id === 1 , 'the correct record was returned' )
173
+ assert ( results . data [ 1 ] . _id === 2 , 'the correct record was returned' )
165
174
assert ( results . limit === 0 , 'limit was correct' )
166
175
assert ( results . skip === 1 , 'skip was correct' )
167
- assert ( results . total === 3 , 'total was correct' )
176
+ assert ( results . total === 4 , 'total was correct' )
168
177
} )
169
178
170
179
it ( 'find with limit and skip' , function ( ) {
@@ -173,24 +182,24 @@ describe('Service Module - Getters', function () {
173
182
const results = find ( state ) ( params )
174
183
175
184
assert ( results . data . length === 1 , 'the length was correct' )
176
- assert ( results . data [ 0 ] . _id === 2 , 'the correct record was returned' )
185
+ assert ( results . data [ 0 ] . _id === 1 , 'the correct record was returned' )
177
186
assert ( results . limit === 1 , 'limit was correct' )
178
187
assert ( results . skip === 1 , 'skip was correct' )
179
- assert ( results . total === 3 , 'total was correct' )
188
+ assert ( results . total === 4 , 'total was correct' )
180
189
} )
181
190
182
191
it ( 'find with select' , function ( ) {
183
192
const { state } = this
184
193
const params = { query : { $select : [ 'otherField' ] } }
185
194
const results = find ( state ) ( params )
186
195
187
- assert ( results . data . length === 3 , 'the length was correct' )
196
+ assert ( results . data . length === 4 , 'the length was correct' )
188
197
results . data . forEach ( result => {
189
198
assert ( Object . keys ( result ) . length === 1 , 'only one field was returned' )
190
199
assert ( result . otherField , 'the correct field was returned' )
191
200
} )
192
201
assert ( results . limit === 0 , 'limit was correct' )
193
202
assert ( results . skip === 0 , 'skip was correct' )
194
- assert ( results . total === 3 , 'total was correct' )
203
+ assert ( results . total === 4 , 'total was correct' )
195
204
} )
196
205
} )
0 commit comments