From 6371ac9429c8c984fca379f95b3772f5c2c87d56 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sat, 19 Jul 2025 10:18:34 +0800 Subject: [PATCH] chore(api): more test cases for mapped model names --- packages/server/tests/api/rest.test.ts | 43 ++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/server/tests/api/rest.test.ts b/packages/server/tests/api/rest.test.ts index 264a97e41..2ef74e5d2 100644 --- a/packages/server/tests/api/rest.test.ts +++ b/packages/server/tests/api/rest.test.ts @@ -3039,7 +3039,6 @@ describe('REST server tests', () => { endpoint: 'http://localhost/api', modelNameMapping: { user: 'myUser', - post: 'myPost', }, }); handler = (args) => @@ -3053,7 +3052,7 @@ describe('REST server tests', () => { method: 'post', path: '/user', query: {}, - requestBody: { data: { type: 'user', attributes: { name: 'User1' } } }, + requestBody: { data: { type: 'user', attributes: { id: '1', name: 'User1' } } }, prisma, }) ).resolves.toMatchObject({ @@ -3066,7 +3065,45 @@ describe('REST server tests', () => { method: 'post', path: '/myUser', query: {}, - requestBody: { data: { type: 'user', attributes: { name: 'User1' } } }, + requestBody: { data: { type: 'user', attributes: { id: '1', name: 'User1' } } }, + prisma, + }) + ).resolves.toMatchObject({ + status: 201, + body: { + links: { self: 'http://localhost/api/myUser/1' }, + }, + }); + + await expect( + handler({ + method: 'get', + path: '/myUser/1', + query: {}, + prisma, + }) + ).resolves.toMatchObject({ + status: 200, + body: { + links: { self: 'http://localhost/api/myUser/1' }, + }, + }); + + // works with unmapped model name + await expect( + handler({ + method: 'post', + path: '/post', + query: {}, + requestBody: { + data: { + type: 'post', + attributes: { id: '1', title: 'Post1' }, + relationships: { + author: { data: { type: 'user', id: '1' } }, + }, + }, + }, prisma, }) ).resolves.toMatchObject({