2
2
3
3
import { MemoryCache } from '@/lib/cache/MemoryCache' ;
4
4
import { getResolver } from '@/resolvers/stories' ;
5
+ const hash = require ( 'object-hash' ) ;
5
6
6
7
let cache : MemoryCache ;
7
8
let resolver : any ;
@@ -16,7 +17,8 @@ beforeEach(() => {
16
17
} ) ;
17
18
18
19
it ( 'it retrieves the story data and returns it' , async ( ) => {
19
- const data = await resolver ( { } , { first : 2 , kind : 'NEW' } ) ;
20
+ const req = { body : { first : 2 , kind : 'NEW' , a : 1 , b : 2 } } ;
21
+ const data = await resolver ( { } , { first : 2 , kind : 'NEW' } , { req } ) ;
20
22
21
23
for ( const item of data ) {
22
24
//item.ts = 0;
@@ -27,13 +29,17 @@ it('it retrieves the story data and returns it', async () => {
27
29
} ) ;
28
30
29
31
it ( 'it retrieves the user data and caches it' , async ( ) => {
30
- await resolver ( { } , { first : 2 , kind : 'NEW' } ) ;
32
+ const req = { body : { query : 'abc' , vars : 'bbb' } } ;
33
+ const reqHash = hash ( req . body ) ;
31
34
32
- expect ( cache . has ( 'newstoryids:2' ) ) . toBeTruthy ( ) ;
35
+ await resolver ( { } , { first : 2 , kind : 'NEW' } , { req } ) ;
36
+
37
+ expect ( await cache . has ( `newstoryids:2:${ reqHash } ` ) ) . toBeTruthy ( ) ;
33
38
} ) ;
34
39
35
40
it ( 'it retrieves each story and caches it' , async ( ) => {
36
- const data = await resolver ( { } , { first : 2 , kind : 'NEW' } ) ;
41
+ const req = { body : { first : 2 , kind : 'NEW' , a : 1 , b : 2 } } ;
42
+ const data = await resolver ( { } , { first : 2 , kind : 'NEW' } , { req } ) ;
37
43
38
44
data . forEach ( item => {
39
45
expect ( cache . has ( `newstory:${ item . id } ` ) ) . toBeTruthy ( ) ;
0 commit comments