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

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

@ -6,7 +6,13 @@ import { expect } from 'chai';
import init from '../../init'; import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/base'; import { createProject, createSakilaProject } from '../../factory/base';
import { createColumn, createQrCodeColumn } from '../../factory/column'; 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 Model from '../../../../src/models/Model';
import type Base from '~/models/Base'; import type Base from '~/models/Base';
import type Column from '../../../../src/models/Column'; import type Column from '../../../../src/models/Column';
@ -27,6 +33,7 @@ function columnTypeSpecificTests() {
const qrValueReferenceColumnTitle = 'Qr Value Column'; const qrValueReferenceColumnTitle = 'Qr Value Column';
const qrCodeReferenceColumnTitle = 'Qr Code Column'; const qrCodeReferenceColumnTitle = 'Qr Code Column';
describe('Qr Code Column', () => {
beforeEach(async function () { beforeEach(async function () {
console.time('#### columnTypeSpecificTests'); console.time('#### columnTypeSpecificTests');
context = await init(true); context = await init(true);
@ -54,7 +61,6 @@ function columnTypeSpecificTests() {
console.timeEnd('#### columnTypeSpecificTests'); console.timeEnd('#### columnTypeSpecificTests');
}); });
describe('Qr Code Column', () => {
it('delivers the same cell values as the referenced column', async () => { it('delivers the same cell values as the referenced column', async () => {
const resp = await request(context.app) const resp = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}`) .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}`)
@ -93,6 +99,69 @@ function columnTypeSpecificTests() {
).to.eq(false); ).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 () { export default function () {

Loading…
Cancel
Save