Skip to content

Commit a8cba54

Browse files
committed
test: add first debounced tests
1 parent f513293 commit a8cba54

File tree

4 files changed

+251
-103
lines changed

4 files changed

+251
-103
lines changed

test/fixtures/feathers-client.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,52 @@ const baseUrl = 'http://localhost:3030'
1111

1212
// These are fixtures used in the service-modulet.test.js under socket events.
1313
let id = 0
14-
mockServer.on('things::create', function(data) {
14+
mockServer.on('things::create', function (data) {
1515
data.id = id
1616
id++
1717
mockServer.emit('things created', data)
1818
})
19-
mockServer.on('things::patch', function(id, data) {
19+
mockServer.on('things::patch', function (id, data) {
2020
Object.assign(data, { id, test: true })
2121
mockServer.emit('things patched', data)
2222
})
23-
mockServer.on('things::update', function(id, data) {
23+
mockServer.on('things::update', function (id, data) {
2424
Object.assign(data, { id, test: true })
2525
mockServer.emit('things updated', data)
2626
})
27-
mockServer.on('things::remove', function(id) {
27+
mockServer.on('things::remove', function (id) {
2828
mockServer.emit('things removed', { id, test: true })
2929
})
3030

31+
let idDebounce = 0
32+
33+
mockServer.on('things-debounced::create', function (data) {
34+
data.id = idDebounce
35+
idDebounce++
36+
mockServer.emit('things-debounced created', data)
37+
})
38+
mockServer.on('things-debounced::patch', function (id, data) {
39+
Object.assign(data, { id, test: true })
40+
mockServer.emit('things-debounced patched', data)
41+
})
42+
mockServer.on('things-debounced::update', function (id, data) {
43+
Object.assign(data, { id, test: true })
44+
mockServer.emit('things-debounced updated', data)
45+
})
46+
mockServer.on('things-debounced::remove', function (id) {
47+
mockServer.emit('things-debounced removed', { id, test: true })
48+
})
49+
3150
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3251
export function makeFeathersSocketClient(baseUrl) {
3352
const socket = io(baseUrl)
3453

35-
return feathers()
36-
.configure(socketio(socket))
37-
.configure(auth())
54+
return feathers().configure(socketio(socket)).configure(auth())
3855
}
3956

4057
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
4158
export function makeFeathersRestClient(baseUrl) {
42-
return feathers()
43-
.configure(rest(baseUrl).axios(axios))
44-
.configure(auth())
59+
return feathers().configure(rest(baseUrl).axios(axios)).configure(auth())
4560
}
4661

4762
const sock = io(baseUrl)

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

Lines changed: 8 additions & 7 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,7 +28,7 @@ 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
}
@@ -73,6 +73,7 @@ describe('makeServicePlugin', function() {
7373
isRemovePending: false,
7474
isUpdatePending: false,
7575
keepCopiesInStore: false,
76+
debounceEventsTime: null,
7677
keyedById: {},
7778
modelName: 'Todo',
7879
nameStyle: 'short',
@@ -94,7 +95,7 @@ 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+
it('sets up Model.store && service.FeathersVuexModel', function () {
9899
const serverAlias = 'default'
99100
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
100101
serverAlias
@@ -114,7 +115,7 @@ describe('makeServicePlugin', function() {
114115
assert.equal(service.FeathersVuexModel, Todo, 'Model accessible on service')
115116
})
116117

117-
it('allows accessing other models', function() {
118+
it('allows accessing other models', function () {
118119
const serverAlias = 'default'
119120
const { makeServicePlugin, BaseModel, models } = feathersVuex(feathers, {
120121
idField: '_id',
@@ -140,7 +141,7 @@ 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())
145146
const serverAlias = 'default'
146147
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {
@@ -235,7 +236,7 @@ describe('makeServicePlugin', function() {
235236
assert(removedCalled, 'removed handler called')
236237
})
237238

238-
it('fall back to globalOptions handleEvents if service specific handleEvents handler is missing', async function() {
239+
it('fall back to globalOptions handleEvents if service specific handleEvents handler is missing', async function () {
239240
// feathers.use('todos', new TodosService())
240241
const serverAlias = 'default'
241242

@@ -339,7 +340,7 @@ describe('makeServicePlugin', function() {
339340
assert(globalRemovedCalled, 'global removed handler called')
340341
})
341342

342-
it('allow handleEvents handlers to return extracted event data', async function() {
343+
it('allow handleEvents handlers to return extracted event data', async function () {
343344
const serverAlias = 'default'
344345

345346
const { makeServicePlugin, BaseModel } = feathersVuex(feathers, {

test/service-module/service-module.reinitialization.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function makeContext() {
2929
}
3030
}
3131

32-
describe('Service Module - Reinitialization', function() {
32+
describe('Service Module - Reinitialization', function () {
3333
/**
3434
* Tests that when the make service plugin is reinitialized state
3535
* is reset in the vuex module/model.
3636
* This prevents state pollution in SSR setups.
3737
*/
38-
it('does not preserve module/model state when reinitialized', function() {
38+
it('does not preserve module/model state when reinitialized', function () {
3939
const {
4040
makeServicePlugin,
4141
todoService,
@@ -74,6 +74,7 @@ describe('Service Module - Reinitialization', function() {
7474
isRemovePending: false,
7575
isUpdatePending: false,
7676
keepCopiesInStore: false,
77+
debounceEventsTime: null,
7778
keyedById: {},
7879
modelName: 'Todo',
7980
nameStyle: 'short',

0 commit comments

Comments
 (0)