From 31d2fa437808633a785f7e5b676ac0d740aacb95 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Wed, 7 Sep 2022 14:17:50 +0530 Subject: [PATCH] refactor/Added unit test for view row api --- .../lib/meta/api/dataApis/dataAliasApis.ts | 1 + .../tests/unit/rest/tests/viewRow.test.ts | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts index ac73cea258..854262a5aa 100644 --- a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts +++ b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts @@ -47,6 +47,7 @@ async function dataCount(req: Request, res: Response) { res.json({ count }); } +// todo: Handle the error case where view doesnt belong to model async function dataInsert(req: Request, res: Response) { const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); diff --git a/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts b/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts index 1fa875991a..273bb405bc 100644 --- a/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts +++ b/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts @@ -511,6 +511,35 @@ function viewRowTests() { it('Create table row form', async function () { await testCreateRowView(ViewTypes.FORM); }); + + const testCreateRowViewWithWrongView = async (viewType: ViewTypes) => { + const table = await createTable(context, project); + const nonRelatedView = await createView(context, { + title: 'View', + table: customerTable, + type: viewType + }); + + await request(context.app) + .post(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${nonRelatedView.id}`) + .set('xc-auth', context.token) + .send({ + title: 'Test', + }) + .expect(400); + } + + it('Create table row grid wrong grid id', async function () { + await testCreateRowViewWithWrongView(ViewTypes.GRID); + }); + + it('Create table row wrong gallery id', async function () { + await testCreateRowViewWithWrongView(ViewTypes.GALLERY); + }); + + it('Create table row wrong form id', async function () { + await testCreateRowViewWithWrongView(ViewTypes.FORM); + }); } export default function () {