From 497903260ba5dfb8efab97c54958c5b9ea5a84ba Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 30 Sep 2022 14:10:57 +0800 Subject: [PATCH] test: prettier viewRow.test.ts --- .../tests/unit/rest/tests/viewRow.test.ts | 414 +++++++++++------- 1 file changed, 251 insertions(+), 163 deletions(-) diff --git a/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts b/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts index 282949b14d..9a0e45a78a 100644 --- a/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts +++ b/packages/nocodb/tests/unit/rest/tests/viewRow.test.ts @@ -8,8 +8,19 @@ import { createTable, getTable } from '../../factory/table'; import View from '../../../../src/lib/models/View'; import { ColumnType, UITypes, ViewTypes } from 'nocodb-sdk'; import { createView } from '../../factory/view'; -import { createColumn, createLookupColumn, createLtarColumn, createRollupColumn, updateViewColumn } from '../../factory/column'; -import { createChildRow, createRow, getOneRow, getRow } from '../../factory/row'; +import { + createColumn, + createLookupColumn, + createLtarColumn, + createRollupColumn, + updateViewColumn, +} from '../../factory/column'; +import { + createChildRow, + createRow, + getOneRow, + getRow, +} from '../../factory/row'; import { expect } from 'chai'; const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => { @@ -36,54 +47,66 @@ function viewRowTests() { context = await init(); sakilaProject = await createSakilaProject(context); project = await createProject(context); - customerTable = await getTable({project: sakilaProject, name: 'customer'}) + customerTable = await getTable({ + project: sakilaProject, + name: 'customer', + }); customerColumns = await customerTable.getColumns(); customerGridView = await createView(context, { title: 'Customer Gallery', table: customerTable, - type: ViewTypes.GRID + type: ViewTypes.GRID, }); customerGalleryView = await createView(context, { title: 'Customer Gallery', table: customerTable, - type: ViewTypes.GALLERY + type: ViewTypes.GALLERY, }); customerFormView = await createView(context, { - title: 'Customer Form', + title: 'Customer Form', table: customerTable, - type: ViewTypes.FORM + type: ViewTypes.FORM, }); }); const testGetViewRowListGallery = async (view: View) => { const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .expect(200); const pageInfo = response.body.pageInfo; - if(pageInfo.totalRows !== 599 || response.body.list[0]['CustomerId'] !== 1){ + if ( + pageInfo.totalRows !== 599 || + response.body.list[0]['CustomerId'] !== 1 + ) { throw new Error('View row list is not correct'); } - } + }; it('Get view row list gallery', async () => { await testGetViewRowListGallery(customerGalleryView); - }) + }); it('Get view row list form', async () => { await testGetViewRowListGallery(customerFormView); - }) + }); it('Get view row list grid', async () => { await testGetViewRowListGallery(customerGridView); - }) + }); const testGetViewDataListWithRequiredColumns = async (view: View) => { - const requiredColumns = customerColumns.filter((_, index) => index < 3).filter((c: ColumnType) => c.uidt !== UITypes.ForeignKey); + const requiredColumns = customerColumns + .filter((_, index) => index < 3) + .filter((c: ColumnType) => c.uidt !== UITypes.ForeignKey); const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ fields: requiredColumns.map((c) => c.title), @@ -96,22 +119,28 @@ function viewRowTests() { } if (!isColumnsCorrectInResponse(response.body.list[0], requiredColumns)) { - console.log(response.body.list[0], requiredColumns.map((c: ColumnType) => ({title: c.title,uidt: c.uidt}))); + console.log( + response.body.list[0], + requiredColumns.map((c: ColumnType) => ({ + title: c.title, + uidt: c.uidt, + })) + ); throw new Error('Wrong columns'); } - } + }; it('Get view data list with required columns gallery', async () => { await testGetViewDataListWithRequiredColumns(customerGalleryView); - }) + }); it('Get view data list with required columns form', async () => { await testGetViewDataListWithRequiredColumns(customerFormView); - }) + }); it('Get view data list with required columns grid', async () => { await testGetViewDataListWithRequiredColumns(customerGridView); - }) + }); const testDescSortedViewDataList = async (view: View) => { const firstNameColumn = customerColumns.find( @@ -121,7 +150,9 @@ function viewRowTests() { const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'desc' }]; const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ fields: visibleColumns.map((c) => c.title), @@ -147,7 +178,9 @@ function viewRowTests() { const lastPageOffset = Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize; const lastPageResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ fields: visibleColumns.map((c) => c.title), @@ -164,7 +197,7 @@ function viewRowTests() { console.log(lastPageOffset, lastPageResponse.body.list); throw new Error('Wrong sort on last page'); } - } + }; it('Get desc sorted table data list with required columns gallery', async function () { await testDescSortedViewDataList(customerGalleryView); @@ -186,7 +219,9 @@ function viewRowTests() { const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'asc' }]; const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ fields: visibleColumns.map((c) => c.title), @@ -212,7 +247,9 @@ function viewRowTests() { const lastPageOffset = Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize; const lastPageResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ fields: visibleColumns.map((c) => c.title), @@ -229,7 +266,7 @@ function viewRowTests() { console.log(lastPageOffset, lastPageResponse.body.list); throw new Error('Wrong sort on last page'); } - } + }; it('Get asc sorted view data list with required columns gallery', async function () { await testAscSortedViewDataList(customerGalleryView); @@ -243,12 +280,17 @@ function viewRowTests() { await testAscSortedViewDataList(customerGridView); }); - const testGetViewDataListWithRequiredColumnsAndFilter = async (viewType: ViewTypes) => { - const rentalTable = await getTable({project: sakilaProject, name: 'rental'}); + const testGetViewDataListWithRequiredColumnsAndFilter = async ( + viewType: ViewTypes + ) => { + const rentalTable = await getTable({ + project: sakilaProject, + name: 'rental', + }); const view = await createView(context, { - title: 'View', + title: 'View', table: rentalTable, - type: viewType + type: viewType, }); const lookupColumn = await createLookupColumn(context, { @@ -285,16 +327,20 @@ function viewRowTests() { }; const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ filterArrJson: JSON.stringify([nestedFilter]), }); - - expect(response.body.pageInfo.totalRows).equal(9558) + + expect(response.body.pageInfo.totalRows).equal(9558); const ascResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ filterArrJson: JSON.stringify([nestedFilter]), @@ -307,11 +353,13 @@ function viewRowTests() { }) .expect(200); - expect(ascResponse.body.pageInfo.totalRows).equal(9558) - expect(ascResponse.body.list[0][lookupColumn.title]).equal('AARON') + expect(ascResponse.body.pageInfo.totalRows).equal(9558); + expect(ascResponse.body.list[0][lookupColumn.title]).equal('AARON'); const descResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ filterArrJson: JSON.stringify([nestedFilter]), @@ -324,9 +372,9 @@ function viewRowTests() { }) .expect(200); - expect(descResponse.body.pageInfo.totalRows).equal(9558) - expect(descResponse.body.list[0][lookupColumn.title]).equal('ZACHARY') - } + expect(descResponse.body.pageInfo.totalRows).equal(9558); + expect(descResponse.body.list[0][lookupColumn.title]).equal('ZACHARY'); + }; it('Get nested sorted filtered table data list with a lookup column gallery', async function () { await testGetViewDataListWithRequiredColumnsAndFilter(ViewTypes.GALLERY); @@ -336,11 +384,13 @@ function viewRowTests() { await testGetViewDataListWithRequiredColumnsAndFilter(ViewTypes.GRID); }); - const testGetNestedSortedFilteredTableDataListWithLookupColumn = async (viewType: ViewTypes) => { + const testGetNestedSortedFilteredTableDataListWithLookupColumn = async ( + viewType: ViewTypes + ) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const rollupColumn = await createRollupColumn(context, { @@ -400,7 +450,7 @@ function viewRowTests() { fk_column_id: activeColumn?.id, status: 'create', comparison_op: 'eq', - value: 1 + value: 1, }, ], }, @@ -409,7 +459,9 @@ function viewRowTests() { ]; const ascResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .query({ nested: nestedFields, @@ -434,17 +486,21 @@ function viewRowTests() { ); if ( - !(nestedRentalResponse.includes('RentalId') && - nestedRentalResponse.includes('RentalDate') && - nestedRentalResponse.length === 2) + !( + nestedRentalResponse.includes('RentalId') && + nestedRentalResponse.includes('RentalDate') && + nestedRentalResponse.length === 2 + ) ) { throw new Error('Wrong nested fields'); } - } + }; it('Get nested sorted filtered table with nested fields data list with a rollup column in customer table view grid', async () => { - await testGetNestedSortedFilteredTableDataListWithLookupColumn(ViewTypes.GRID); - }) + await testGetNestedSortedFilteredTableDataListWithLookupColumn( + ViewTypes.GRID + ); + }); // todo: gallery view doesnt seem to support rollup // it('Get nested sorted filtered table with nested fields data list with a rollup column in customer table view gallery', async () => { @@ -454,9 +510,9 @@ function viewRowTests() { const testCreateRowView = async (viewType: ViewTypes) => { const table = await createTable(context, project); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); const response = await request(context.app) @@ -469,7 +525,7 @@ function viewRowTests() { const row = response.body; if (row['Title'] !== 'Test') throw new Error('Wrong row title'); - } + }; it('Create table row grid', async function () { await testCreateRowView(ViewTypes.GRID); @@ -486,19 +542,21 @@ function viewRowTests() { const testCreateRowViewWithWrongView = async (viewType: ViewTypes) => { const table = await createTable(context, project); const nonRelatedView = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); await request(context.app) - .post(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${nonRelatedView.id}`) + .post( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${nonRelatedView.id}` + ) .set('xc-auth', context.token) .send({ title: 'Test', }) .expect(400); - } + }; it('Create table row grid wrong grid id', async function () { await testCreateRowViewWithWrongView(ViewTypes.GRID); @@ -514,11 +572,13 @@ function viewRowTests() { // todo: Test that all the columns needed to be shown in the view are returned - const testFindOneSortedDataWithRequiredColumns = async (viewType: ViewTypes) => { + const testFindOneSortedDataWithRequiredColumns = async ( + viewType: ViewTypes + ) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const firstNameColumn = customerColumns.find( (col) => col.title === 'FirstName' @@ -566,7 +626,7 @@ function viewRowTests() { console.log(response.body); throw new Error('Wrong sort'); } - } + }; it('Find one sorted data list with required columns gallery', async function () { await testFindOneSortedDataWithRequiredColumns(ViewTypes.GALLERY); @@ -579,8 +639,10 @@ function viewRowTests() { it('Find one sorted data list with required columns grid', async function () { await testFindOneSortedDataWithRequiredColumns(ViewTypes.GRID); }); - - const testFindOneSortedFilteredNestedFieldsDataWithRollup = async (viewType: ViewTypes) => { + + const testFindOneSortedFilteredNestedFieldsDataWithRollup = async ( + viewType: ViewTypes + ) => { const rollupColumn = await createRollupColumn(context, { project: sakilaProject, title: 'Number of rentals', @@ -590,17 +652,17 @@ function viewRowTests() { relatedTableColumnTitle: 'RentalDate', }); const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); await updateViewColumn(context, { column: rollupColumn, view: view, - attr: {show: true}, - }) - + attr: { show: true }, + }); + const paymentListColumn = (await customerTable.getColumns()).find( (c) => c.title === 'Payment List' ); @@ -649,7 +711,7 @@ function viewRowTests() { fk_column_id: activeColumn?.id, status: 'create', comparison_op: 'eq', - value: 1 + value: 1, }, ], }, @@ -670,7 +732,7 @@ function viewRowTests() { .expect(200); if (ascResponse.body[rollupColumn.title] !== 12) { - console.log('response.body',ascResponse.body); + console.log('response.body', ascResponse.body); throw new Error('Wrong filter'); } @@ -682,7 +744,7 @@ function viewRowTests() { ) { throw new Error('Wrong nested fields'); } - } + }; // todo: gallery view doesnt seem to support rollup // it.only('Find one sorted filtered view with nested fields data list with a rollup column in customer table GALLERY', async function () { @@ -699,9 +761,9 @@ function viewRowTests() { const testGroupDescSorted = async (viewType: ViewTypes) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const firstNameColumn = customerColumns.find( (col) => col.title === 'FirstName' @@ -736,7 +798,7 @@ function viewRowTests() { response.body.list[4]['count'] !== 2 ) throw new Error('Wrong groupby'); - } + }; it('Groupby desc sorted and with rollup view data list with required columns GRID', async function () { await testGroupDescSorted(ViewTypes.GRID); @@ -752,9 +814,9 @@ function viewRowTests() { const testGroupWithOffset = async (viewType: ViewTypes) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const firstNameColumn = customerColumns.find( @@ -791,7 +853,7 @@ function viewRowTests() { response.body.list[0]['count'] !== 2 ) throw new Error('Wrong groupby'); - } + }; it('Groupby desc sorted and with rollup view data list with required columns GALLERY', async function () { await testGroupWithOffset(ViewTypes.GALLERY); @@ -807,20 +869,22 @@ function viewRowTests() { const testCount = async (viewType: ViewTypes) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/count`) - .set('xc-auth', context.token) - .expect(200); + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/count` + ) + .set('xc-auth', context.token) + .expect(200); - if(response.body.count !== 599) { + if (response.body.count !== 599) { throw new Error('Wrong count'); } - } + }; it('Count view data list with required columns GRID', async function () { await testCount(ViewTypes.GRID); @@ -834,16 +898,17 @@ function viewRowTests() { await testCount(ViewTypes.GALLERY); }); - const testReadViewRow = async (viewType: ViewTypes) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const listResponse = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}` + ) .set('xc-auth', context.token) .expect(200); @@ -862,31 +927,33 @@ function viewRowTests() { ) { throw new Error('Wrong read'); } - } + }; it('Read view row GALLERY', async function () { await testReadViewRow(ViewTypes.GALLERY); - }) + }); it('Read view row FORM', async function () { await testReadViewRow(ViewTypes.FORM); - }) + }); it('Read view row GRID', async function () { await testReadViewRow(ViewTypes.GRID); - }) + }); const testUpdateViewRow = async (viewType: ViewTypes) => { const table = await createTable(context, project); const row = await createRow(context, { project, table }); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); const updateResponse = await request(context.app) - .patch(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`) + .patch( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}` + ) .set('xc-auth', context.token) .send({ title: 'Updated', @@ -896,21 +963,23 @@ function viewRowTests() { if (updateResponse.body['Title'] !== 'Updated') { throw new Error('Wrong update'); } - } + }; it('Update view row GALLERY', async function () { await testUpdateViewRow(ViewTypes.GALLERY); - }) + }); it('Update view row GRID', async function () { await testUpdateViewRow(ViewTypes.GRID); - }) + }); it('Update view row FORM', async function () { await testUpdateViewRow(ViewTypes.FORM); - }) + }); - const testUpdateViewRowWithValidationAndInvalidData = async (viewType: ViewTypes) => { + const testUpdateViewRowWithValidationAndInvalidData = async ( + viewType: ViewTypes + ) => { const table = await createTable(context, project); const emailColumn = await createColumn(context, table, { title: 'Email', @@ -921,38 +990,42 @@ function viewRowTests() { }, }); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); const row = await createRow(context, { project, table }); await request(context.app) - .patch(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`) + .patch( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}` + ) .set('xc-auth', context.token) .send({ [emailColumn.column_name]: 'invalidemail', }) .expect(400); - } + }; it('Update view row with validation and invalid data GALLERY', async function () { await testUpdateViewRowWithValidationAndInvalidData(ViewTypes.GALLERY); - }) + }); it('Update view row with validation and invalid data GRID', async function () { await testUpdateViewRowWithValidationAndInvalidData(ViewTypes.GRID); - }) + }); it('Update view row with validation and invalid data FORM', async function () { await testUpdateViewRowWithValidationAndInvalidData(ViewTypes.FORM); - }) + }); // todo: Test webhooks of before and after update // todo: Test with form view - const testUpdateViewRowWithValidationAndValidData = async (viewType: ViewTypes) => { + const testUpdateViewRowWithValidationAndValidData = async ( + viewType: ViewTypes + ) => { const table = await createTable(context, project); const emailColumn = await createColumn(context, table, { title: 'Email', @@ -963,77 +1036,82 @@ function viewRowTests() { }, }); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); const row = await createRow(context, { project, table }); const response = await request(context.app) - .patch(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`) + .patch( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}` + ) .set('xc-auth', context.token) .send({ [emailColumn.column_name]: 'valid@example.com', }) .expect(200); - const updatedRow = await getRow( - context, - {project, + const updatedRow = await getRow(context, { + project, table, - id: response.body['Id']} - ); + id: response.body['Id'], + }); if (updatedRow[emailColumn.title] !== 'valid@example.com') { throw new Error('Wrong update'); } - } + }; it('Update view row with validation and valid data GALLERY', async function () { await testUpdateViewRowWithValidationAndValidData(ViewTypes.GALLERY); - }) + }); it('Update view row with validation and valid data GRID', async function () { await testUpdateViewRowWithValidationAndValidData(ViewTypes.GRID); - }) + }); it('Update view row with validation and valid data FORM', async function () { await testUpdateViewRowWithValidationAndValidData(ViewTypes.FORM); - }) + }); const testDeleteViewRow = async (viewType: ViewTypes) => { const table = await createTable(context, project); const row = await createRow(context, { project, table }); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); await request(context.app) - .delete(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`) + .delete( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}` + ) .set('xc-auth', context.token) .expect(200); - const deleteRow = await getRow(context, {project, table, id: row['Id']}); + const deleteRow = await getRow(context, { project, table, id: row['Id'] }); if (deleteRow && Object.keys(deleteRow).length > 0) { console.log(deleteRow); throw new Error('Wrong delete'); } - } + }; it('Delete view row GALLERY', async function () { await testDeleteViewRow(ViewTypes.GALLERY); - }) + }); it('Delete view row GRID', async function () { await testDeleteViewRow(ViewTypes.GRID); - }) + }); it('Delete view row FORM', async function () { await testDeleteViewRow(ViewTypes.FORM); - }) + }); - const testDeleteViewRowWithForiegnKeyConstraint = async (viewType: ViewTypes) => { + const testDeleteViewRowWithForiegnKeyConstraint = async ( + viewType: ViewTypes + ) => { const table = await createTable(context, project); const relatedTable = await createTable(context, project, { table_name: 'Table2', @@ -1046,9 +1124,9 @@ function viewRowTests() { type: 'hm', }); const view = await createView(context, { - title: 'View', + title: 'View', table: table, - type: viewType + type: viewType, }); const row = await createRow(context, { project, table }); @@ -1063,11 +1141,13 @@ function viewRowTests() { }); const response = await request(context.app) - .delete(`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`) + .delete( + `/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}` + ) .set('xc-auth', context.token) .expect(200); - const deleteRow = await getRow(context, {project, table, id: row['Id']}); + const deleteRow = await getRow(context, { project, table, id: row['Id'] }); if (!deleteRow) { throw new Error('Should not delete'); } @@ -1079,19 +1159,19 @@ function viewRowTests() { ) { throw new Error('Should give ltar foreign key error'); } - } + }; it('Delete view row with ltar foreign key constraint GALLERY', async function () { await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.GALLERY); - }) + }); it('Delete view row with ltar foreign key constraint GRID', async function () { await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.GRID); - }) + }); it('Delete view row with ltar foreign key constraint FORM', async function () { await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.FORM); - }) + }); const testViewRowExists = async (viewType: ViewTypes) => { const row = await getOneRow(context, { @@ -1099,9 +1179,9 @@ function viewRowTests() { table: customerTable, }); const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const response = await request(context.app) @@ -1114,7 +1194,7 @@ function viewRowTests() { if (!response.body) { throw new Error('Should exist'); } - } + }; it('Exist should be true view row when it exists GALLERY', async function () { await testViewRowExists(ViewTypes.GALLERY); @@ -1122,17 +1202,17 @@ function viewRowTests() { it('Exist should be true view row when it exists GRID', async function () { await testViewRowExists(ViewTypes.GRID); - }) + }); it('Exist should be true view row when it exists FORM', async function () { await testViewRowExists(ViewTypes.FORM); - }) + }); const testViewRowNotExists = async (viewType: ViewTypes) => { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: viewType + type: viewType, }); const response = await request(context.app) .get( @@ -1144,61 +1224,69 @@ function viewRowTests() { if (response.body) { throw new Error('Should not exist'); } - } + }; it('Exist should be false view row when it does not exist GALLERY', async function () { await testViewRowNotExists(ViewTypes.GALLERY); - }) + }); it('Exist should be false view row when it does not exist GRID', async function () { await testViewRowNotExists(ViewTypes.GRID); - }) + }); it('Exist should be false view row when it does not exist FORM', async function () { await testViewRowNotExists(ViewTypes.FORM); - }) + }); it('Export csv GRID', async function () { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: ViewTypes.GRID + type: ViewTypes.GRID, }); const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/csv`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/csv` + ) .set('xc-auth', context.token) .expect(200); - if(!response['header']['content-disposition'].includes("View-export.csv")){ + if ( + !response['header']['content-disposition'].includes('View-export.csv') + ) { console.log(response['header']['content-disposition']); throw new Error('Wrong file name'); } - if(!response.text){ + if (!response.text) { throw new Error('Wrong export'); } - }) + }); it('Export excel GRID', async function () { const view = await createView(context, { - title: 'View', + title: 'View', table: customerTable, - type: ViewTypes.GRID + type: ViewTypes.GRID, }); const response = await request(context.app) - .get(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/excel`) + .get( + `/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/excel` + ) .set('xc-auth', context.token) .expect(200); - if(!response['header']['content-disposition'].includes("View-export.xlsx")){ + if ( + !response['header']['content-disposition'].includes('View-export.xlsx') + ) { console.log(response['header']['content-disposition']); throw new Error('Wrong file name'); } - if(!response.text){ + if (!response.text) { throw new Error('Wrong export'); } - }) + }); } export default function () { - describe('ViewRow', viewRowTests); -} \ No newline at end of file + describe.only('ViewRow', viewRowTests); +}