@@ -305,6 +305,40 @@ describe('REST server tests', () => {
305305 } ) ;
306306 } ) ;
307307
308+ it ( 'returns an empty data array when loading empty related resources' , async ( ) => {
309+ // Create a user first
310+ await prisma . user . create ( {
311+ data :
{ myId :
'user1' , email :
'[email protected] ' } , 312+ } ) ;
313+
314+ const r = await handler ( {
315+ method : 'get' ,
316+ path : '/user/user1' ,
317+ prisma,
318+ } ) ;
319+
320+ expect ( r . status ) . toBe ( 200 ) ;
321+ expect ( r . body ) . toMatchObject ( {
322+ data : {
323+ type : 'user' ,
324+ id : 'user1' ,
325+ attributes :
{ email :
'[email protected] ' } , 326+ links : {
327+ self : 'http://localhost/api/user/user1' ,
328+ } ,
329+ relationships : {
330+ posts : {
331+ links : {
332+ self : 'http://localhost/api/user/user1/relationships/posts' ,
333+ related : 'http://localhost/api/user/user1/posts' ,
334+ } ,
335+ data : [ ] ,
336+ } ,
337+ } ,
338+ } ,
339+ } ) ;
340+ } ) ;
341+
308342 it ( 'fetches a related resource with a compound ID' , async ( ) => {
309343 await prisma . user . create ( {
310344 data : {
@@ -1785,6 +1819,54 @@ describe('REST server tests', () => {
17851819 } ) ;
17861820 } ) ;
17871821
1822+ it ( "returns an empty data list in relationships if it's empty" , async ( ) => {
1823+ await prisma . user . create ( {
1824+ data : {
1825+ myId : 'user1' ,
1826+ 1827+ } ,
1828+ } ) ;
1829+
1830+ const r = await handler ( {
1831+ method : 'put' ,
1832+ path : '/user/user1' ,
1833+ query : { } ,
1834+ requestBody : {
1835+ data : {
1836+ type : 'user' ,
1837+ attributes :
{ email :
'[email protected] ' } , 1838+ } ,
1839+ } ,
1840+ prisma,
1841+ } ) ;
1842+
1843+ expect ( r . status ) . toBe ( 200 ) ;
1844+ expect ( r . body ) . toMatchObject ( {
1845+ links : {
1846+ self : 'http://localhost/api/user/user1' ,
1847+ } ,
1848+ data : {
1849+ type : 'user' ,
1850+ id : 'user1' ,
1851+ attributes : {
1852+ 1853+ } ,
1854+ links : {
1855+ self : 'http://localhost/api/user/user1' ,
1856+ } ,
1857+ relationships : {
1858+ posts : {
1859+ links : {
1860+ self : 'http://localhost/api/user/user1/relationships/posts' ,
1861+ related : 'http://localhost/api/user/user1/posts' ,
1862+ } ,
1863+ data : [ ] ,
1864+ } ,
1865+ } ,
1866+ } ,
1867+ } ) ;
1868+ } ) ;
1869+
17881870 it ( 'returns 404 if the user does not exist' , async ( ) => {
17891871 const r = await handler ( {
17901872 method : 'put' ,
0 commit comments