|
|
@ -1,10 +1,11 @@ |
|
|
|
import 'mocha'; |
|
|
|
import 'mocha'; |
|
|
|
import request from 'supertest'; |
|
|
|
import request from 'supertest'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
|
|
|
|
import { expect } from 'chai'; |
|
|
|
import init from '../../init'; |
|
|
|
import init from '../../init'; |
|
|
|
import { createProject } from '../../factory/base'; |
|
|
|
import { createProject } from '../../factory/base'; |
|
|
|
import { createTable } from '../../factory/table'; |
|
|
|
import { createTable } from '../../factory/table'; |
|
|
|
import type Model from '../../../../src/models/Model'; |
|
|
|
import { createBulkRows, createChildRow, listRow } from '../../factory/row'; |
|
|
|
import type Base from '~/models/Base'; |
|
|
|
import type Base from '~/models/Base'; |
|
|
|
|
|
|
|
|
|
|
|
// Test case list
|
|
|
|
// Test case list
|
|
|
@ -13,40 +14,13 @@ function columnTests() { |
|
|
|
let context; |
|
|
|
let context; |
|
|
|
let base: Base; |
|
|
|
let base: Base; |
|
|
|
|
|
|
|
|
|
|
|
const qrValueReferenceColumnTitle = 'Qr Value Column'; |
|
|
|
|
|
|
|
const qrCodeReferenceColumnTitle = 'Qr Code Column'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const defaultTableColumns = [ |
|
|
|
const defaultTableColumns = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: 'Id', |
|
|
|
title: 'Id', |
|
|
|
|
|
|
|
column_name: 'Id', |
|
|
|
uidt: UITypes.ID, |
|
|
|
uidt: UITypes.ID, |
|
|
|
system: false, |
|
|
|
system: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
|
|
|
|
title: 'DateField', |
|
|
|
|
|
|
|
uidt: UITypes.Date, |
|
|
|
|
|
|
|
system: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'CreatedAt', |
|
|
|
|
|
|
|
uidt: UITypes.CreatedTime, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'UpdatedAt', |
|
|
|
|
|
|
|
uidt: UITypes.LastModifiedTime, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'nc_created_by', |
|
|
|
|
|
|
|
uidt: UITypes.CreatedBy, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'nc_updated_by', |
|
|
|
|
|
|
|
uidt: UITypes.LastModifiedBy, |
|
|
|
|
|
|
|
system: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
describe('Advance Column', () => { |
|
|
|
describe('Advance Column', () => { |
|
|
@ -54,23 +28,25 @@ function columnTests() { |
|
|
|
console.time('#### columnTypeSpecificTests'); |
|
|
|
console.time('#### columnTypeSpecificTests'); |
|
|
|
context = await init(true); |
|
|
|
context = await init(true); |
|
|
|
|
|
|
|
|
|
|
|
// sakilaProject = await createSakilaProject(context);
|
|
|
|
|
|
|
|
base = await createProject(context); |
|
|
|
base = await createProject(context); |
|
|
|
|
|
|
|
|
|
|
|
console.timeEnd('#### columnTypeSpecificTests'); |
|
|
|
console.timeEnd('#### columnTypeSpecificTests'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Create HM relation', async () => { |
|
|
|
it('Create HM relation', async () => { |
|
|
|
const country = await createTable(context, base.id, { |
|
|
|
let country = await createTable(context, base, { |
|
|
|
title: 'Country', |
|
|
|
title: 'Country', |
|
|
|
|
|
|
|
table_name: 'Country', |
|
|
|
columns: defaultTableColumns, |
|
|
|
columns: defaultTableColumns, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const city = await createTable(context, base.id, { |
|
|
|
const city = await createTable(context, base, { |
|
|
|
title: 'City', |
|
|
|
title: 'City', |
|
|
|
|
|
|
|
table_name: 'City', |
|
|
|
columns: [ |
|
|
|
columns: [ |
|
|
|
...defaultTableColumns, |
|
|
|
...defaultTableColumns, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: 'CountryId', |
|
|
|
title: 'CountryId', |
|
|
|
|
|
|
|
column_name: 'CountryId', |
|
|
|
uidt: UITypes.Number, |
|
|
|
uidt: UITypes.Number, |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -82,11 +58,16 @@ function columnTests() { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
const response = await request(context.app) |
|
|
|
.post(`/api/v1/db/meta/projects/${base.id}/columns`) |
|
|
|
.post(`/api/v1/db/meta/tables/${country.id}/columns`) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.send({ |
|
|
|
.send({ |
|
|
|
title: 'Country', |
|
|
|
title: 'Cities', |
|
|
|
uidt: UITypes.Links, |
|
|
|
uidt: UITypes.Links, |
|
|
|
|
|
|
|
column_name: 'Cities', |
|
|
|
|
|
|
|
type: 'hm', |
|
|
|
|
|
|
|
childId: city.id, |
|
|
|
|
|
|
|
parentId: country.id, |
|
|
|
|
|
|
|
is_custom_link: true, |
|
|
|
custom: { |
|
|
|
custom: { |
|
|
|
base_id: base.id, |
|
|
|
base_id: base.id, |
|
|
|
column_id: pkColumn?.id, |
|
|
|
column_id: pkColumn?.id, |
|
|
@ -95,33 +76,100 @@ function columnTests() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
console.log(response.body); |
|
|
|
country = response.body; |
|
|
|
|
|
|
|
const hmColumn = country.columns.find( |
|
|
|
|
|
|
|
(column) => column.title === 'Cities', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add rows to tables
|
|
|
|
|
|
|
|
await createBulkRows(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: country, |
|
|
|
|
|
|
|
values: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Country1', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Country2', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Country3', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add rows to tables
|
|
|
|
|
|
|
|
await createBulkRows(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: city, |
|
|
|
|
|
|
|
values: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'City1', |
|
|
|
|
|
|
|
CountryId: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'City2', |
|
|
|
|
|
|
|
CountryId: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'City3', |
|
|
|
|
|
|
|
CountryId: 2, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'City3', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// link rows
|
|
|
|
|
|
|
|
await createChildRow(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: country, |
|
|
|
|
|
|
|
childTable: city, |
|
|
|
|
|
|
|
column: hmColumn, |
|
|
|
|
|
|
|
rowId: '3', |
|
|
|
|
|
|
|
childRowId: '4', |
|
|
|
|
|
|
|
type: 'hm', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rows = await listRow({ |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: country, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rows1 = await listRow({ |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: city, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(rows[0].Cities).to.be.eq(2); |
|
|
|
|
|
|
|
expect(rows[1].Cities).to.be.eq(1); |
|
|
|
|
|
|
|
expect(rows[2].Cities).to.be.eq(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('Create MM relation', async () => { |
|
|
|
it('Create MM relation', async () => { |
|
|
|
const film = await createTable(context, base.id, { |
|
|
|
const film = await createTable(context, base, { |
|
|
|
title: 'Film', |
|
|
|
title: 'Film', |
|
|
|
|
|
|
|
table_name: 'Film', |
|
|
|
columns: defaultTableColumns, |
|
|
|
columns: defaultTableColumns, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const actor = await createTable(context, base.id, { |
|
|
|
let actor = await createTable(context, base, { |
|
|
|
title: 'Actor', |
|
|
|
title: 'Actor', |
|
|
|
columns: [ |
|
|
|
table_name: 'Actor', |
|
|
|
...defaultTableColumns, |
|
|
|
columns: defaultTableColumns, |
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Table1Id', |
|
|
|
|
|
|
|
uidt: UITypes.Number, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const filmActor = await createTable(context, base.id, { |
|
|
|
const filmActor = await createTable(context, base, { |
|
|
|
title: 'FilmActor', |
|
|
|
title: 'FilmActor', |
|
|
|
|
|
|
|
table_name: 'FilmActor', |
|
|
|
columns: [ |
|
|
|
columns: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: 'ActorId', |
|
|
|
title: 'ActorId', |
|
|
|
|
|
|
|
column_name: 'ActorId', |
|
|
|
uidt: UITypes.Number, |
|
|
|
uidt: UITypes.Number, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: 'FilmId', |
|
|
|
title: 'FilmId', |
|
|
|
|
|
|
|
column_name: 'FilmId', |
|
|
|
uidt: UITypes.Number, |
|
|
|
uidt: UITypes.Number, |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -137,11 +185,16 @@ function columnTests() { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
const response = await request(context.app) |
|
|
|
.post(`/api/v1/db/meta/projects/${base.id}/columns`) |
|
|
|
.post(`/api/v1/db/meta/tables/${actor.id}/columns`) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.set('xc-auth', context.token) |
|
|
|
.send({ |
|
|
|
.send({ |
|
|
|
title: 'Actor', |
|
|
|
title: 'Films', |
|
|
|
uidt: UITypes.Links, |
|
|
|
uidt: UITypes.Links, |
|
|
|
|
|
|
|
childId: film.id, |
|
|
|
|
|
|
|
parentId: actor.id, |
|
|
|
|
|
|
|
column_name: 'Films', |
|
|
|
|
|
|
|
type: 'mm', |
|
|
|
|
|
|
|
is_custom_link: true, |
|
|
|
custom: { |
|
|
|
custom: { |
|
|
|
base_id: base.id, |
|
|
|
base_id: base.id, |
|
|
|
junc_base_id: base.id, |
|
|
|
junc_base_id: base.id, |
|
|
@ -154,7 +207,69 @@ function columnTests() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
console.log(response.body); |
|
|
|
actor = response.body; |
|
|
|
|
|
|
|
const mmColumn = actor.columns.find((column) => column.title === 'Films'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add rows to tables
|
|
|
|
|
|
|
|
await createBulkRows(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: actor, |
|
|
|
|
|
|
|
values: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Actor1', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Actor2', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Actor3', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add rows to tables
|
|
|
|
|
|
|
|
await createBulkRows(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: film, |
|
|
|
|
|
|
|
values: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Film1', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Film2', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Title: 'Film3', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// link rows
|
|
|
|
|
|
|
|
await createChildRow(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: actor, |
|
|
|
|
|
|
|
childTable: film, |
|
|
|
|
|
|
|
column: mmColumn, |
|
|
|
|
|
|
|
rowId: '1', |
|
|
|
|
|
|
|
childRowId: '1', |
|
|
|
|
|
|
|
type: 'mm', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
await createChildRow(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: actor, |
|
|
|
|
|
|
|
childTable: film, |
|
|
|
|
|
|
|
column: mmColumn, |
|
|
|
|
|
|
|
rowId: '1', |
|
|
|
|
|
|
|
childRowId: '2', |
|
|
|
|
|
|
|
type: 'mm', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rows = await listRow({ |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
table: actor, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(rows[0].Films).to.be.eq(2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|