@@ -161,8 +161,6 @@ describe('REST server tests', () => {
161161
162162 // expect(r.status).toBe(200);
163163
164- // console.log('body', JSON.stringify(r.body));
165-
166164 // expect(r.body.data).toEqual([
167165 // {
168166 // type: 'user',
@@ -249,8 +247,6 @@ describe('REST server tests', () => {
249247
250248 // expect(r.status).toBe(200);
251249
252- // console.log('body', JSON.stringify(r.body));
253-
254250 // expect(r.body.data).toEqual([
255251 // {
256252 // type: 'user',
@@ -346,46 +342,84 @@ describe('REST server tests', () => {
346342 // ]);
347343 // });
348344
349- it ( 'returns the full item when the ID is specified' , async ( ) => {
350- // Create a user first
351- await prisma . user . create ( {
352- data : {
353- myId : 'user1' ,
354- email : 'user1@abc.com' ,
355- nickName : 'User 1' ,
356- posts : { create : { title : 'Post1' , content : 'Post 1 Content' } } ,
357- } ,
358- } ) ;
345+ // it('returns the full item when the ID is specified', async () => {
346+ // // Create a user first
347+ // await prisma.user.create({
348+ // data: {
349+ // myId: 'user1',
350+ // email: 'user1@abc.com',
351+ // nickName: 'User 1',
352+ // posts: { create: { title: 'Post1', content: 'Post 1 Content' } },
353+ // },
354+ // });
359355
360- const r = await handler ( {
361- method : 'get' ,
362- path : '/user/user1' ,
363- prisma,
364- } ) ;
356+ // const r = await handler({
357+ // method: 'get',
358+ // path: '/user/user1',
359+ // prisma,
360+ // });
365361
366- expect ( r . status ) . toBe ( 200 ) ;
367- expect ( r . body ) . toMatchObject ( {
368- data : {
369- type : 'user' ,
370- id : 'user1' ,
371- attributes : { email : 'user1@abc.com' , nickName : 'User 1' } ,
372- links : {
373- self : 'http://localhost/api/user/user1' ,
374- } ,
375- relationships : {
376- posts : {
377- links : {
378- self : 'http://localhost/api/user/user1/relationships/posts' ,
379- related : 'http://localhost/api/user/user1/posts' ,
380- } ,
381- data : [ { type : 'post' , id : 1 } ] ,
382- } ,
383- } ,
384- } ,
385- } ) ;
386- } ) ;
362+ // expect(r.status).toBe(200);
363+ // expect(r.body).toMatchObject({
364+ // data: {
365+ // type: 'user',
366+ // id: 'user1',
367+ // attributes: { email: 'user1@abc.com', nickName: 'User 1' },
368+ // links: {
369+ // self: 'http://localhost/api/user/user1',
370+ // },
371+ // relationships: {
372+ // posts: {
373+ // links: {
374+ // self: 'http://localhost/api/user/user1/relationships/posts',
375+ // related: 'http://localhost/api/user/user1/posts',
376+ // },
377+ // data: [{ type: 'post', id: 1 }],
378+ // },
379+ // },
380+ // },
381+ // });
382+ // });
387383
388- it ( 'returns only the requested fields when the ID is specified' , async ( ) => {
384+ // it('returns only the requested fields when the ID is specified', async () => {
385+ // // Create a user first
386+ // await prisma.user.create({
387+ // data: {
388+ // myId: 'user1',
389+ // email: 'user1@abc.com',
390+ // nickName: 'User 1',
391+ // posts: { create: { title: 'Post1', content: 'Post 1 Content' } },
392+ // },
393+ // });
394+
395+ // const r = await handler({
396+ // method: 'get',
397+ // path: '/user/user1',
398+ // prisma,
399+ // query: { ['fields[user]']: 'email' },
400+ // });
401+
402+ // expect(r.status).toBe(200);
403+ // expect(r.body.data).toEqual({
404+ // type: 'user',
405+ // id: 'user1',
406+ // attributes: { email: 'user1@abc.com' },
407+ // links: {
408+ // self: 'http://localhost/api/user/user1',
409+ // },
410+ // relationships: {
411+ // posts: {
412+ // links: {
413+ // self: 'http://localhost/api/user/user1/relationships/posts',
414+ // related: 'http://localhost/api/user/user1/posts',
415+ // },
416+ // data: [{ type: 'post', id: 1 }],
417+ // },
418+ // },
419+ // });
420+ // });
421+
422+ it ( 'returns only the requested fields when the ID is specified and has an include' , async ( ) => {
389423 // Create a user first
390424 await prisma . user . create ( {
391425 data : {
@@ -400,14 +434,14 @@ describe('REST server tests', () => {
400434 method : 'get' ,
401435 path : '/user/user1' ,
402436 prisma,
403- query : { [ 'fields[user]' ] : 'email' } ,
437+ query : { [ 'fields[user]' ] : 'email,nickName' , [ 'fields[post]' ] : 'title,published' , include : 'posts ' } ,
404438 } ) ;
405439
406440 expect ( r . status ) . toBe ( 200 ) ;
407441 expect ( r . body . data ) . toEqual ( {
408442 type : 'user' ,
409443 id : 'user1' ,
410- attributes : { email : 'user1@abc.com' } ,
444+ attributes : { email : 'user1@abc.com' , nickName : 'User 1' } ,
411445 links : {
412446 self : 'http://localhost/api/user/user1' ,
413447 } ,
@@ -421,6 +455,28 @@ describe('REST server tests', () => {
421455 } ,
422456 } ,
423457 } ) ;
458+
459+ expect ( r . body . included ) . toEqual ( [
460+ {
461+ type : 'post' ,
462+ id : 1 ,
463+ attributes : {
464+ title : 'Post1' ,
465+ published : false ,
466+ } ,
467+ links : {
468+ self : 'http://localhost/api/post/1' ,
469+ } ,
470+ relationships : {
471+ author : {
472+ links : {
473+ self : 'http://localhost/api/post/1/relationships/author' ,
474+ related : 'http://localhost/api/post/1/author' ,
475+ } ,
476+ } ,
477+ } ,
478+ } ,
479+ ] ) ;
424480 } ) ;
425481
426482 /**
0 commit comments