Browse Source

test: API test framework for formula, sample tests for REGEXP

pull/7268/head
Raju Udava 11 months ago
parent
commit
e788c69c40
  1. 18
      packages/nocodb/tests/unit/factory/column.ts
  2. 2
      packages/nocodb/tests/unit/rest/index.test.ts
  3. 101
      packages/nocodb/tests/unit/rest/tests/formula.test.ts

18
packages/nocodb/tests/unit/factory/column.ts

@ -386,6 +386,23 @@ const updateViewColumn = async (
return updatedColumn; return updatedColumn;
}; };
const updateColumn = async (
context,
{ table, column, attr }: { column: Column; table: Model; attr: any },
) => {
const res = await request(context.app)
.patch(`/api/v2/meta/columns/${column.id}`)
.set('xc-auth', context.token)
.send({
...attr,
});
const updatedColumn: Column = (await table.getColumns()).find(
(column) => column.id === column.id,
);
return updatedColumn;
};
export { export {
customColumns, customColumns,
defaultColumns, defaultColumns,
@ -396,4 +413,5 @@ export {
createLookupColumn, createLookupColumn,
createLtarColumn, createLtarColumn,
updateViewColumn, updateViewColumn,
updateColumn,
}; };

2
packages/nocodb/tests/unit/rest/index.test.ts

@ -10,6 +10,7 @@ import attachmentTests from './tests/attachment.test';
import filterTest from './tests/filter.test'; import filterTest from './tests/filter.test';
import newDataApisTest from './tests/newDataApis.test'; import newDataApisTest from './tests/newDataApis.test';
import groupByTest from './tests/groupby.test'; import groupByTest from './tests/groupby.test';
import formulaTests from './tests/formula.test';
let workspaceTest = () => {}; let workspaceTest = () => {};
if (process.env.EE === 'true') { if (process.env.EE === 'true') {
@ -31,6 +32,7 @@ function restTests() {
newDataApisTest(); newDataApisTest();
groupByTest(); groupByTest();
workspaceTest(); workspaceTest();
formulaTests();
// Enable for dashboard feature // Enable for dashboard feature
// widgetTest(); // widgetTest();

101
packages/nocodb/tests/unit/rest/tests/formula.test.ts

@ -0,0 +1,101 @@
import 'mocha';
import { UITypes } from 'nocodb-sdk';
import { expect } from 'chai';
import init from '../../init';
import { createProject } from '../../factory/base';
import { createTable } from '../../factory/table';
import { createBulkRows, listRow, rowMixedValue } from '../../factory/row';
import { updateColumn } from '../../factory/column';
import type Model from '../../../../src/models/Model';
import type Base from '~/models/Base';
let context;
let base: Base;
let table: Model;
let columns: any[];
let unfilteredRecords: any[] = [];
function formulaRegExpBased() {
// prepare data for test cases
beforeEach(async function () {
context = await init();
base = await createProject(context);
table = await createTable(context, base, {
table_name: 'sampleTable',
title: 'sampleTable',
columns: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Title',
title: 'Title',
uidt: UITypes.SingleLineText,
},
{
column_name: 'formula',
title: 'formula',
uidt: UITypes.Formula,
formula: '20',
},
],
});
columns = await table.getColumns();
const rowAttributes = [];
for (let i = 0; i < 100; i++) {
const row = {
Title: 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('Type: REGEX_MATCH ', async () => {
const formulaList = [
`REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")`,
'REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("ABC-45-6789", "\\w{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("123-XY-6789", "\\d{3}-\\w{2}-\\d{4}")',
'REGEX_MATCH("123-45-$#@!", "123-45-[\\s\\S]{4}")',
'REGEX_MATCH("123456789", "1?2?3?-?4?5-?6?7?8?9?")',
'REGEX_MATCH("123-456789", "\\d{3}-?\\d{2}-?\\d{4}")',
'REGEX_MATCH("123-45-6789", "123-\\d{2}-6789")',
];
for (let i = 0; i < formulaList.length; i++) {
await updateColumn(context, {
table,
column: columns[2],
attr: {
formula: formulaList[i],
formula_raw: formulaList[i],
title: 'formula',
uidt: UITypes.Formula,
},
});
console.log(formulaList[i]);
unfilteredRecords = await listRow({ base, table });
expect(unfilteredRecords[0].formula).to.equal(1);
}
});
}
export default function () {
describe('Formula: REGEXP based', formulaRegExpBased);
}
Loading…
Cancel
Save