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