Skip to content

Commit 74b85c6

Browse files
committed
Create tests
1 parent 528dc86 commit 74b85c6

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ describe('makeModel / BaseModel', function () {
8585
)
8686
})
8787

88+
// Utility Methods
89+
const utilityMethods = [
90+
'hydrateAll'
91+
]
92+
utilityMethods.forEach(method => {
93+
assert(
94+
typeof BaseModel[method] === 'function',
95+
`has ${method} method`
96+
)
97+
})
98+
8899
const eventMethods = [
89100
'on',
90101
'off',

test/utils.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { assert } from 'chai'
22
import { AuthState } from '../src/auth-module/types'
3+
import { ServiceState } from './service-module/types'
34
import { isNode, isBrowser } from '../src/utils'
45
import { diff as deepDiff } from 'deep-object-diff'
56
import {
67
initAuth,
8+
hydrateApi,
79
getServicePrefix,
810
getServiceCapitalization,
911
getQueryInfo
@@ -16,7 +18,8 @@ import Vuex from 'vuex'
1618
Vue.use(Vuex)
1719

1820
interface RootState {
19-
auth: AuthState
21+
auth: AuthState,
22+
users: ServiceState
2023
}
2124

2225
describe('Utils', function() {
@@ -76,6 +79,38 @@ describe('Utils', function() {
7679
})
7780
})
7881

82+
it('properly hydrate SSR store', function() {
83+
const { makeServicePlugin, BaseModel, models } = feathersVuex(
84+
feathersClient,
85+
{ serverAlias: 'hydrate' }
86+
)
87+
88+
class User extends BaseModel {
89+
public static modelName = 'User'
90+
public static test: boolean = true
91+
}
92+
93+
const store = new Vuex.Store<RootState>({
94+
plugins: [
95+
makeServicePlugin({
96+
Model: User,
97+
servicePath: 'users',
98+
service: feathersClient.service('users'),
99+
mutations: {
100+
addServerItem (state) {
101+
state.keyedById['abcdefg'] = { id: 'abcdefg', name: 'Guzz' }
102+
}
103+
}
104+
})
105+
]
106+
})
107+
store.commit('users/addServerItem')
108+
assert(store.state.users.keyedById['abcdefg'], 'server document added')
109+
assert(store.state.users.keyedById['abcdefg'] instanceof Object, 'server document is pure javascript object')
110+
hydrateApi({ api: models.hydrate })
111+
assert(store.state.users.keyedById['abcdefg'] instanceof User, 'document hydrated')
112+
})
113+
79114
describe('Inflections', function() {
80115
it('properly inflects the service prefix', function() {
81116
const decisionTable = [

0 commit comments

Comments
 (0)