From fdf42d269c594b6dbca16f73d5b3c270fbc6cb1e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Fri, 12 Jul 2024 18:22:03 +0000 Subject: [PATCH] test: unit test --- packages/nocodb/tests/unit/rest/index.test.ts | 2 + .../tests/unit/rest/tests/column.test.ts | 153 ++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 packages/nocodb/tests/unit/rest/tests/column.test.ts diff --git a/packages/nocodb/tests/unit/rest/index.test.ts b/packages/nocodb/tests/unit/rest/index.test.ts index a9208b7be4..c537822a62 100644 --- a/packages/nocodb/tests/unit/rest/index.test.ts +++ b/packages/nocodb/tests/unit/rest/index.test.ts @@ -14,6 +14,7 @@ import formulaTests from './tests/formula.test'; import typeCastsTest from './tests/typeCasts.test'; import readOnlyTest from './tests/readOnlySource.test'; import aggregationTest from './tests/aggregation.test'; +import columnTests from './tests/column.test'; let workspaceTest = () => {}; let ssoTest = () => {}; @@ -48,6 +49,7 @@ function restTests() { readOnlyTest(); aggregationTest(); bulkAggregationTest(); + columnTests(); // Enable for dashboard feature // widgetTest(); diff --git a/packages/nocodb/tests/unit/rest/tests/column.test.ts b/packages/nocodb/tests/unit/rest/tests/column.test.ts new file mode 100644 index 0000000000..a073921899 --- /dev/null +++ b/packages/nocodb/tests/unit/rest/tests/column.test.ts @@ -0,0 +1,153 @@ +import 'mocha'; +import request from 'supertest'; +import { UITypes } from 'nocodb-sdk'; +import { expect } from 'chai'; +import init from '../../init'; +import { createProject, createSakilaProject } from '../../factory/base'; +import { + createColumn, + createQrCodeColumn, + deleteColumn, +} from '../../factory/column'; +import { createTable, getColumnsByAPI, getTable } from '../../factory/table'; +import { createBulkRows, listRow, rowMixedValue } from '../../factory/row'; +import type Model from '../../../../src/models/Model'; +import type Base from '~/models/Base'; +import type Column from '../../../../src/models/Column'; + +// Test case list +// 1. Advanced link creation +function columnTests() { + let context; + let base: Base; + + const qrValueReferenceColumnTitle = 'Qr Value Column'; + const qrCodeReferenceColumnTitle = 'Qr Code Column'; + + const defaultTableColumns = [ + { + title: 'Id', + uidt: UITypes.ID, + system: false, + }, + { + title: 'DateField', + uidt: UITypes.Date, + system: false, + }, + { + title: 'CreatedAt', + uidt: UITypes.CreatedTime, + system: true, + }, + { + title: 'UpdatedAt', + uidt: UITypes.LastModifiedTime, + system: true, + }, + { + title: 'nc_created_by', + uidt: UITypes.CreatedBy, + system: true, + }, + { + title: 'nc_updated_by', + uidt: UITypes.LastModifiedBy, + system: true, + }, + ]; + + describe('Advance Column', () => { + beforeEach(async function () { + console.time('#### columnTypeSpecificTests'); + context = await init(true); + + // sakilaProject = await createSakilaProject(context); + base = await createProject(context); + + console.timeEnd('#### columnTypeSpecificTests'); + }); + + it.only('Create HM relation', async () => { + let table1: Model; + let table2: Model; + + table1 = await createTable(context, base.id, { + title: 'Country', + columns: defaultTableColumns, + }); + table2 = await createTable(context, base.id, { + title: 'City', + columns: [ + ...defaultTableColumns, + { + title: 'Table1Id', + uidt: UITypes.Number, + }, + ], + }); + + const response = await request(context.app) + .post(`/api/v1/db/meta/projects/${base.id}/columns`) + .set('xc-auth', context.token) + .send({ + title: 'Country', + uidt: UITypes.Links, + custom: { + base_id: meta.value?.base_id, + column_id: pkColumn.value?.id, + junc_base_id: meta.value?.base_id, + }, + }); + }); + it.only('Create MM relation', async () => { + let table1: Model; + let table2: Model; + + const film = await createTable(context, base.id, { + title: 'Film', + columns: defaultTableColumns, + }); + const actor = await createTable(context, base.id, { + title: 'Actor', + columns: [ + ...defaultTableColumns, + { + title: 'Table1Id', + uidt: UITypes.Number, + }, + ], + }); + + const filmActor = await createTable(context, base.id, { + title: 'FilmActor', + columns: [ + { + title: 'ActorId', + uidt: UITypes.Number, + }, + { + title: 'FilmId', + uidt: UITypes.Number, + }, + ], + }); + const response = await request(context.app) + .post(`/api/v1/db/meta/projects/${base.id}/columns`) + .set('xc-auth', context.token) + .send({ + title: 'Actor', + uidt: UITypes.Links, + custom: { + base_id: meta.value?.base_id, + column_id: pkColumn.value?.id, + junc_base_id: meta.value?.base_id, + }, + }); + }); + }); +} + +export default function () { + describe('Column', columnTests); +}