1
1
import { assert } from 'chai'
2
2
import { AuthState } from '../src/auth-module/types'
3
+ import { ServiceState } from './service-module/types'
3
4
import { isNode , isBrowser } from '../src/utils'
4
5
import { diff as deepDiff } from 'deep-object-diff'
5
6
import {
6
7
initAuth ,
8
+ hydrateApi ,
7
9
getServicePrefix ,
8
10
getServiceCapitalization ,
9
11
getQueryInfo
@@ -16,7 +18,8 @@ import Vuex from 'vuex'
16
18
Vue . use ( Vuex )
17
19
18
20
interface RootState {
19
- auth : AuthState
21
+ auth : AuthState ,
22
+ users : ServiceState
20
23
}
21
24
22
25
describe ( 'Utils' , function ( ) {
@@ -76,6 +79,38 @@ describe('Utils', function() {
76
79
} )
77
80
} )
78
81
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
+
79
114
describe ( 'Inflections' , function ( ) {
80
115
it ( 'properly inflects the service prefix' , function ( ) {
81
116
const decisionTable = [
0 commit comments