|
|
@ -1,5 +1,4 @@ |
|
|
|
import 'mocha'; |
|
|
|
import 'mocha'; |
|
|
|
import { title } from 'process'; |
|
|
|
|
|
|
|
import request from 'supertest'; |
|
|
|
import request from 'supertest'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { expect } from 'chai'; |
|
|
|
import { expect } from 'chai'; |
|
|
@ -10,12 +9,7 @@ import { |
|
|
|
createQrCodeColumn, |
|
|
|
createQrCodeColumn, |
|
|
|
deleteColumn, |
|
|
|
deleteColumn, |
|
|
|
} from '../../factory/column'; |
|
|
|
} from '../../factory/column'; |
|
|
|
import { |
|
|
|
import { createTable, getColumnsByAPI, getTable } from '../../factory/table'; |
|
|
|
createTable, |
|
|
|
|
|
|
|
getColumnsByAPI, |
|
|
|
|
|
|
|
getTable, |
|
|
|
|
|
|
|
getTableByAPI, |
|
|
|
|
|
|
|
} from '../../factory/table'; |
|
|
|
|
|
|
|
import { createBulkRows, listRow, rowMixedValue } from '../../factory/row'; |
|
|
|
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'; |
|
|
@ -37,6 +31,39 @@ function columnTypeSpecificTests() { |
|
|
|
const qrValueReferenceColumnTitle = 'Qr Value Column'; |
|
|
|
const qrValueReferenceColumnTitle = 'Qr Value Column'; |
|
|
|
const qrCodeReferenceColumnTitle = 'Qr Code Column'; |
|
|
|
const qrCodeReferenceColumnTitle = 'Qr Code Column'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const defaultTableColumns = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Id', |
|
|
|
|
|
|
|
uidt: UITypes.ID, |
|
|
|
|
|
|
|
system: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'DateField', |
|
|
|
|
|
|
|
uidt: UITypes.Date, |
|
|
|
|
|
|
|
system: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'CreatedAt', |
|
|
|
|
|
|
|
uidt: UITypes.CreatedTime, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'UpdatedAt', |
|
|
|
|
|
|
|
uidt: UITypes.LastModifiedTime, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'CreatedBy', |
|
|
|
|
|
|
|
uidt: UITypes.CreatedBy, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'UpdatedBy', |
|
|
|
|
|
|
|
uidt: UITypes.LastModifiedBy, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
describe('Qr Code Column', () => { |
|
|
|
describe('Qr Code Column', () => { |
|
|
|
beforeEach(async function () { |
|
|
|
beforeEach(async function () { |
|
|
|
console.time('#### columnTypeSpecificTests'); |
|
|
|
console.time('#### columnTypeSpecificTests'); |
|
|
@ -89,7 +116,7 @@ function columnTypeSpecificTests() { |
|
|
|
), |
|
|
|
), |
|
|
|
).to.eq(true); |
|
|
|
).to.eq(true); |
|
|
|
|
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
const _response = await request(context.app) |
|
|
|
.delete(`/api/v1/db/meta/columns/${qrValueReferenceColumn.id}`) |
|
|
|
.delete(`/api/v1/db/meta/columns/${qrValueReferenceColumn.id}`) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.send({}); |
|
|
|
.send({}); |
|
|
@ -133,7 +160,7 @@ function columnTypeSpecificTests() { |
|
|
|
|
|
|
|
|
|
|
|
columns = await table.getColumns(); |
|
|
|
columns = await table.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const rowAttributes = []; |
|
|
|
const rowAttributes: any = []; |
|
|
|
for (let i = 0; i < 100; i++) { |
|
|
|
for (let i = 0; i < 100; i++) { |
|
|
|
const row = { |
|
|
|
const row = { |
|
|
|
DateField: rowMixedValue(columns[1], i), |
|
|
|
DateField: rowMixedValue(columns[1], i), |
|
|
@ -154,26 +181,19 @@ function columnTypeSpecificTests() { |
|
|
|
|
|
|
|
|
|
|
|
describe('Basic verification', async () => { |
|
|
|
describe('Basic verification', async () => { |
|
|
|
it('New table: verify system fields are added by default', async () => { |
|
|
|
it('New table: verify system fields are added by default', async () => { |
|
|
|
// Id, Date, CreatedAt, LastModifiedAt, Createdby, LastModifiedBy
|
|
|
|
// Id, Date, CreatedAt, LastModifiedAt
|
|
|
|
expect(columns.length).to.equal(6); |
|
|
|
expect(columns.length).to.equal(defaultTableColumns.length); |
|
|
|
|
|
|
|
for (let i = 0; i < defaultTableColumns.length; i++) { |
|
|
|
expect(columns[2].title).to.equal('CreatedAt'); |
|
|
|
expect(columns[i].title).to.equal(defaultTableColumns[i].title); |
|
|
|
expect(columns[2].uidt).to.equal(UITypes.CreatedTime); |
|
|
|
expect(columns[i].uidt).to.equal(defaultTableColumns[i].uidt); |
|
|
|
expect(!!columns[2].system).to.equal(true); |
|
|
|
expect(columns[i].system).to.equal(defaultTableColumns[i].system); |
|
|
|
expect(columns[3].title).to.equal('UpdatedAt'); |
|
|
|
} |
|
|
|
expect(columns[3].uidt).to.equal(UITypes.LastModifiedTime); |
|
|
|
|
|
|
|
expect(columns[3].system).to.equal(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(columns[4].title).to.equal('CreatedBy'); |
|
|
|
|
|
|
|
expect(columns[4].uidt).to.equal(UITypes.CreatedBy); |
|
|
|
|
|
|
|
expect(columns[4].system).to.equal(true); |
|
|
|
|
|
|
|
expect(columns[5].title).to.equal('UpdatedBy'); |
|
|
|
|
|
|
|
expect(columns[5].uidt).to.equal(UITypes.LastModifiedBy); |
|
|
|
|
|
|
|
expect(columns[5].system).to.equal(true); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('New table: should not be able to delete system fields', async () => { |
|
|
|
it('New table: should not be able to delete system fields', async () => { |
|
|
|
for (let i = 2; i < 6; i++) { |
|
|
|
// try to delete system fields
|
|
|
|
|
|
|
|
for (let i = 0; i < defaultTableColumns.length; i++) { |
|
|
|
|
|
|
|
if (!defaultTableColumns[i].system) return; |
|
|
|
await request(context.app) |
|
|
|
await request(context.app) |
|
|
|
.delete(`/api/v2/meta/columns/${columns[i].id}`) |
|
|
|
.delete(`/api/v2/meta/columns/${columns[i].id}`) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.set('xc-auth', context.token) |
|
|
@ -332,9 +352,16 @@ function columnTypeSpecificTests() { |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
|
|
|
|
|
|
|
|
// verify contents of both fields are same
|
|
|
|
// verify contents of both fields are same
|
|
|
|
expect(columns.columns[6].title).to.equal('CreatedAt2'); |
|
|
|
expect(columns.columns[defaultTableColumns.length].title).to.equal( |
|
|
|
expect(columns.columns[6].uidt).to.equal(UITypes.CreatedTime); |
|
|
|
'CreatedAt2', |
|
|
|
expect(columns.columns[6].system).to.equal(false); |
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].uidt).to.equal( |
|
|
|
|
|
|
|
UITypes.CreatedTime, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].system).to.equal( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
expect(records[0].CreatedAt).to.equal(records[0].CreatedAt2); |
|
|
|
expect(records[0].CreatedAt).to.equal(records[0].CreatedAt2); |
|
|
|
|
|
|
|
|
|
|
|
const d1 = new Date(); |
|
|
|
const d1 = new Date(); |
|
|
@ -375,14 +402,26 @@ function columnTypeSpecificTests() { |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
|
|
|
|
|
|
|
|
// verify contents of both fields are same
|
|
|
|
// verify contents of both fields are same
|
|
|
|
expect(columns.columns[6].title).to.equal('CreatedBy2'); |
|
|
|
expect(columns.columns[defaultTableColumns.length].title).to.equal( |
|
|
|
expect(columns.columns[6].uidt).to.equal(UITypes.CreatedBy); |
|
|
|
'CreatedBy2', |
|
|
|
expect(columns.columns[6].system).to.equal(false); |
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].uidt).to.equal( |
|
|
|
|
|
|
|
UITypes.CreatedBy, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].system).to.equal( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); |
|
|
|
expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); |
|
|
|
|
|
|
|
|
|
|
|
expect(columns.columns[7].title).to.equal('ModifiedBy2'); |
|
|
|
expect(columns.columns[defaultTableColumns.length + 1].title).to.equal( |
|
|
|
expect(columns.columns[7].uidt).to.equal(UITypes.LastModifiedBy); |
|
|
|
'ModifiedBy2', |
|
|
|
expect(columns.columns[7].system).to.equal(false); |
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length + 1].uidt).to.equal( |
|
|
|
|
|
|
|
UITypes.LastModifiedBy, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length + 1].system).to.equal( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
expect(records[0].UpdatedBy).to.deep.equal(records[0].ModifiedBy2); |
|
|
|
expect(records[0].UpdatedBy).to.deep.equal(records[0].ModifiedBy2); |
|
|
|
|
|
|
|
|
|
|
|
// update record should fail
|
|
|
|
// update record should fail
|
|
|
@ -419,7 +458,10 @@ function columnTypeSpecificTests() { |
|
|
|
// get all columns
|
|
|
|
// get all columns
|
|
|
|
let columns = await getColumnsByAPI(context, base, table); |
|
|
|
let columns = await getColumnsByAPI(context, base, table); |
|
|
|
// delete the field
|
|
|
|
// delete the field
|
|
|
|
await deleteColumn(context, { table, column: columns.columns[6] }); |
|
|
|
await deleteColumn(context, { |
|
|
|
|
|
|
|
table, |
|
|
|
|
|
|
|
column: columns.columns[defaultTableColumns.length], |
|
|
|
|
|
|
|
}); |
|
|
|
// create column again
|
|
|
|
// create column again
|
|
|
|
await createColumn(context, table, { |
|
|
|
await createColumn(context, table, { |
|
|
|
title: 'CreatedAt2', |
|
|
|
title: 'CreatedAt2', |
|
|
@ -433,9 +475,16 @@ function columnTypeSpecificTests() { |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
|
|
|
|
|
|
|
|
// verify contents of both fields are same
|
|
|
|
// verify contents of both fields are same
|
|
|
|
expect(columns.columns[6].title).to.equal('CreatedAt2'); |
|
|
|
expect(columns.columns[defaultTableColumns.length].title).to.equal( |
|
|
|
expect(columns.columns[6].uidt).to.equal(UITypes.CreatedTime); |
|
|
|
'CreatedAt2', |
|
|
|
expect(columns.columns[6].system).to.equal(false); |
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].uidt).to.equal( |
|
|
|
|
|
|
|
UITypes.CreatedTime, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].system).to.equal( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
expect(records[0].CreatedAt).to.equal(records[0].CreatedAt2); |
|
|
|
expect(records[0].CreatedAt).to.equal(records[0].CreatedAt2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -463,9 +512,15 @@ function columnTypeSpecificTests() { |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
const records = await listRow({ base, table }); |
|
|
|
|
|
|
|
|
|
|
|
// verify contents of both fields are same
|
|
|
|
// verify contents of both fields are same
|
|
|
|
expect(columns.columns[6].title).to.equal('CreatedBy2'); |
|
|
|
expect(columns.columns[defaultTableColumns.length].title).to.equal( |
|
|
|
expect(columns.columns[6].uidt).to.equal(UITypes.CreatedBy); |
|
|
|
'CreatedBy2', |
|
|
|
expect(columns.columns[6].system).to.equal(false); |
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].uidt).to.equal( |
|
|
|
|
|
|
|
UITypes.CreatedBy, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
expect(columns.columns[defaultTableColumns.length].system).to.equal( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); |
|
|
|
expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|