Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

add skeleton for column test

Fendy Heryanto62e7be6874c4
diff --git a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts
new file mode 100644
index 0000000000..854e5ef282
--- /dev/null
+++ b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts
@@ -0,0 +1,148 @@
+import 'mocha';
+import { expect } from 'chai';
+import request from 'supertest';
+import init from '../../../../init';
+
+export default function () {
+ describe('error-handling: Column v3', () => {
+ let context: Awaited<ReturnType<typeof init>>;
+ let initBase: any;
+ let API_PREFIX: string;
+ let table: any;
+
+ beforeEach(async () => {
+ context = await init();
+ const workspaceId = context.fk_workspace_id;
+ const baseResult = await request(context.app)
+ .post(`/api/v3/meta/workspaces/${workspaceId}/bases`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'MyBase' })
+ .expect(200);
+ initBase = baseResult.body;
+ API_PREFIX = `/api/v3/meta/bases/${initBase.id}`;
+ // create a table for column tests
+ const tableResult = await request(context.app)
+ .post(`${API_PREFIX}/tables`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'MyTable' })
+ .expect(200);
+ table = tableResult.body;
+ });
+
+ describe.only('column create', () => {
+ it('will handle empty title', async () => {
+ const result = await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: '', type: 'SingleLineText' })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include(
+ 'Missing column `title` property',
+ );
+ });
+ it('will handle duplicate alias', async () => {
+ await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'MyColumn', type: 'SingleLineText' })
+ .expect(200);
+ const result = await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'MyColumn', type: 'SingleLineText' })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include('Duplicate column alias');
+ });
+ it('will handle incorrect title length', async () => {
+ const longTitle = 'a'.repeat(300);
+ const result = await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: longTitle, type: 'SingleLineText' })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include('exceeds 255 characters');
+ });
+ it('will handle missing type', async () => {
+ const result = await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'NoType' })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include(
+ 'Missing column `type` property',
+ );
+ });
+ });
+
+ describe('column get', () => {
+ it('will handle column not found', async () => {
+ const result = await request(context.app)
+ .get(`${API_PREFIX}/fields/NOT_FOUND`)
+ .set('xc-token', context.xc_token)
+ .expect(422);
+ expect(result.body.error).to.eq('COLUMN_NOT_FOUND');
+ expect(result.body.message).to.include(`Column 'NOT_FOUND' not found`);
+ });
+ });
+
+ describe('column update', () => {
+ let column: any;
+ beforeEach(async () => {
+ const colResult = await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'UpdatableColumn', type: 'SingleLineText' })
+ .expect(200);
+ column = colResult.body;
+ });
+ it('will handle column not found', async () => {
+ const result = await request(context.app)
+ .patch(`${API_PREFIX}/fields/NOT_FOUND`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'any' })
+ .expect(422);
+ expect(result.body.error).to.eq('COLUMN_NOT_FOUND');
+ expect(result.body.message).to.include(`Column 'NOT_FOUND' not found`);
+ });
+ it('will handle duplicate alias', async () => {
+ await request(context.app)
+ .post(`${API_PREFIX}/tables/${table.id}/fields/`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'AnotherColumn', type: 'SingleLineText' })
+ .expect(200);
+ const result = await request(context.app)
+ .patch(`${API_PREFIX}/fields/${column.id}`)
+ .set('xc-token', context.xc_token)
+ .send({ title: 'AnotherColumn' })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include('Duplicate column alias');
+ });
+ it('will handle incorrect title length', async () => {
+ const longTitle = 'a'.repeat(300);
+ const result = await request(context.app)
+ .patch(`${API_PREFIX}/fields/${column.id}`)
+ .set('xc-token', context.xc_token)
+ .send({ title: longTitle })
+ .expect(400);
+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
+ expect(result.body.message).to.include('exceeds 255 characters');
+ });
+ });
+
+ describe('column delete', () => {
+ it('will handle column not found', async () => {
+ const result = await request(context.app)
+ .delete(`${API_PREFIX}/fields/NOT_FOUND`)
+ .set('xc-token', context.xc_token)
+ .expect(422);
+ expect(result.body.error).to.eq('COLUMN_NOT_FOUND');
+ expect(result.body.message).to.include(`Column 'NOT_FOUND' not found`);
+ });
+ });
+ });
+}
diff --git a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/index.test.ts b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/index.test.ts
index 98a40313a0..7e6e3bca9c 100644
--- a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/index.test.ts
+++ b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/index.test.ts
@@ -1,7 +1,9 @@
import baseTestV3 from './base.test';
import tableTestV3 from './table.test';
+import columnTestV3 from './column.test';
export default function () {
baseTestV3();
tableTestV3();
+ columnTestV3();
}