Browse Source

test: draft framework (WIP)

pull/7304/head
Raju Udava 12 months ago
parent
commit
dda4993b6a
  1. 33
      packages/nocodb/tests/unit/factory/table.ts
  2. 115
      packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts

33
packages/nocodb/tests/unit/factory/table.ts

@ -20,13 +20,23 @@ const createTable = async (context, base, args = {}) => {
return table;
};
const getTable = async ({
base,
name,
}: {
base: Base;
name: string;
}) => {
const getTableByAPI = async (context, base) => {
const response = await request(context.app)
.get(`/api/v1/db/meta/projects/${base.id}/tables`)
.set('xc-auth', context.token);
return response.body;
};
const getColumnsByAPI = async (context, base, table) => {
const response = await request(context.app)
.get(`/api/v2/meta/tables/${table.id}`)
.set('xc-auth', context.token);
return response.body;
};
const getTable = async ({ base, name }: { base: Base; name: string }) => {
const sources = await base.getSources();
return await Model.getByIdOrName({
base_id: base.id,
@ -57,4 +67,11 @@ const updateTable = async (
return response.body;
};
export { createTable, getTable, getAllTables, updateTable };
export {
createTable,
getTable,
getAllTables,
updateTable,
getTableByAPI,
getColumnsByAPI,
};

115
packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts

@ -6,7 +6,13 @@ import { expect } from 'chai';
import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/base';
import { createColumn, createQrCodeColumn } from '../../factory/column';
import { getTable } from '../../factory/table';
import {
createTable,
getColumnsByAPI,
getTable,
getTableByAPI,
} 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';
@ -27,34 +33,34 @@ function columnTypeSpecificTests() {
const qrValueReferenceColumnTitle = 'Qr Value Column';
const qrCodeReferenceColumnTitle = 'Qr Code Column';
beforeEach(async function () {
console.time('#### columnTypeSpecificTests');
context = await init(true);
describe('Qr Code Column', () => {
beforeEach(async function () {
console.time('#### columnTypeSpecificTests');
context = await init(true);
sakilaProject = await createSakilaProject(context);
base = await createProject(context);
sakilaProject = await createSakilaProject(context);
base = await createProject(context);
customerTable = await getTable({
base: sakilaProject,
name: 'customer',
});
customerTable = await getTable({
base: sakilaProject,
name: 'customer',
});
qrValueReferenceColumn = await createColumn(context, customerTable, {
title: qrValueReferenceColumnTitle,
uidt: UITypes.SingleLineText,
table_name: customerTable.table_name,
column_name: qrValueReferenceColumnTitle,
});
qrValueReferenceColumn = await createColumn(context, customerTable, {
title: qrValueReferenceColumnTitle,
uidt: UITypes.SingleLineText,
table_name: customerTable.table_name,
column_name: qrValueReferenceColumnTitle,
});
await createQrCodeColumn(context, {
title: qrCodeReferenceColumnTitle,
table: customerTable,
referencedQrValueTableColumnTitle: qrValueReferenceColumnTitle,
await createQrCodeColumn(context, {
title: qrCodeReferenceColumnTitle,
table: customerTable,
referencedQrValueTableColumnTitle: qrValueReferenceColumnTitle,
});
console.timeEnd('#### columnTypeSpecificTests');
});
console.timeEnd('#### columnTypeSpecificTests');
});
describe('Qr Code Column', () => {
it('delivers the same cell values as the referenced column', async () => {
const resp = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}`)
@ -93,6 +99,69 @@ function columnTypeSpecificTests() {
).to.eq(false);
});
});
// Created-at, Last-modified-at field
let table: Model;
let columns: any[];
let unfilteredRecords: any[] = [];
describe.skip('CreatedAt, LastModifiedAt Field', () => {
beforeEach(async function () {
context = await init();
base = await createProject(context);
table = await createTable(context, base, {
table_name: 'dateBased',
title: 'dateBased',
columns: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Date',
title: 'Date',
uidt: UITypes.Date,
},
// {
// column_name: 'CreatedAt',
// title: 'CreatedAt',
// uidt: UITypes.CreatedTime,
// },
// {
// column_name: 'LastModifiedAt',
// title: 'LastModifiedAt',
// uidt: UITypes.LastModifiedTime,
// },
],
});
columns = await table.getColumns();
const rowAttributes = [];
for (let i = 0; i < 100; i++) {
const row = {
Date: rowMixedValue(columns[1], i),
};
rowAttributes.push(row);
}
await createBulkRows(context, {
base,
table,
values: rowAttributes,
});
unfilteredRecords = await listRow({ base, table });
// verify length of unfiltered records to be 800
expect(unfilteredRecords.length).to.equal(100);
});
it('should filter records by created-at field', async () => {
console.log('test');
});
});
}
export default function () {

Loading…
Cancel
Save