11import { assert } from 'chai'
22import { AuthState } from '../src/auth-module/types'
3+ import { ServiceState } from './service-module/types'
34import { isNode , isBrowser } from '../src/utils'
45import { diff as deepDiff } from 'deep-object-diff'
56import {
67 initAuth ,
8+ hydrateApi ,
79 getServicePrefix ,
810 getServiceCapitalization ,
911 getQueryInfo
@@ -16,7 +18,8 @@ import Vuex from 'vuex'
1618Vue . use ( Vuex )
1719
1820interface RootState {
19- auth : AuthState
21+ auth : AuthState ,
22+ users : ServiceState
2023}
2124
2225describe ( '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