@@ -6,7 +6,6 @@ import { loadSchema, run } from '@zenstackhq/testtools';
6
6
import { Decimal } from 'decimal.js' ;
7
7
import SuperJSON from 'superjson' ;
8
8
import makeHandler , { idDivider } from '../../src/api/rest' ;
9
- import e from 'express' ;
10
9
11
10
describe ( 'REST server tests' , ( ) => {
12
11
let prisma : any ;
@@ -137,7 +136,7 @@ describe('REST server tests', () => {
137
136
path : '/user' ,
138
137
prisma,
139
138
} ) ;
140
- console . log ( 'yufail' , JSON . stringify ( r ) ) ;
139
+
141
140
expect ( r . status ) . toBe ( 200 ) ;
142
141
expect ( r . body ) . toMatchObject ( {
143
142
data : [ ] ,
@@ -324,8 +323,6 @@ describe('REST server tests', () => {
324
323
prisma,
325
324
} ) ;
326
325
327
- console . log ( 'yufail' , JSON . stringify ( r ) ) ;
328
-
329
326
expect ( r . status ) . toBe ( 200 ) ;
330
327
expect ( r . body ) . toMatchObject ( {
331
328
links : {
@@ -1641,6 +1638,27 @@ describe('REST server tests', () => {
1641
1638
expect ( r . status ) . toBe ( 404 ) ;
1642
1639
} ) ;
1643
1640
1641
+ it ( 'create relation with compound id' , async ( ) => {
1642
+ await prisma . user . create ( { data : { myId : 'user1' , email : 'user1@abc.com' } } ) ;
1643
+ await prisma . post . create ( { data : { id : 1 , title : 'Post1' } } ) ;
1644
+
1645
+ const r = await handler ( {
1646
+ method : 'post' ,
1647
+ path : '/postLike' ,
1648
+ query : { } ,
1649
+ requestBody : {
1650
+ data : {
1651
+ type : 'postLike' ,
1652
+ id : `1${ idDivider } user1` ,
1653
+ attributes : { userId : 'user1' , postId : 1 , superLike : false } ,
1654
+ } ,
1655
+ } ,
1656
+ prisma,
1657
+ } ) ;
1658
+
1659
+ expect ( r . status ) . toBe ( 201 ) ;
1660
+ } ) ;
1661
+
1644
1662
describe ( 'compound id' , ( ) => {
1645
1663
beforeEach ( async ( ) => {
1646
1664
await prisma . user . create ( { data : { myId : 'user1' , email : 'user1@abc.com' } } ) ;
@@ -1909,6 +1927,24 @@ describe('REST server tests', () => {
1909
1927
} ) ;
1910
1928
} ) ;
1911
1929
1930
+ it ( 'update a collection of relations with compound id' , async ( ) => {
1931
+ await prisma . user . create ( { data : { myId : 'user1' , email : 'user1@abc.com' } } ) ;
1932
+ await prisma . post . create ( { data : { id : 1 , title : 'Post1' } } ) ;
1933
+ await prisma . postLike . create ( { data : { userId : 'user1' , postId : 1 , superLike : false } } ) ;
1934
+
1935
+ const r = await handler ( {
1936
+ method : 'patch' ,
1937
+ path : '/post/1/relationships/likes' ,
1938
+ query : { } ,
1939
+ requestBody : {
1940
+ data : [ { type : 'postLike' , id : '1_user1' , attributes : { superLike : true } } ] ,
1941
+ } ,
1942
+ prisma,
1943
+ } ) ;
1944
+
1945
+ expect ( r . status ) . toBe ( 200 ) ;
1946
+ } ) ;
1947
+
1912
1948
it ( 'update a collection of relations to empty' , async ( ) => {
1913
1949
await prisma . user . create ( {
1914
1950
data : { myId : 'user1' , email : 'user1@abc.com' , posts : { create : { id : 1 , title : 'Post1' } } } ,
0 commit comments