Skip to content

Commit 31a72b1

Browse files
committed
refactor(tests): add Model & service
1 parent dc5d78d commit 31a72b1

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

test/service-module/module.getters.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ const options = {
1616
idField: '_id',
1717
tempIdField: '__id',
1818
autoRemove: false,
19-
serverAlias: 'default'
19+
serverAlias: 'default',
20+
Model: null,
21+
service: null
2022
}
2123

2224
const { find, list, get, getCopyById } = makeServiceGetters()
2325
const { addItems } = makeServiceMutations()
2426

2527
describe('Service Module - Getters', function() {
2628
beforeEach(function() {
27-
const state = makeServiceState('getter-todos', options)
29+
const state = makeServiceState(options)
2830
this.items = [
2931
{
3032
_id: 1,
@@ -201,8 +203,9 @@ describe('Service Module - Getters', function() {
201203
it('find with non-whitelisted custom operator fails', function() {
202204
const { state } = this
203205
const params = { query: { $client: 'test' } }
206+
let results
204207
try {
205-
var results = find(state)(params)
208+
results = find(state)(params)
206209
} catch (error) {
207210
assert(error)
208211
}
@@ -216,8 +219,9 @@ describe('Service Module - Getters', function() {
216219
name: { $regex: 'marsh', $options: 'igm' }
217220
}
218221
const params = { query }
222+
let results
219223
try {
220-
var results = find(state)(params)
224+
results = find(state)(params)
221225
} catch (error) {
222226
assert(!error, 'should not have failed with whitelisted custom operator')
223227
}

test/service-module/service-module.mutations.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@ import fakeData from '../fixtures/fake-data'
1414
import { getQueryInfo } from '../../src/utils'
1515
import { diff as deepDiff } from 'deep-object-diff'
1616
import omitDeep from 'omit-deep-lodash'
17+
import feathersVuex from '../../src/index'
18+
19+
import { feathersRestClient as feathersClient } from '../fixtures/feathers-client'
20+
21+
const { BaseModel } = feathersVuex(feathersClient, {
22+
serverAlias: 'mutations'
23+
})
1724

1825
Vue.use(Vuex)
1926

27+
class Todo extends BaseModel {
28+
public static modelName = 'Todo'
29+
public static test = true
30+
}
31+
2032
const options = {
2133
idField: '_id',
2234
autoRemove: false,
23-
serverAlias: 'myApi'
35+
serverAlias: 'myApi',
36+
service: feathersClient.service('mutations-todo'),
37+
Model: Todo
2438
}
2539

2640
const {
@@ -44,7 +58,7 @@ const {
4458

4559
describe('Service Module - Mutations', function() {
4660
beforeEach(function() {
47-
this.state = makeServiceState('mutation-todos', options)
61+
this.state = makeServiceState(options)
4862
this.state.keepCopiesInStore = true
4963
})
5064

@@ -165,7 +179,10 @@ describe('Service Module - Mutations', function() {
165179
{ _id: 4, test: true }
166180
]
167181
addItems(state, items)
168-
const itemsToRemove = [{ _id: 1, test: true }, { _id: 2, test: true }]
182+
const itemsToRemove = [
183+
{ _id: 1, test: true },
184+
{ _id: 2, test: true }
185+
]
169186
removeItems(state, itemsToRemove)
170187

171188
assert(state.ids.length === 2, 'should have 2 ids left')
@@ -857,7 +874,7 @@ describe('Service Module - Mutations', function() {
857874
})
858875

859876
describe('Pagination', function() {
860-
it('updatePaginationForQuery', function () {
877+
it('updatePaginationForQuery', function() {
861878
this.timeout(600000)
862879
const state = this.state
863880
const qid = 'main-list'

0 commit comments

Comments
 (0)