Skip to content

Commit 9990659

Browse files
committed
tests: chore - rename namespace
- namespace should be unique for test-files. - because of the 1on1: service-path <-> Model relation - otherwise event-emitters for services call wrong mutations...
1 parent 5f7ac40 commit 9990659

File tree

5 files changed

+66
-69
lines changed

5 files changed

+66
-69
lines changed

test/make-find-mixin.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function makeContext() {
3030
Vue.use(Vuex)
3131
Vue.use(FeathersVuex)
3232

33-
describe('Find Mixin', function() {
33+
describe('Find Mixin', function () {
3434
const { makeServicePlugin, FindModel } = makeContext()
3535
const serviceName = 'todos'
3636
const store = new Vuex.Store({
@@ -42,7 +42,7 @@ describe('Find Mixin', function() {
4242
]
4343
})
4444

45-
it('correctly forms mixin data', function() {
45+
it('correctly forms mixin data', function () {
4646
const todosMixin = makeFindMixin({ service: 'todos' })
4747
interface TodosComponent {
4848
todos: []
@@ -99,7 +99,7 @@ describe('Find Mixin', function() {
9999
)
100100
})
101101

102-
it('correctly forms mixin data for dynamic service', function() {
102+
it('correctly forms mixin data for dynamic service', function () {
103103
const tasksMixin = makeFindMixin({
104104
service() {
105105
return this.serviceName

test/service-module/make-service-plugin.test.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import _omit from 'lodash/omit'
1616

1717
Vue.use(Vuex)
1818

19-
describe('makeServicePlugin', function() {
19+
describe('makeServicePlugin', function () {
2020
beforeEach(() => {
2121
clearModels()
2222
})
@@ -28,29 +28,30 @@ describe('makeServicePlugin', function() {
2828
assert(clients.byAlias['this is a test'], 'got a reference to the client.')
2929
})
3030

31-
it('registers the vuex module with options', function() {
31+
it('registers the vuex module with options', function () {
3232
interface RootState {
3333
todos: {}
3434
}
3535

36-
const serverAlias = 'default'
36+
const serverAlias = 'make-service-plugin'
3737
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
3838
serverAlias
3939
})
40-
const servicePath = 'todos'
40+
const servicePath = 'make-service-plugin-todos'
4141
class Todo extends BaseModel {
4242
public static modelName = 'Todo'
4343
public static servicePath = servicePath
4444
}
4545
const todosPlugin = makeServicePlugin({
4646
servicePath,
4747
Model: Todo,
48-
service: feathers.service(servicePath)
48+
service: feathers.service(servicePath),
49+
namespace: 'make-service-plugin-todos'
4950
})
5051
const store = new Vuex.Store<RootState>({ plugins: [todosPlugin] })
5152

52-
const keys = Object.keys(store.state.todos)
53-
const received = _pick(store.state.todos, keys)
53+
const keys = Object.keys(store.state['make-service-plugin-todos'])
54+
const received = _pick(store.state['make-service-plugin-todos'], keys)
5455
const expected = {
5556
addOnUpsert: false,
5657
autoRemove: false,
@@ -76,16 +77,16 @@ describe('makeServicePlugin', function() {
7677
keyedById: {},
7778
modelName: 'Todo',
7879
nameStyle: 'short',
79-
namespace: 'todos',
80+
namespace: 'make-service-plugin-todos',
8081
pagination: {
8182
defaultLimit: null,
8283
defaultSkip: null
8384
},
8485
paramsForServer: ['$populateParams'],
8586
preferUpdate: false,
8687
replaceItems: false,
87-
serverAlias: 'default',
88-
servicePath: 'todos',
88+
serverAlias: 'make-service-plugin',
89+
servicePath: 'make-service-plugin-todos',
8990
skipRequestIfExists: false,
9091
tempsById: {},
9192
whitelist: []
@@ -94,13 +95,13 @@ describe('makeServicePlugin', function() {
9495
assert.deepEqual(_omit(received), _omit(expected), 'defaults in place.')
9596
})
9697

97-
it('sets up Model.store && service.FeathersVuexModel', function() {
98-
const serverAlias = 'default'
98+
it('sets up Model.store && service.FeathersVuexModel', function () {
99+
const serverAlias = 'make-service-plugin'
99100
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
100101
serverAlias
101102
})
102103

103-
const servicePath = 'todos'
104+
const servicePath = 'make-service-plugin-todos'
104105
const service = feathers.service(servicePath)
105106
class Todo extends BaseModel {
106107
public static modelName = 'Todo'
@@ -114,14 +115,14 @@ describe('makeServicePlugin', function() {
114115
assert.equal(service.FeathersVuexModel, Todo, 'Model accessible on service')
115116
})
116117

117-
it('allows accessing other models', function() {
118-
const serverAlias = 'default'
118+
it('allows accessing other models', function () {
119+
const serverAlias = 'make-service-plugin'
119120
const { makeServicePlugin, BaseModel, models } = feathersVuex(feathers, {
120121
idField: '_id',
121122
serverAlias
122123
})
123124

124-
const servicePath = 'todos'
125+
const servicePath = 'make-service-plugin-todos'
125126
class Todo extends BaseModel {
126127
public static modelName = 'Todo'
127128
public static servicePath = servicePath
@@ -140,18 +141,19 @@ describe('makeServicePlugin', function() {
140141
assert(Todo.store === store)
141142
})
142143

143-
it('allows service specific handleEvents', async function() {
144+
it('allows service specific handleEvents', async function () {
144145
// feathers.use('todos', new TodosService())
145-
const serverAlias = 'default'
146+
const serverAlias = 'make-service-plugin'
146147
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
147148
idField: '_id',
148149
serverAlias
149150
})
150151

151-
const servicePath = 'todos'
152+
const servicePath = 'make-service-plugin-todos'
152153
class Todo extends BaseModel {
153154
public static modelName = 'Todo'
154155
public static servicePath = servicePath
156+
public static namespace = 'make-service-plugin-todos'
155157
}
156158

157159
let createdCalled = false
@@ -189,7 +191,7 @@ describe('makeServicePlugin', function() {
189191
const todo = new Todo()
190192

191193
// Fake server call
192-
feathers.service('todos').hooks({
194+
feathers.service('make-service-plugin-todos').hooks({
193195
before: {
194196
create: [
195197
context => {
@@ -235,9 +237,9 @@ describe('makeServicePlugin', function() {
235237
assert(removedCalled, 'removed handler called')
236238
})
237239

238-
it('fall back to globalOptions handleEvents if service specific handleEvents handler is missing', async function() {
240+
it('fall back to globalOptions handleEvents if service specific handleEvents handler is missing', async function () {
239241
// feathers.use('todos', new TodosService())
240-
const serverAlias = 'default'
242+
const serverAlias = 'make-service-plugin'
241243

242244
let globalCreatedCalled = false
243245
let globalUpdatedCalled = false
@@ -266,17 +268,19 @@ describe('makeServicePlugin', function() {
266268
}
267269
})
268270

269-
const servicePath = 'todos'
271+
const servicePath = 'make-service-plugin-todos'
270272
class Todo extends BaseModel {
271273
public static modelName = 'Todo'
272274
public static servicePath = servicePath
275+
public static namespace = 'make-service-plugin-todos'
273276
}
274277

275278
let specificUpdatedCalled = false
276279
const todosPlugin = makeServicePlugin({
277280
servicePath,
278281
Model: Todo,
279282
service: feathers.service(servicePath),
283+
namespace: 'make-service-plugin-todos',
280284
handleEvents: {
281285
updated() {
282286
specificUpdatedCalled = true
@@ -292,7 +296,7 @@ describe('makeServicePlugin', function() {
292296
const todo = new Todo()
293297

294298
// Fake server call
295-
feathers.service('todos').hooks({
299+
feathers.service('make-service-plugin-todos').hooks({
296300
before: {
297301
create: [
298302
context => {
@@ -339,8 +343,8 @@ describe('makeServicePlugin', function() {
339343
assert(globalRemovedCalled, 'global removed handler called')
340344
})
341345

342-
it('allow handleEvents handlers to return extracted event data', async function() {
343-
const serverAlias = 'default'
346+
it('allow handleEvents handlers to return extracted event data', async function () {
347+
const serverAlias = 'make-service-plugin'
344348

345349
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
346350
idField: '_id',
@@ -361,7 +365,7 @@ describe('makeServicePlugin', function() {
361365
}
362366
})
363367

364-
const servicePath = 'todos'
368+
const servicePath = 'make-service-plugin-todos'
365369
class Todo extends BaseModel {
366370
public static modelName = 'Todo'
367371
public static servicePath = servicePath
@@ -371,13 +375,14 @@ describe('makeServicePlugin', function() {
371375
const todosPlugin = makeServicePlugin({
372376
servicePath,
373377
Model: Todo,
374-
service: todosService
378+
service: todosService,
379+
namespace: 'make-service-plugin-todos'
375380
})
376381

377382
const store = new Vuex.Store<{ todos: ServiceState }>({
378383
plugins: [todosPlugin]
379384
})
380-
const { keyedById } = store.state.todos
385+
const { keyedById } = store.state['make-service-plugin-todos']
381386

382387
let createdData = null
383388
let updatedData = null

test/service-module/model-base.test.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Vue.use(Vuex)
1818
process.setMaxListeners(100)
1919

2020
describe.skip('Model - Standalone', function () {
21-
it.skip('allows using a model without a service', function () { })
22-
it.skip('rename serverAlias to just `alias` or maybe `groupName`', function () { })
21+
it.skip('allows using a model without a service', function () {})
22+
it.skip('rename serverAlias to just `alias` or maybe `groupName`', function () {})
2323
})
2424

2525
describe('makeModel / BaseModel', function () {
@@ -28,7 +28,7 @@ describe('makeModel / BaseModel', function () {
2828
})
2929

3030
it('properly sets up the BaseModel', function () {
31-
const alias = 'default'
31+
const alias = 'model-base'
3232
const { BaseModel } = feathersVuex(feathers, { serverAlias: alias })
3333
const {
3434
name,
@@ -51,7 +51,7 @@ describe('makeModel / BaseModel', function () {
5151
assert(!preferUpdate, 'prefer fetch by default')
5252

5353
// Readonly props
54-
assert(serverAlias === 'default', 'serverAlias')
54+
assert(serverAlias === 'model-base', 'serverAlias')
5555
assert(models, 'models are available')
5656
assert.equal(Object.keys(copiesById).length, 0, 'copiesById is empty')
5757

@@ -88,14 +88,9 @@ describe('makeModel / BaseModel', function () {
8888
})
8989

9090
// Utility Methods
91-
const utilityMethods = [
92-
'hydrateAll'
93-
]
91+
const utilityMethods = ['hydrateAll']
9492
utilityMethods.forEach(method => {
95-
assert(
96-
typeof BaseModel[method] === 'function',
97-
`has ${method} method`
98-
)
93+
assert(typeof BaseModel[method] === 'function', `has ${method} method`)
9994
})
10095

10196
const eventMethods = [
@@ -108,10 +103,7 @@ describe('makeModel / BaseModel', function () {
108103
'removeAllListeners'
109104
]
110105
eventMethods.forEach(method => {
111-
assert(
112-
typeof BaseModel[method] === 'function',
113-
`has ${method} method`
114-
)
106+
assert(typeof BaseModel[method] === 'function', `has ${method} method`)
115107
})
116108
})
117109

@@ -149,7 +141,7 @@ describe('makeModel / BaseModel', function () {
149141
})
150142

151143
it('allows access to other models after Vuex plugins are registered', function () {
152-
const serverAlias = 'default'
144+
const serverAlias = 'model-base'
153145
const { makeServicePlugin, BaseModel, models } = feathersVuex(feathers, {
154146
idField: '_id',
155147
serverAlias
@@ -158,7 +150,7 @@ describe('makeModel / BaseModel', function () {
158150
// Create a Todo Model & Plugin
159151
class Todo extends BaseModel {
160152
public static modelName = 'Todo'
161-
public test: boolean = true
153+
public test = true
162154
}
163155
const todosPlugin = makeServicePlugin({
164156
servicePath: 'todos',
@@ -169,7 +161,7 @@ describe('makeModel / BaseModel', function () {
169161
// Create a Task Model & Plugin
170162
class Task extends BaseModel {
171163
public static modelName = 'Task'
172-
public test: boolean = true
164+
public test = true
173165
}
174166
const tasksPlugin = makeServicePlugin({
175167
servicePath: 'tasks',
@@ -196,7 +188,7 @@ describe('makeModel / BaseModel', function () {
196188
})
197189
class Todo extends myApi.BaseModel {
198190
public static modelName = 'Todo'
199-
public test: boolean = true
191+
public test = true
200192
}
201193
const todosPlugin = myApi.makeServicePlugin({
202194
Model: Todo,
@@ -210,7 +202,7 @@ describe('makeModel / BaseModel', function () {
210202
})
211203
class Task extends theirApi.BaseModel {
212204
public static modelName = 'Task'
213-
public test: boolean = true
205+
public test = true
214206
}
215207
const tasksPlugin = theirApi.makeServicePlugin({
216208
Model: Task,

0 commit comments

Comments
 (0)