11import resolvers from '../src/resolvers' ;
22import expectMockFields from './helpers/expectMockFields' ;
3- import expectMockList from './helpers/expectMockList' ;
3+ // import expectMockList from './helpers/expectMockList';
44import expectNullable from './helpers/expectNullable' ;
55
6- // TODO: Update the data source name.
7- const DATA_SOURCE_NAME = 'YourDataSource' ;
6+ const DATA_SOURCE_NAME = 'OpenLibrary' ;
87
98describe ( `${ DATA_SOURCE_NAME } resolvers` , ( ) => {
109 it ( 'returns valid resolvers' , ( ) => {
@@ -15,37 +14,41 @@ describe(`${DATA_SOURCE_NAME} resolvers`, () => {
1514 ] ) ;
1615 } ) ;
1716
17+ const modelResult = {
18+ title_suggest : 'Fight Club' ,
19+ author_name : [ 'Chuck Palahniuk' ] ,
20+ isbn : [ '9782070422401' ] ,
21+ } ;
22+
1823 describe ( 'queryResolvers' , ( ) => {
1924 describe ( DATA_SOURCE_NAME , ( ) => {
20- it ( 'loads a thing by its ID ' , ( ) => {
25+ it ( 'searches for a book by title ' , ( ) => {
2126 expect . assertions ( 1 ) ;
2227
2328 const req = { } ;
2429
25- // TODO: Update with mock arguments for your model method.
26- const args = { id : 'abc1234' } ;
30+ const args = { title : 'Fight Club' } ;
2731
28- // TODO: Update with the data source model name and method(s).
2932 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 ] } ) ,
3335 } ,
3436 } ;
3537
3638 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 ) ;
4041 } ) ;
4142 } ) ;
4243 } ) ;
4344
4445 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' ] ) ;
4952 } ) ;
5053 } ) ;
5154
@@ -55,11 +58,10 @@ describe(`${DATA_SOURCE_NAME} resolvers`, () => {
5558 * exploding. To that end, we’ll just check that the mock response returns
5659 * the proper fields.
5760 */
58- describe ( 'PFX_YourDataSource ' , ( ) => {
59- const mockResolvers = resolvers . mockResolvers . PFX_YourDataSource ( ) ;
61+ describe ( 'OL_SearchResult ' , ( ) => {
62+ const mockResolvers = resolvers . mockResolvers . OL_SearchResult ( ) ;
6063
61- expectMockFields ( mockResolvers , [ 'id' , 'name' , 'lucky_numbers' ] ) ;
62- expectMockList ( mockResolvers , [ 'lucky_numbers' ] ) ;
64+ expectMockFields ( mockResolvers , [ 'title' , 'author' , 'isbn' ] ) ;
6365 } ) ;
6466 } ) ;
6567} ) ;
0 commit comments