Browse Source

test: base data for filters to run on

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5029/head
Raju Udava 2 years ago
parent
commit
8612da67ab
  1. 156
      packages/nocodb/tests/unit/factory/row.ts
  2. 97
      packages/nocodb/tests/unit/rest/tests/filter.test.ts

156
packages/nocodb/tests/unit/factory/row.ts

@ -24,13 +24,124 @@ const rowValue = (column: ColumnType, index: number) => {
}
};
const getRow = async (context, {project, table, id}) => {
const rowMixedValue = (column: ColumnType, index: number) => {
console.log(column.uidt, index);
// Array of country names
const countries = [
'Afghanistan',
'Albania',
'',
'Andorra',
'Angola',
'Antigua and Barbuda',
'Argentina',
null,
'Armenia',
'Australia',
'Austria',
'',
null,
];
// Array of sample random paragraphs (comma separated list of cities and countries). Not more than 200 characters
const longText = [
'Aberdeen, United Kingdom',
'Abidjan, Côte d’Ivoire',
'Abuja, Nigeria',
'',
'Addis Ababa, Ethiopia',
'Adelaide, Australia',
'Ahmedabad, India',
'Albuquerque, United States',
null,
'Alexandria, Egypt',
'Algiers, Algeria',
'Allahabad, India',
'',
null,
];
// Array of random integers, not more than 10000
const numbers = [33, 456, 54, 267, 34, 8754, 3234, 44, 33, null];
// Array of random sample email strings (not more than 100 characters)
const emails = [
'jbutt@gmail.com',
'josephine_darakjy@darakjy.org',
'art@venere.org',
'',
null,
'donette.foller@cox.net',
'simona@morasca.com',
'mitsue_tollner@yahoo.com',
'leota@hotmail.com',
'sage_wieser@cox.net',
'',
null,
];
// Array of random sample phone numbers
const phoneNumbers = [
'1-541-754-3010',
'504-621-8927',
'810-292-9388',
'856-636-8749',
'907-385-4412',
'513-570-1893',
'419-503-2484',
'773-573-6914',
'',
null,
];
// Array of random sample URLs
const urls = [
'https://www.google.com',
'https://www.facebook.com',
'https://www.youtube.com',
'https://www.amazon.com',
'https://www.wikipedia.org',
'https://www.twitter.com',
'https://www.instagram.com',
'https://www.linkedin.com',
'https://www.reddit.com',
'https://www.tiktok.com',
'https://www.pinterest.com',
'https://www.netflix.com',
'https://www.microsoft.com',
'https://www.apple.com',
'',
null,
];
switch (column.uidt) {
case UITypes.Number:
return numbers[index % numbers.length];
case UITypes.SingleLineText:
return countries[index % countries.length];
case UITypes.Email:
return emails[index % emails.length];
case UITypes.PhoneNumber:
return phoneNumbers[index % phoneNumbers.length];
case UITypes.LongText:
return longText[index % longText.length];
case UITypes.Date:
return '2020-01-01';
case UITypes.URL:
return urls[index % urls.length];
default:
return `test-${index}`;
}
};
const getRow = async (context, { project, table, id }) => {
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}/${id}`)
.set('xc-auth', context.token);
if(response.status !== 200) {
return undefined
if (response.status !== 200) {
return undefined;
}
return response.body;
@ -119,18 +230,19 @@ const createBulkRows = async (
{
project,
table,
values
values,
}: {
project: Project;
table: Model;
values: any[];
}) => {
await request(context.app)
.post(`/api/v1/db/data/bulk/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.send(values)
.expect(200);
}
) => {
await request(context.app)
.post(`/api/v1/db/data/bulk/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.send(values)
.expect(200);
};
// Links 2 table rows together. Will create rows if ids are not provided
const createChildRow = async (
@ -174,6 +286,26 @@ const createChildRow = async (
return row;
};
// Mixed row attributes
const generateMixedRowAttributes = ({
columns,
index = 0,
}: {
columns: ColumnType[];
index?: number;
}) =>
columns.reduce((acc, column) => {
if (
column.uidt === UITypes.LinkToAnotherRecord ||
column.uidt === UITypes.ForeignKey ||
column.uidt === UITypes.ID
) {
return acc;
}
acc[column.title!] = rowMixedValue(column, index);
return acc;
}, {});
export {
createRow,
getRow,
@ -181,5 +313,7 @@ export {
getOneRow,
listRow,
generateDefaultRowAttributes,
createBulkRows
generateMixedRowAttributes,
createBulkRows,
rowMixedValue,
};

97
packages/nocodb/tests/unit/rest/tests/filter.test.ts

@ -0,0 +1,97 @@
import 'mocha';
import init from '../../init';
import { createProject } from '../../factory/project';
import Project from '../../../../src/lib/models/Project';
import { createTable } from '../../factory/table';
import { isSqlite } from '../../init/db';
import { UITypes } from 'nocodb-sdk';
import {
createBulkRows,
generateDefaultRowAttributes,
generateMixedRowAttributes,
rowMixedValue,
listRow,
} from '../../factory/row';
import Model from '../../../../src/lib/models/Model';
import { expect } from 'chai';
// Test case list
function filterTests() {
let context;
let project: Project;
let table: Model;
let unfilteredRecords: any[] = [];
// prepare data for test cases
beforeEach(async function () {
context = await init();
project = await createProject(context);
table = await createTable(context, project, {
table_name: 'textBased',
title: 'TextBased',
columns: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'SingleLineText',
title: 'SingleLineText',
uidt: UITypes.SingleLineText,
},
{
column_name: 'MultiLineText',
title: 'MultiLineText',
uidt: UITypes.LongText,
},
{
column_name: 'Email',
title: 'Email',
uidt: UITypes.Email,
},
{
column_name: 'Phone',
title: 'Phone',
uidt: UITypes.PhoneNumber,
},
{
column_name: 'Url',
title: 'Url',
uidt: UITypes.URL,
},
],
});
const columns = await table.getColumns();
let rowAttributes = [];
for (let i = 0; i < 400; i++) {
let row = {
SingleLineText: rowMixedValue(columns[1], i),
MultiLineText: rowMixedValue(columns[2], i),
Email: rowMixedValue(columns[3], i),
Phone: rowMixedValue(columns[4], i),
Url: rowMixedValue(columns[5], i),
};
rowAttributes.push(row);
}
await createBulkRows(context, {
project,
table,
values: rowAttributes,
});
unfilteredRecords = await listRow({ project, table });
// verify length of unfiltered records to be 400
expect(unfilteredRecords.length).to.equal(400);
});
it('Type: Single Line Text', async () => {});
}
export default function () {
describe('Filters', filterTests);
}
Loading…
Cancel
Save