@@ -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 ( ) {
@@ -63,6 +72,7 @@ describe('Service Module - Getters', function () {
63
72
64
73
assert ( results . data . length === 1 , 'the length was correct' )
65
74
assert ( results . data [ 0 ] . _id === 3 , 'the correct record was returned' )
75
+
66
76
assert ( results . limit === 0 , 'limit was correct' )
67
77
assert ( results . skip === 0 , 'skip was correct' )
68
78
assert ( results . total === 1 , 'total was correct' )
@@ -148,23 +158,23 @@ describe('Service Module - Getters', function () {
148
158
const results = find ( state ) ( params )
149
159
150
160
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' )
152
162
assert ( results . limit === 1 , 'limit was correct' )
153
163
assert ( results . skip === 0 , 'skip was correct' )
154
- assert ( results . total === 3 , 'total was correct' )
164
+ assert ( results . total === 4 , 'total was correct' )
155
165
} )
156
166
157
167
it ( 'find with skip' , function ( ) {
158
168
const { state } = this
159
169
const params = { query : { $skip : 1 } }
160
170
const results = find ( state ) ( params )
161
171
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' )
165
175
assert ( results . limit === 0 , 'limit was correct' )
166
176
assert ( results . skip === 1 , 'skip was correct' )
167
- assert ( results . total === 3 , 'total was correct' )
177
+ assert ( results . total === 4 , 'total was correct' )
168
178
} )
169
179
170
180
it ( 'find with limit and skip' , function ( ) {
@@ -173,24 +183,24 @@ describe('Service Module - Getters', function () {
173
183
const results = find ( state ) ( params )
174
184
175
185
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' )
177
187
assert ( results . limit === 1 , 'limit was correct' )
178
188
assert ( results . skip === 1 , 'skip was correct' )
179
- assert ( results . total === 3 , 'total was correct' )
189
+ assert ( results . total === 4 , 'total was correct' )
180
190
} )
181
191
182
192
it ( 'find with select' , function ( ) {
183
193
const { state } = this
184
194
const params = { query : { $select : [ 'otherField' ] } }
185
195
const results = find ( state ) ( params )
186
196
187
- assert ( results . data . length === 3 , 'the length was correct' )
197
+ assert ( results . data . length === 4 , 'the length was correct' )
188
198
results . data . forEach ( result => {
189
199
assert ( Object . keys ( result ) . length === 1 , 'only one field was returned' )
190
200
assert ( result . otherField , 'the correct field was returned' )
191
201
} )
192
202
assert ( results . limit === 0 , 'limit was correct' )
193
203
assert ( results . skip === 0 , 'skip was correct' )
194
- assert ( results . total === 3 , 'total was correct' )
204
+ assert ( results . total === 4 , 'total was correct' )
195
205
} )
196
206
} )
0 commit comments