1
1
import resolvers from '../src/resolvers' ;
2
2
import expectMockFields from './helpers/expectMockFields' ;
3
- import expectMockList from './helpers/expectMockList' ;
3
+ // import expectMockList from './helpers/expectMockList';
4
4
import expectNullable from './helpers/expectNullable' ;
5
5
6
- // TODO: Update the data source name.
7
- const DATA_SOURCE_NAME = 'YourDataSource' ;
6
+ const DATA_SOURCE_NAME = 'OpenLibrary' ;
8
7
9
8
describe ( `${ DATA_SOURCE_NAME } resolvers` , ( ) => {
10
9
it ( 'returns valid resolvers' , ( ) => {
@@ -15,37 +14,41 @@ describe(`${DATA_SOURCE_NAME} resolvers`, () => {
15
14
] ) ;
16
15
} ) ;
17
16
17
+ const modelResult = {
18
+ title_suggest : 'Fight Club' ,
19
+ author_name : [ 'Chuck Palahniuk' ] ,
20
+ isbn : [ '9782070422401' ] ,
21
+ } ;
22
+
18
23
describe ( 'queryResolvers' , ( ) => {
19
24
describe ( DATA_SOURCE_NAME , ( ) => {
20
- it ( 'loads a thing by its ID ' , ( ) => {
25
+ it ( 'searches for a book by title ' , ( ) => {
21
26
expect . assertions ( 1 ) ;
22
27
23
28
const req = { } ;
24
29
25
- // TODO: Update with mock arguments for your model method.
26
- const args = { id : 'abc1234' } ;
30
+ const args = { title : 'Fight Club' } ;
27
31
28
- // TODO: Update with the data source model name and method(s).
29
32
const mockContext = {
30
- YourDataSource : {
31
- // For testing, we mock the model to simply return the ID.
32
- getById : id => Promise . resolve ( id ) ,
33
+ OpenLibrary : {
34
+ searchBooksByTitle : ( ) => Promise . resolve ( { docs : [ modelResult ] } ) ,
33
35
} ,
34
36
} ;
35
37
36
38
return expect (
37
- // TODO: Update to use your data source.
38
- resolvers . queryResolvers . YourDataSource ( req , args , mockContext ) ,
39
- ) . resolves . toEqual ( 'abc1234' ) ;
39
+ resolvers . queryResolvers . SearchBooksByTitle ( req , args , mockContext ) ,
40
+ ) . resolves . toEqual ( modelResult ) ;
40
41
} ) ;
41
42
} ) ;
42
43
} ) ;
43
44
44
45
describe ( 'dataResolvers' , ( ) => {
45
- describe ( 'PFX_YourDataSource' , ( ) => {
46
- const resolver = resolvers . dataResolvers . PFX_YourDataSource ;
47
-
48
- expectNullable ( resolver , [ 'name' ] ) ;
46
+ describe ( 'OL_SearchResult' , ( ) => {
47
+ const resolver = resolvers . dataResolvers . OL_SearchResult ;
48
+ expect ( resolver . title ( modelResult ) ) . toBe ( 'Fight Club' ) ;
49
+ expect ( resolver . author ( modelResult ) ) . toBe ( 'Chuck Palahniuk' ) ;
50
+ expect ( resolver . isbn ( modelResult ) ) . toBe ( '9782070422401' ) ;
51
+ expectNullable ( resolver , [ 'title' , 'author' , 'isbn' ] ) ;
49
52
} ) ;
50
53
} ) ;
51
54
@@ -55,11 +58,10 @@ describe(`${DATA_SOURCE_NAME} resolvers`, () => {
55
58
* exploding. To that end, we’ll just check that the mock response returns
56
59
* the proper fields.
57
60
*/
58
- describe ( 'PFX_YourDataSource ' , ( ) => {
59
- const mockResolvers = resolvers . mockResolvers . PFX_YourDataSource ( ) ;
61
+ describe ( 'OL_SearchResult ' , ( ) => {
62
+ const mockResolvers = resolvers . mockResolvers . OL_SearchResult ( ) ;
60
63
61
- expectMockFields ( mockResolvers , [ 'id' , 'name' , 'lucky_numbers' ] ) ;
62
- expectMockList ( mockResolvers , [ 'lucky_numbers' ] ) ;
64
+ expectMockFields ( mockResolvers , [ 'title' , 'author' , 'isbn' ] ) ;
63
65
} ) ;
64
66
} ) ;
65
67
} ) ;
0 commit comments