11import { setupMockData , User , Post } from "../support/mock-data" ;
2- import { mock } from "../../src/test-utils" ;
2+ import { clearORMStore , mock , setupTestUtils } from "../../src/test-utils" ;
33import { recordGraphQLRequest } from "../support/helpers" ;
4+ import VuexORMGraphQLPlugin from "../../src" ;
45
56// @ts -ignore
67let store ;
@@ -31,7 +32,7 @@ describe("TestUtils", () => {
3132 [ store , vuexOrmGraphQL ] = await setupMockData ( ) ;
3233 } ) ;
3334
34- test ( "allows to mock a fetch" , async ( ) => {
35+ it ( "allows to mock a fetch" , async ( ) => {
3536 mock ( "fetch" , { filter : { id : 42 } } )
3637 . for ( User )
3738 . andReturn ( userData ) ;
@@ -46,7 +47,7 @@ describe("TestUtils", () => {
4647 expect ( result ) . toEqual ( userResult ) ;
4748 } ) ;
4849
49- test ( "allows to return multiple records" , async ( ) => {
50+ it ( "allows to return multiple records" , async ( ) => {
5051 const userData2 = JSON . parse ( JSON . stringify ( userData ) ) ;
5152 userData2 . id = 8 ;
5253 userData2 . name = "Snoopy" ;
@@ -88,7 +89,7 @@ describe("TestUtils", () => {
8889 } ) ;
8990 } ) ;
9091
91- test ( "only mocks matched options" , async ( ) => {
92+ it ( "only mocks matched options" , async ( ) => {
9293 mock ( "fetch" , { filter : { id : 42 } } )
9394 . for ( User )
9495 . andReturn ( userData ) ;
@@ -103,7 +104,26 @@ describe("TestUtils", () => {
103104 expect ( result ) . not . toEqual ( userResult ) ;
104105 } ) ;
105106
106- test ( "allows to mock a action with a dynamic value" , async ( ) => {
107+ it ( "only mocks once" , async ( ) => {
108+ mock ( "fetch" , { filter : { id : 42 } } )
109+ . for ( User )
110+ . andReturn ( userData ) ;
111+
112+ mock ( "fetch" , { filter : { id : 42 } } )
113+ . for ( User )
114+ . andReturn ( userData ) ;
115+
116+ let result ;
117+ const request = await recordGraphQLRequest ( async ( ) => {
118+ // @ts -ignore
119+ result = await User . fetch ( 1 ) ;
120+ } , true ) ;
121+
122+ expect ( request ) . not . toEqual ( null ) ;
123+ expect ( result ) . not . toEqual ( userResult ) ;
124+ } ) ;
125+
126+ it ( "allows to mock a action with a dynamic value" , async ( ) => {
107127 mock ( "fetch" , { filter : { id : 42 } } )
108128 . for ( User )
109129 . andReturn ( ( ) => userData ) ;
@@ -118,7 +138,7 @@ describe("TestUtils", () => {
118138 expect ( result ) . toEqual ( userResult ) ;
119139 } ) ;
120140
121- test ( "allows to mock a action without options" , async ( ) => {
141+ it ( "allows to mock a action without options" , async ( ) => {
122142 mock ( "fetch" )
123143 . for ( User )
124144 . andReturn ( ( ) => userData ) ;
@@ -133,7 +153,7 @@ describe("TestUtils", () => {
133153 expect ( result ) . toEqual ( userResult ) ;
134154 } ) ;
135155
136- test ( "allows to mock a action without partial matching options" , async ( ) => {
156+ it ( "allows to mock a action without partial matching options" , async ( ) => {
137157 mock ( "fetch" , { filter : { id : 42 } } )
138158 . for ( User )
139159 . andReturn ( ( ) => userData ) ;
@@ -148,7 +168,7 @@ describe("TestUtils", () => {
148168 expect ( result ) . toEqual ( userResult ) ;
149169 } ) ;
150170
151- test ( "allows to mock a destroy" , async ( ) => {
171+ it ( "allows to mock a destroy" , async ( ) => {
152172 mock ( "destroy" , { id : 42 } )
153173 . for ( User )
154174 . andReturn ( userData ) ;
@@ -165,7 +185,7 @@ describe("TestUtils", () => {
165185 expect ( result ) . toEqual ( true ) ;
166186 } ) ;
167187
168- test ( "allows to mock a mutate" , async ( ) => {
188+ it ( "allows to mock a mutate" , async ( ) => {
169189 mock ( "mutate" , { name : "upvote" , args : { id : 4 } } )
170190 . for ( Post )
171191 . andReturn ( {
@@ -203,7 +223,7 @@ describe("TestUtils", () => {
203223 } ) ;
204224 } ) ;
205225
206- test ( "allows to mock a persist" , async ( ) => {
226+ it ( "allows to mock a persist" , async ( ) => {
207227 mock ( "persist" , { id : 42 } )
208228 . for ( User )
209229 . andReturn ( userData ) ;
@@ -220,7 +240,7 @@ describe("TestUtils", () => {
220240 expect ( result ) . toEqual ( userResult ) ;
221241 } ) ;
222242
223- test ( "allows to mock a push" , async ( ) => {
243+ it ( "allows to mock a push" , async ( ) => {
224244 mock ( "push" )
225245 . for ( User )
226246 . andReturn ( userData ) ;
@@ -237,7 +257,7 @@ describe("TestUtils", () => {
237257 expect ( result ) . toEqual ( userResult ) ;
238258 } ) ;
239259
240- test ( "allows to mock a custom query" , async ( ) => {
260+ it ( "allows to mock a custom query" , async ( ) => {
241261 mock ( "query" , { name : "example" } )
242262 . for ( User )
243263 . andReturn ( userData ) ;
@@ -252,7 +272,7 @@ describe("TestUtils", () => {
252272 expect ( result ) . not . toEqual ( null ) ;
253273 } ) ;
254274
255- test ( "allows to mock a simple mutation" , async ( ) => {
275+ it ( "allows to mock a simple mutation" , async ( ) => {
256276 mock ( "simpleMutation" , {
257277 name : "SendSms" ,
258278 variables : { to : "+4912345678" , text : "GraphQL is awesome!" }
@@ -279,7 +299,7 @@ describe("TestUtils", () => {
279299 expect ( result ) . toEqual ( { sendSms : { delivered : true } } ) ;
280300 } ) ;
281301
282- test ( "allows to mock a simple query" , async ( ) => {
302+ it ( "allows to mock a simple query" , async ( ) => {
283303 mock ( "simpleQuery" , { name : "example" } ) . andReturn ( { success : true } ) ;
284304
285305 let result ;
@@ -297,4 +317,13 @@ describe("TestUtils", () => {
297317 expect ( request ) . toEqual ( null ) ;
298318 expect ( result ) . toEqual ( { success : true } ) ;
299319 } ) ;
320+
321+ describe ( "clearORMStore" , ( ) => {
322+ it ( "cleans the store" , async ( ) => {
323+ await Post . create ( { data : { name : "test" } } ) ;
324+ expect ( Post . find ( 1 ) ) . not . toEqual ( null ) ;
325+ await clearORMStore ( ) ;
326+ expect ( Post . find ( 1 ) ) . toEqual ( null ) ;
327+ } ) ;
328+ } ) ;
300329} ) ;
0 commit comments