Skip to content

Commit 8d16533

Browse files
committed
test auth with and without params
1 parent c407127 commit 8d16533

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/auth-module/auth-module.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { assert } from 'chai'
44
import feathersVuex from '../../src/index'
55
import { feathersRestClient as feathersClient } from '../fixtures/feathers-client'
66
import Vuex from 'vuex'
7+
import { isEmpty } from 'lodash'
78

89
const { makeAuthPlugin, makeServicePlugin, BaseModel } = feathersVuex(
910
feathersClient,
@@ -209,4 +210,43 @@ describe('Auth Module', () => {
209210
assert(store.state.auth.isTrue === true, 'the custom action was run')
210211
})
211212
})
213+
214+
it('Calls auth service without params', async function() {
215+
let receivedData = null
216+
let receivedParams = null
217+
feathersClient.use('authentication', {
218+
create(data, params) {
219+
receivedData = data
220+
receivedParams = params
221+
return Promise.resolve({ accessToken: 'jg54jh2gj6fgh734j5h4j25jbh' })
222+
}
223+
})
224+
225+
const { store } = makeContext()
226+
227+
const request = { strategy: 'local', email: 'test', password: 'test' }
228+
await store.dispatch('auth/authenticate', request)
229+
assert(receivedData, 'got data')
230+
assert(receivedData.strategy === 'local', 'got strategy')
231+
assert(receivedData.email === 'test', 'got email')
232+
assert(receivedData.password === 'test', 'got password')
233+
assert(receivedParams && isEmpty(receivedParams), 'empty params')
234+
})
235+
236+
it('Calls auth service with params', async function() {
237+
let receivedParams = null
238+
feathersClient.use('authentication', {
239+
create(data, params) {
240+
receivedParams = params
241+
return Promise.resolve({ accessToken: 'jg54jh2gj6fgh734j5h4j25jbh' })
242+
}
243+
})
244+
245+
const { store } = makeContext()
246+
247+
const request = { strategy: 'local', email: 'test', password: 'test' }
248+
const customParams = { theAnswer: 42 }
249+
await store.dispatch('auth/authenticate', [request, customParams])
250+
assert(receivedParams && receivedParams.theAnswer === 42, 'got params')
251+
})
212252
})

0 commit comments

Comments
 (0)