Skip to content

Commit 4d75919

Browse files
authored
chore(api): more test cases for mapped model names (#2190)
1 parent f2c2725 commit 4d75919

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

packages/server/tests/api/rest.test.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,6 @@ describe('REST server tests', () => {
30393039
endpoint: 'http://localhost/api',
30403040
modelNameMapping: {
30413041
user: 'myUser',
3042-
post: 'myPost',
30433042
},
30443043
});
30453044
handler = (args) =>
@@ -3053,7 +3052,7 @@ describe('REST server tests', () => {
30533052
method: 'post',
30543053
path: '/user',
30553054
query: {},
3056-
requestBody: { data: { type: 'user', attributes: { name: 'User1' } } },
3055+
requestBody: { data: { type: 'user', attributes: { id: '1', name: 'User1' } } },
30573056
prisma,
30583057
})
30593058
).resolves.toMatchObject({
@@ -3066,7 +3065,45 @@ describe('REST server tests', () => {
30663065
method: 'post',
30673066
path: '/myUser',
30683067
query: {},
3069-
requestBody: { data: { type: 'user', attributes: { name: 'User1' } } },
3068+
requestBody: { data: { type: 'user', attributes: { id: '1', name: 'User1' } } },
3069+
prisma,
3070+
})
3071+
).resolves.toMatchObject({
3072+
status: 201,
3073+
body: {
3074+
links: { self: 'http://localhost/api/myUser/1' },
3075+
},
3076+
});
3077+
3078+
await expect(
3079+
handler({
3080+
method: 'get',
3081+
path: '/myUser/1',
3082+
query: {},
3083+
prisma,
3084+
})
3085+
).resolves.toMatchObject({
3086+
status: 200,
3087+
body: {
3088+
links: { self: 'http://localhost/api/myUser/1' },
3089+
},
3090+
});
3091+
3092+
// works with unmapped model name
3093+
await expect(
3094+
handler({
3095+
method: 'post',
3096+
path: '/post',
3097+
query: {},
3098+
requestBody: {
3099+
data: {
3100+
type: 'post',
3101+
attributes: { id: '1', title: 'Post1' },
3102+
relationships: {
3103+
author: { data: { type: 'user', id: '1' } },
3104+
},
3105+
},
3106+
},
30703107
prisma,
30713108
})
30723109
).resolves.toMatchObject({

0 commit comments

Comments
 (0)