|
|
|
@ -14,7 +14,7 @@ import { expect } from 'chai';
|
|
|
|
|
import Filter from '../../../../src/lib/models/Filter'; |
|
|
|
|
import { createLtarColumn } from '../../factory/column'; |
|
|
|
|
import LinkToAnotherRecordColumn from '../../../../src/lib/models/LinkToAnotherRecordColumn'; |
|
|
|
|
import { isSqlite } from '../../init/db'; |
|
|
|
|
import { isPg, isSqlite } from '../../init/db'; |
|
|
|
|
|
|
|
|
|
function baseModelSqlTests() { |
|
|
|
|
let context; |
|
|
|
@ -33,25 +33,42 @@ function baseModelSqlTests() {
|
|
|
|
|
baseModelSql = new BaseModelSqlv2({ |
|
|
|
|
dbDriver: await NcConnectionMgrv2.get(base), |
|
|
|
|
model: table, |
|
|
|
|
view |
|
|
|
|
}) |
|
|
|
|
view, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Insert record', async () => { |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
|
|
|
|
|
const inputData = generateDefaultRowAttributes({columns}) |
|
|
|
|
const response = await baseModelSql.insert(generateDefaultRowAttributes({columns}), undefined, request); |
|
|
|
|
let inputData: any = generateDefaultRowAttributes({ columns }); |
|
|
|
|
const response = await baseModelSql.insert( |
|
|
|
|
generateDefaultRowAttributes({ columns }), |
|
|
|
|
undefined, |
|
|
|
|
request |
|
|
|
|
); |
|
|
|
|
const insertedRow = (await baseModelSql.list())[0]; |
|
|
|
|
|
|
|
|
|
if (isPg(context)) { |
|
|
|
|
inputData.CreatedAt = new Date(inputData.CreatedAt).toISOString(); |
|
|
|
|
inputData.UpdatedAt = new Date(inputData.UpdatedAt).toISOString(); |
|
|
|
|
|
|
|
|
|
insertedRow.CreatedAt = new Date(insertedRow.CreatedAt).toISOString(); |
|
|
|
|
insertedRow.UpdatedAt = new Date(insertedRow.UpdatedAt).toISOString(); |
|
|
|
|
|
|
|
|
|
response.CreatedAt = new Date(response.CreatedAt).toISOString(); |
|
|
|
|
response.UpdatedAt = new Date(response.UpdatedAt).toISOString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
expect(insertedRow).to.include(inputData); |
|
|
|
|
expect(insertedRow).to.include(response); |
|
|
|
|
|
|
|
|
|
const rowInsertedAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'INSERT'); |
|
|
|
|
const rowInsertedAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'INSERT'); |
|
|
|
|
expect(rowInsertedAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -69,18 +86,33 @@ function baseModelSqlTests() {
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const insertedRows = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
bulkData.forEach((inputData, index) => { |
|
|
|
|
if (isPg(context)) { |
|
|
|
|
insertedRows.forEach((row) => { |
|
|
|
|
row.CreatedAt = new Date(row.CreatedAt).toISOString(); |
|
|
|
|
row.UpdatedAt = new Date(row.UpdatedAt).toISOString(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bulkData.forEach((inputData: any, index) => { |
|
|
|
|
if (isPg(context)) { |
|
|
|
|
inputData.CreatedAt = new Date(inputData.CreatedAt).toISOString(); |
|
|
|
|
inputData.UpdatedAt = new Date(inputData.UpdatedAt).toISOString(); |
|
|
|
|
} |
|
|
|
|
expect(insertedRows[index]).to.include(inputData); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const rowBulkInsertedAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'BULK_INSERT');; |
|
|
|
|
const rowBulkInsertedAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'BULK_INSERT'); |
|
|
|
|
expect(rowBulkInsertedAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -99,20 +131,22 @@ function baseModelSqlTests() {
|
|
|
|
|
it('Update record', async () => { |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
|
|
|
|
|
await baseModelSql.insert(generateDefaultRowAttributes({columns})); |
|
|
|
|
await baseModelSql.insert(generateDefaultRowAttributes({ columns })); |
|
|
|
|
const rowId = 1; |
|
|
|
|
await baseModelSql.updateByPk(rowId, {Title: 'test'},undefined, request); |
|
|
|
|
await baseModelSql.updateByPk(rowId, { Title: 'test' }, undefined, request); |
|
|
|
|
|
|
|
|
|
const updatedRow = await baseModelSql.readByPk(1); |
|
|
|
|
|
|
|
|
|
expect(updatedRow).to.include({Id: rowId, Title: 'test'}); |
|
|
|
|
expect(updatedRow).to.include({ Id: rowId, Title: 'test' }); |
|
|
|
|
|
|
|
|
|
const rowUpdatedAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'UPDATE'); |
|
|
|
|
const rowUpdatedAudit = (await Audit.projectAuditList(project.id, {})).find( |
|
|
|
|
(audit) => audit.op_sub_type === 'UPDATE' |
|
|
|
|
); |
|
|
|
|
expect(rowUpdatedAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -128,26 +162,33 @@ function baseModelSqlTests() {
|
|
|
|
|
|
|
|
|
|
it('Bulk update record', async () => { |
|
|
|
|
// Since sqlite doesn't support multiple sql connections, we can't test bulk update in sqlite
|
|
|
|
|
if(isSqlite(context)) return |
|
|
|
|
if (isSqlite(context)) return; |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const insertedRows: any[] = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
await baseModelSql.bulkUpdate(insertedRows.map((row)=> ({...row, Title: `new-${row['Title']}`})), { cookie: request }); |
|
|
|
|
await baseModelSql.bulkUpdate( |
|
|
|
|
insertedRows.map((row) => ({ ...row, Title: `new-${row['Title']}` })), |
|
|
|
|
{ cookie: request } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const updatedRows = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
updatedRows.forEach((row, index) => { |
|
|
|
|
expect(row['Title']).to.equal(`new-test-${index}`); |
|
|
|
|
}) |
|
|
|
|
const rowBulkUpdateAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'BULK_UPDATE'); |
|
|
|
|
}); |
|
|
|
|
const rowBulkUpdateAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'BULK_UPDATE'); |
|
|
|
|
expect(rowBulkUpdateAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -167,28 +208,38 @@ function baseModelSqlTests() {
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const idColumn = columns.find((column) => column.title === 'Id')!; |
|
|
|
|
|
|
|
|
|
await baseModelSql.bulkUpdateAll({filterArr: [ |
|
|
|
|
await baseModelSql.bulkUpdateAll( |
|
|
|
|
{ |
|
|
|
|
filterArr: [ |
|
|
|
|
new Filter({ |
|
|
|
|
logical_op: 'and', |
|
|
|
|
fk_column_id: idColumn.id, |
|
|
|
|
comparison_op: 'lt', |
|
|
|
|
value: 5, |
|
|
|
|
}) |
|
|
|
|
]}, ({Title: 'new-1'}), { cookie: request }); |
|
|
|
|
}), |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
{ Title: 'new-1' }, |
|
|
|
|
{ cookie: request } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const updatedRows = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
updatedRows.forEach((row) => { |
|
|
|
|
if(row.id < 5) expect(row['Title']).to.equal('new-1'); |
|
|
|
|
}) |
|
|
|
|
const rowBulkUpdateAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'BULK_UPDATE'); |
|
|
|
|
if (row.id < 5) expect(row['Title']).to.equal('new-1'); |
|
|
|
|
}); |
|
|
|
|
const rowBulkUpdateAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'BULK_UPDATE'); |
|
|
|
|
expect(rowBulkUpdateAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -207,23 +258,27 @@ function baseModelSqlTests() {
|
|
|
|
|
it('Delete record', async () => { |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'}, |
|
|
|
|
params: {id: 1} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
params: { id: 1 }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const rowIdToDeleted = 1; |
|
|
|
|
await baseModelSql.delByPk(rowIdToDeleted,undefined ,request); |
|
|
|
|
await baseModelSql.delByPk(rowIdToDeleted, undefined, request); |
|
|
|
|
|
|
|
|
|
const deletedRow = await baseModelSql.readByPk(rowIdToDeleted); |
|
|
|
|
|
|
|
|
|
expect(deletedRow).to.be.undefined; |
|
|
|
|
|
|
|
|
|
console.log('Delete record', await Audit.projectAuditList(project.id, {})); |
|
|
|
|
const rowDeletedAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'DELETE'); |
|
|
|
|
const rowDeletedAudit = (await Audit.projectAuditList(project.id, {})).find( |
|
|
|
|
(audit) => audit.op_sub_type === 'DELETE' |
|
|
|
|
); |
|
|
|
|
expect(rowDeletedAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -241,17 +296,19 @@ function baseModelSqlTests() {
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const insertedRows: any[] = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
await baseModelSql.bulkDelete( |
|
|
|
|
insertedRows |
|
|
|
|
.filter((row) => row['Id'] < 5) |
|
|
|
|
.map((row)=> ({'id': row['Id']})),
|
|
|
|
|
.map((row) => ({ id: row['Id'] })), |
|
|
|
|
{ cookie: request } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
@ -259,7 +316,9 @@ function baseModelSqlTests() {
|
|
|
|
|
|
|
|
|
|
expect(remainingRows).to.length(6); |
|
|
|
|
|
|
|
|
|
const rowBulkDeleteAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'BULK_DELETE'); |
|
|
|
|
const rowBulkDeleteAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'BULK_DELETE'); |
|
|
|
|
|
|
|
|
|
expect(rowBulkDeleteAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
@ -280,26 +339,35 @@ function baseModelSqlTests() {
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
const bulkData = Array(10).fill(0).map((_, index) => generateDefaultRowAttributes({columns, index})) |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, {cookie:request}); |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
const bulkData = Array(10) |
|
|
|
|
.fill(0) |
|
|
|
|
.map((_, index) => generateDefaultRowAttributes({ columns, index })); |
|
|
|
|
await baseModelSql.bulkInsert(bulkData, { cookie: request }); |
|
|
|
|
|
|
|
|
|
const idColumn = columns.find((column) => column.title === 'Id')!; |
|
|
|
|
|
|
|
|
|
await baseModelSql.bulkDeleteAll({filterArr: [ |
|
|
|
|
await baseModelSql.bulkDeleteAll( |
|
|
|
|
{ |
|
|
|
|
filterArr: [ |
|
|
|
|
new Filter({ |
|
|
|
|
logical_op: 'and', |
|
|
|
|
fk_column_id: idColumn.id, |
|
|
|
|
comparison_op: 'lt', |
|
|
|
|
value: 5, |
|
|
|
|
}) |
|
|
|
|
]}, { cookie: request }); |
|
|
|
|
}), |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
{ cookie: request } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const remainingRows = await baseModelSql.list(); |
|
|
|
|
|
|
|
|
|
expect(remainingRows).to.length(6); |
|
|
|
|
const rowBulkDeleteAudit = (await Audit.projectAuditList(project.id, {})).find((audit) => audit.op_sub_type === 'BULK_DELETE'); |
|
|
|
|
const rowBulkDeleteAudit = ( |
|
|
|
|
await Audit.projectAuditList(project.id, {}) |
|
|
|
|
).find((audit) => audit.op_sub_type === 'BULK_DELETE'); |
|
|
|
|
expect(rowBulkDeleteAudit).to.include({ |
|
|
|
|
user: 'test@example.com', |
|
|
|
|
ip: '::ffff:192.0.0.1', |
|
|
|
@ -319,29 +387,32 @@ function baseModelSqlTests() {
|
|
|
|
|
const childTable = await createTable(context, project, { |
|
|
|
|
title: 'Child Table', |
|
|
|
|
table_name: 'child_table', |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
const ltarColumn = await createLtarColumn(context, { |
|
|
|
|
title: 'Ltar Column', |
|
|
|
|
parentTable: table, |
|
|
|
|
childTable, |
|
|
|
|
type: "hm" |
|
|
|
|
}) |
|
|
|
|
type: 'hm', |
|
|
|
|
}); |
|
|
|
|
const childRow = await createRow(context, { |
|
|
|
|
project, |
|
|
|
|
table: childTable, |
|
|
|
|
}) |
|
|
|
|
const ltarColOptions = await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
}); |
|
|
|
|
const ltarColOptions = |
|
|
|
|
await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
const childCol = await ltarColOptions.getChildColumn(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await baseModelSql.nestedInsert( |
|
|
|
|
{...generateDefaultRowAttributes({columns}), [ltarColumn.title]: [{'Id': childRow['Id']}]},
|
|
|
|
|
{ |
|
|
|
|
...generateDefaultRowAttributes({ columns }), |
|
|
|
|
[ltarColumn.title]: [{ Id: childRow['Id'] }], |
|
|
|
|
}, |
|
|
|
|
undefined, |
|
|
|
|
request |
|
|
|
|
); |
|
|
|
@ -349,8 +420,8 @@ function baseModelSqlTests() {
|
|
|
|
|
const childBaseModel = new BaseModelSqlv2({ |
|
|
|
|
dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), |
|
|
|
|
model: childTable, |
|
|
|
|
view |
|
|
|
|
}) |
|
|
|
|
view, |
|
|
|
|
}); |
|
|
|
|
const insertedChildRow = await childBaseModel.readByPk(childRow['Id']); |
|
|
|
|
expect(insertedChildRow[childCol.column_name]).to.equal(childRow['Id']); |
|
|
|
|
|
|
|
|
@ -369,48 +440,55 @@ function baseModelSqlTests() {
|
|
|
|
|
op_sub_type: 'INSERT', |
|
|
|
|
description: '1 inserted into Table1_Title', |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Link child', async () => { |
|
|
|
|
const childTable = await createTable(context, project, { |
|
|
|
|
title: 'Child Table', |
|
|
|
|
table_name: 'child_table', |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
const ltarColumn = await createLtarColumn(context, { |
|
|
|
|
title: 'Ltar Column', |
|
|
|
|
parentTable: table, |
|
|
|
|
childTable, |
|
|
|
|
type: "hm" |
|
|
|
|
}) |
|
|
|
|
type: 'hm', |
|
|
|
|
}); |
|
|
|
|
const insertedChildRow = await createRow(context, { |
|
|
|
|
project, |
|
|
|
|
table: childTable, |
|
|
|
|
}) |
|
|
|
|
const ltarColOptions = await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
}); |
|
|
|
|
const ltarColOptions = |
|
|
|
|
await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
const childCol = await ltarColOptions.getChildColumn(); |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await baseModelSql.insert(generateDefaultRowAttributes({columns}), undefined, request); |
|
|
|
|
await baseModelSql.insert( |
|
|
|
|
generateDefaultRowAttributes({ columns }), |
|
|
|
|
undefined, |
|
|
|
|
request |
|
|
|
|
); |
|
|
|
|
const insertedRow = await baseModelSql.readByPk(1); |
|
|
|
|
|
|
|
|
|
await baseModelSql.addChild({ |
|
|
|
|
colId: ltarColumn.id, |
|
|
|
|
rowId: insertedRow['Id'], |
|
|
|
|
childId: insertedChildRow['Id'], |
|
|
|
|
cookie: request |
|
|
|
|
cookie: request, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const childBaseModel = new BaseModelSqlv2({ |
|
|
|
|
dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), |
|
|
|
|
model: childTable, |
|
|
|
|
view |
|
|
|
|
}) |
|
|
|
|
const updatedChildRow = await childBaseModel.readByPk(insertedChildRow['Id']); |
|
|
|
|
view, |
|
|
|
|
}); |
|
|
|
|
const updatedChildRow = await childBaseModel.readByPk( |
|
|
|
|
insertedChildRow['Id'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(updatedChildRow[childCol.column_name]).to.equal(insertedRow['Id']); |
|
|
|
|
|
|
|
|
@ -427,57 +505,65 @@ function baseModelSqlTests() {
|
|
|
|
|
row_id: '1', |
|
|
|
|
op_type: 'DATA', |
|
|
|
|
op_sub_type: 'LINK_RECORD', |
|
|
|
|
description: 'Record [id:1] record linked with record [id:1] record in Table1_Title', |
|
|
|
|
description: |
|
|
|
|
'Record [id:1] record linked with record [id:1] record in Table1_Title', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('Unlink child', async () => { |
|
|
|
|
const childTable = await createTable(context, project, { |
|
|
|
|
title: 'Child Table', |
|
|
|
|
table_name: 'child_table', |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
const ltarColumn = await createLtarColumn(context, { |
|
|
|
|
title: 'Ltar Column', |
|
|
|
|
parentTable: table, |
|
|
|
|
childTable, |
|
|
|
|
type: "hm" |
|
|
|
|
}) |
|
|
|
|
type: 'hm', |
|
|
|
|
}); |
|
|
|
|
const insertedChildRow = await createRow(context, { |
|
|
|
|
project, |
|
|
|
|
table: childTable, |
|
|
|
|
}) |
|
|
|
|
const ltarColOptions = await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
}); |
|
|
|
|
const ltarColOptions = |
|
|
|
|
await ltarColumn.getColOptions<LinkToAnotherRecordColumn>(); |
|
|
|
|
const childCol = await ltarColOptions.getChildColumn(); |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
const request = { |
|
|
|
|
clientIp: '::ffff:192.0.0.1', |
|
|
|
|
user: {email: 'test@example.com'} |
|
|
|
|
} |
|
|
|
|
user: { email: 'test@example.com' }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await baseModelSql.insert(generateDefaultRowAttributes({columns}), undefined, request); |
|
|
|
|
await baseModelSql.insert( |
|
|
|
|
generateDefaultRowAttributes({ columns }), |
|
|
|
|
undefined, |
|
|
|
|
request |
|
|
|
|
); |
|
|
|
|
const insertedRow = await baseModelSql.readByPk(1); |
|
|
|
|
|
|
|
|
|
await baseModelSql.addChild({ |
|
|
|
|
colId: ltarColumn.id, |
|
|
|
|
rowId: insertedRow['Id'], |
|
|
|
|
childId: insertedChildRow['Id'], |
|
|
|
|
cookie: request |
|
|
|
|
cookie: request, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await baseModelSql.removeChild({ |
|
|
|
|
colId: ltarColumn.id, |
|
|
|
|
rowId: insertedRow['Id'], |
|
|
|
|
childId: insertedChildRow['Id'], |
|
|
|
|
cookie: request |
|
|
|
|
cookie: request, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const childBaseModel = new BaseModelSqlv2({ |
|
|
|
|
dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), |
|
|
|
|
model: childTable, |
|
|
|
|
view |
|
|
|
|
}) |
|
|
|
|
const updatedChildRow = await childBaseModel.readByPk(insertedChildRow['Id']); |
|
|
|
|
view, |
|
|
|
|
}); |
|
|
|
|
const updatedChildRow = await childBaseModel.readByPk( |
|
|
|
|
insertedChildRow['Id'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(updatedChildRow[childCol.column_name]).to.be.null; |
|
|
|
|
|
|
|
|
@ -494,9 +580,10 @@ function baseModelSqlTests() {
|
|
|
|
|
row_id: '1', |
|
|
|
|
op_type: 'DATA', |
|
|
|
|
op_sub_type: 'UNLINK_RECORD', |
|
|
|
|
description: 'Record [id:1] record unlinked with record [id:1] record in Table1_Title', |
|
|
|
|
description: |
|
|
|
|
'Record [id:1] record unlinked with record [id:1] record in Table1_Title', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function () { |
|
|
|
|