Browse Source

test: corrections

pull/8367/head
Pranav C 4 months ago
parent
commit
c48b3da8f9
  1. 65
      packages/nocodb/tests/unit/rest/tests/column.test.ts

65
packages/nocodb/tests/unit/rest/tests/column.test.ts

@ -1,19 +1,11 @@
import 'mocha'; import 'mocha';
import request from 'supertest'; import request from 'supertest';
import { UITypes } from 'nocodb-sdk'; import { UITypes } from 'nocodb-sdk';
import { expect } from 'chai';
import init from '../../init'; import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/base'; import { createProject } from '../../factory/base';
import { import { createTable } from '../../factory/table';
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 Model from '../../../../src/models/Model';
import type Base from '~/models/Base'; import type Base from '~/models/Base';
import type Column from '../../../../src/models/Column';
// Test case list // Test case list
// 1. Advanced link creation // 1. Advanced link creation
@ -68,25 +60,27 @@ function columnTests() {
console.timeEnd('#### columnTypeSpecificTests'); console.timeEnd('#### columnTypeSpecificTests');
}); });
it.only('Create HM relation', async () => { it('Create HM relation', async () => {
let table1: Model; const country = await createTable(context, base.id, {
let table2: Model;
table1 = await createTable(context, base.id, {
title: 'Country', title: 'Country',
columns: defaultTableColumns, columns: defaultTableColumns,
}); });
table2 = await createTable(context, base.id, { const city = await createTable(context, base.id, {
title: 'City', title: 'City',
columns: [ columns: [
...defaultTableColumns, ...defaultTableColumns,
{ {
title: 'Table1Id', title: 'CountryId',
uidt: UITypes.Number, uidt: UITypes.Number,
}, },
], ],
}); });
const pkColumn = (await country.getColumns()).find((column) => column.pk);
const fkColumn = (await city.getColumns()).find(
(column) => column.title === 'CountryId',
);
const response = await request(context.app) const response = await request(context.app)
.post(`/api/v1/db/meta/projects/${base.id}/columns`) .post(`/api/v1/db/meta/projects/${base.id}/columns`)
.set('xc-auth', context.token) .set('xc-auth', context.token)
@ -94,16 +88,16 @@ function columnTests() {
title: 'Country', title: 'Country',
uidt: UITypes.Links, uidt: UITypes.Links,
custom: { custom: {
base_id: meta.value?.base_id, base_id: base.id,
column_id: pkColumn.value?.id, column_id: pkColumn?.id,
junc_base_id: meta.value?.base_id, ref_model_id: city.id,
ref_column_id: fkColumn?.id,
}, },
}); });
});
it.only('Create MM relation', async () => {
let table1: Model;
let table2: Model;
console.log(response.body);
});
it('Create MM relation', async () => {
const film = await createTable(context, base.id, { const film = await createTable(context, base.id, {
title: 'Film', title: 'Film',
columns: defaultTableColumns, columns: defaultTableColumns,
@ -132,6 +126,16 @@ function columnTests() {
}, },
], ],
}); });
const pkColumn = (await actor.getColumns()).find((column) => column.pk);
const refPkColumn = (await film.getColumns()).find((column) => column.pk);
const junColId = (await filmActor.getColumns()).find(
(column) => column.title === 'ActorId',
);
const juRefColId = (await filmActor.getColumns()).find(
(column) => column.title === 'FilmId',
);
const response = await request(context.app) const response = await request(context.app)
.post(`/api/v1/db/meta/projects/${base.id}/columns`) .post(`/api/v1/db/meta/projects/${base.id}/columns`)
.set('xc-auth', context.token) .set('xc-auth', context.token)
@ -139,11 +143,18 @@ function columnTests() {
title: 'Actor', title: 'Actor',
uidt: UITypes.Links, uidt: UITypes.Links,
custom: { custom: {
base_id: meta.value?.base_id, base_id: base.id,
column_id: pkColumn.value?.id, junc_base_id: base.id,
junc_base_id: meta.value?.base_id, column_id: pkColumn?.id,
junc_model_id: filmActor.id,
junc_column_id: junColId?.id,
junc_ref_column_id: juRefColId?.id,
ref_model_id: film.id,
ref_column_id: refPkColumn?.id,
}, },
}); });
console.log(response.body);
}); });
}); });
} }

Loading…
Cancel
Save