@@ -35,9 +35,9 @@ export function initApiMockServer () {
35
35
fetchMock . reset ( )
36
36
fetchMock . config . sendAsJson = false
37
37
38
- function book ( id ) {
38
+ function Author ( id ) {
39
39
return {
40
- type : 'Book ' ,
40
+ type : 'Author ' ,
41
41
id,
42
42
attributes : {
43
43
author : faker . person . fullName ( ) ,
@@ -46,10 +46,39 @@ export function initApiMockServer () {
46
46
}
47
47
}
48
48
49
+ function book ( id ) {
50
+ return {
51
+ type : 'book' ,
52
+ id,
53
+ attributes : {
54
+ author : faker . name . findName ( ) ,
55
+ title : faker . lorem . words ( 3 )
56
+ }
57
+ }
58
+ }
59
+
60
+ function category ( id ) {
61
+ return {
62
+ type : 'Category' ,
63
+ id,
64
+ attributes : {
65
+ author : faker . name . findName ( ) ,
66
+ title : faker . lorem . words ( 3 )
67
+ }
68
+ }
69
+ }
70
+
71
+ fetchMock . get ( url ( '/Author/1' ) , response ( Author ( 1 ) ) )
49
72
fetchMock . get ( url ( '/book/1' ) , response ( book ( 1 ) ) )
73
+ fetchMock . get ( url ( '/category/1' ) , response ( category ( 1 ) ) )
74
+
50
75
fetchMock . getOnce ( url ( '/book/1/nometa' ) , response ( book ( 1 ) , null ) )
51
76
fetchMock . getOnce ( url ( '/book/1/nolinks' ) , response ( book ( 1 ) , { } , null ) )
77
+
78
+ fetchMock . get ( url ( '/Author/' ) , response ( [ Author ( 1 ) , Author ( 2 ) , Author ( 3 ) ] ) )
52
79
fetchMock . get ( url ( '/book/' ) , response ( [ book ( 1 ) , book ( 2 ) , book ( 3 ) ] ) )
80
+ fetchMock . get ( url ( '/category/' ) , response ( [ category ( 1 ) , category ( 2 ) , category ( 3 ) ] ) )
81
+
53
82
fetchMock . postOnce ( url ( '/book/' ) , response ( book ( 'new' ) , { } , { } , 201 ) )
54
83
fetchMock . postOnce ( {
55
84
url : url ( '/clientBook/' ) ,
@@ -97,23 +126,33 @@ export function initApiMock () {
97
126
initApiMockServer ( )
98
127
99
128
const router = new Router ( )
129
+ router
130
+ . addRoute ( new Route ( 'Author' , 'get' , '/Author/{id}' , [ 'id' ] ) )
131
+ . addRoute ( new Route ( 'Author' , 'delete' , '/Author/{id}' , [ 'id' ] ) )
132
+ . addRoute ( new Route ( 'Author' , 'list' , '/Author/' , [ ] ) )
133
+ . addRoute ( new Route ( 'Author' , 'create' , '/Author/' , [ ] ) )
100
134
router
101
135
. addRoute ( new Route ( 'book' , 'get' , '/book/{id}' , [ 'id' ] ) )
102
136
. addRoute ( new Route ( 'book' , 'delete' , '/book/{id}' , [ 'id' ] ) )
103
137
. addRoute ( new Route ( 'book' , 'list' , '/book/' , [ ] ) )
104
138
. addRoute ( new Route ( 'book' , 'create' , '/book/' , [ ] ) )
139
+ router
140
+ . addRoute ( new Route ( 'Category' , 'get' , '/category/{id}' , [ 'id' ] ) )
141
+ . addRoute ( new Route ( 'Category' , 'delete' , '/category/{id}' , [ 'id' ] ) )
142
+ . addRoute ( new Route ( 'Category' , 'list' , '/category/' , [ ] ) )
143
+ . addRoute ( new Route ( 'Category' , 'create' , '/category/' , [ ] ) )
105
144
106
145
const store = new Vuex . Store ( )
107
146
const api = new ResourcefulApi ( )
108
147
109
148
api . setBaseUrl ( 'http://api/' )
110
149
api . setStore ( store )
111
150
api . setupResourcefulRequests ( router )
112
- api . setupApiModules ( [ 'book' ] )
151
+ api . setupApiModules ( [ 'Author' , ' book' , 'Category '] )
113
152
114
153
return api
115
154
}
116
155
117
- export function getVuexContextForResourceType ( api , type ) {
118
- return api . store . _modules . root . _children [ type ] . context
156
+ export function getVuexContextForResourceType ( api , moduleName ) {
157
+ return api . store . _modules . root . _children [ moduleName ] . context
119
158
}
0 commit comments