Browse Source

test: general error correction

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5901/head
Raju Udava 2 years ago
parent
commit
6ad1ce8d63
  1. 102
      packages/nocodb/tests/unit/rest/tests/newDataApis.test.ts

102
packages/nocodb/tests/unit/rest/tests/newDataApis.test.ts

@ -193,6 +193,10 @@ function generalDb() {
}); });
customerColumns = await customerTable.getColumns(); customerColumns = await customerTable.getColumns();
}); });
it('should list all records', async function () {
console.log('should list all records');
});
} }
function textBased() { function textBased() {
@ -561,11 +565,7 @@ function textBased() {
url: `/api/v1/tables/123456789/rows`, url: `/api/v1/tables/123456789/rows`,
status: 404, status: 404,
}); });
// Invalid project ID
// await ncAxiosGet({
// url: `/api/v1/base/123456789/tables/123456789`,
// status: 404,
// });
// Invalid view ID // Invalid view ID
await ncAxiosGet({ await ncAxiosGet({
query: { query: {
@ -576,39 +576,56 @@ function textBased() {
}); });
it('List: invalid limit & offset', async function () { it('List: invalid limit & offset', async function () {
// Invalid limit const expectedPageInfo = {
await ncAxiosGet({ totalRows: 400,
page: 1,
pageSize: 25,
isFirstPage: true,
isLastPage: false,
};
// Invalid limit : falls back to default value
let rsp = await ncAxiosGet({
query: { query: {
limit: -100, limit: -100,
}, },
status: 200, status: 200,
}); });
await ncAxiosGet({ expect(rsp.body.pageInfo).to.deep.equal(expectedPageInfo);
rsp = await ncAxiosGet({
query: { query: {
limit: 'abc', limit: 'abc',
}, },
status: 200, status: 200,
}); });
expect(rsp.body.pageInfo).to.deep.equal(expectedPageInfo);
// Invalid offset // Invalid offset : falls back to default value
await ncAxiosGet({ rsp = await ncAxiosGet({
query: { query: {
offset: -100, offset: -100,
}, },
status: 422, status: 200,
}); });
await ncAxiosGet({ expect(rsp.body.pageInfo).to.deep.equal(expectedPageInfo);
rsp = await ncAxiosGet({
query: { query: {
offset: 'abc', offset: 'abc',
}, },
status: 422, status: 200,
}); });
await ncAxiosGet({ expect(rsp.body.pageInfo).to.deep.equal(expectedPageInfo);
// Offset > totalRows : returns empty list
rsp = await ncAxiosGet({
query: { query: {
offset: 10000, offset: 10000,
}, },
status: 422, status: 200,
}); });
expect(rsp.body.list.length).to.equal(0);
}); });
it('List: invalid sort, filter, fields', async function () { it('List: invalid sort, filter, fields', async function () {
@ -646,10 +663,7 @@ function textBased() {
it('Create: all fields', async function () { it('Create: all fields', async function () {
const rsp = await ncAxiosPost({ body: newRecord }); const rsp = await ncAxiosPost({ body: newRecord });
expect(rsp.body).to.deep.equal({ expect(rsp.body).to.deep.equal({ Id: 401 });
Id: 401,
...newRecord,
});
}); });
it('Create: few fields left out', async function () { it('Create: few fields left out', async function () {
@ -660,13 +674,7 @@ function textBased() {
const rsp = await ncAxiosPost({ body: newRecord }); const rsp = await ncAxiosPost({ body: newRecord });
// fields left out should be null // fields left out should be null
expect(rsp.body).to.deep.equal({ expect(rsp.body).to.deep.equal({ Id: 401 });
Id: 401,
...newRecord,
Email: null,
Url: null,
Phone: null,
});
}); });
it('Create: bulk', async function () { it('Create: bulk', async function () {
@ -682,11 +690,7 @@ function textBased() {
url: `/api/v1/tables/123456789/rows`, url: `/api/v1/tables/123456789/rows`,
status: 404, status: 404,
}); });
// Invalid project ID
// await ncAxiosPost({
// url: `/api/v1/base/123456789/tables/123456789`,
// status: 404,
// });
// Invalid data - create should not specify ID // Invalid data - create should not specify ID
await ncAxiosPost({ await ncAxiosPost({
body: { ...newRecord, Id: 300 }, body: { ...newRecord, Id: 300 },
@ -743,11 +747,7 @@ function textBased() {
}, },
], ],
}); });
expect(rsp.body).to.deep.equal([ expect(rsp.body).to.deep.equal([{ Id: 1 }]);
{
Id: '1',
},
]);
}); });
it('Update: partial', async function () { it('Update: partial', async function () {
@ -764,11 +764,7 @@ function textBased() {
}, },
], ],
}); });
expect(rsp.body).to.deep.equal([ expect(rsp.body).to.deep.equal([{ Id: 1 }]);
{
Id: '1',
},
]);
const recordAfterUpdate = await ncAxiosGet({ const recordAfterUpdate = await ncAxiosGet({
url: `/api/v1/tables/${table.id}/rows/1`, url: `/api/v1/tables/${table.id}/rows/1`,
@ -795,17 +791,12 @@ function textBased() {
}, },
], ],
}); });
expect(rsp.body).to.deep.equal([{ Id: '1' }, { Id: '2' }]); expect(rsp.body).to.deep.equal([{ Id: 1 }, { Id: 2 }]);
}); });
// Error handling // Error handling
it('Update: invalid ID', async function () { it('Update: invalid ID', async function () {
// // Invalid project ID
// await ncAxiosPatch({
// url: `/api/v1/base/123456789/tables/${table.id}`,
// status: 404,
// });
// Invalid table ID // Invalid table ID
await ncAxiosPatch({ await ncAxiosPatch({
url: `/api/v1/tables/123456789/rows`, url: `/api/v1/tables/123456789/rows`,
@ -815,7 +806,7 @@ function textBased() {
// Invalid row ID // Invalid row ID
await ncAxiosPatch({ await ncAxiosPatch({
body: { Id: 123456789, SingleLineText: 'some text' }, body: { Id: 123456789, SingleLineText: 'some text' },
status: 400, status: 422,
}); });
}); });
@ -828,9 +819,9 @@ function textBased() {
it('Delete: single', async function () { it('Delete: single', async function () {
const rsp = await ncAxiosDelete({ body: [{ Id: 1 }] }); const rsp = await ncAxiosDelete({ body: [{ Id: 1 }] });
expect(rsp.body).to.deep.equal([{ Id: '1' }]); expect(rsp.body).to.deep.equal([{ Id: 1 }]);
// // check that it's gone // check that it's gone
await ncAxiosGet({ await ncAxiosGet({
url: `/api/v1/tables/${table.id}/rows/1`, url: `/api/v1/tables/${table.id}/rows/1`,
status: 404, status: 404,
@ -839,7 +830,7 @@ function textBased() {
it('Delete: bulk', async function () { it('Delete: bulk', async function () {
const rsp = await ncAxiosDelete({ body: [{ Id: 1 }, { Id: 2 }] }); const rsp = await ncAxiosDelete({ body: [{ Id: 1 }, { Id: 2 }] });
expect(rsp.body).to.deep.equal([{ Id: '1' }, { Id: '2' }]); expect(rsp.body).to.deep.equal([{ Id: 1 }, { Id: 2 }]);
// check that it's gone // check that it's gone
await ncAxiosGet({ await ncAxiosGet({
@ -855,11 +846,6 @@ function textBased() {
// Error handling // Error handling
it('Delete: invalid ID', async function () { it('Delete: invalid ID', async function () {
// // Invalid project ID
// await ncAxiosDelete({
// url: `/api/v1/tables/${table.id}/rows`,
// status: 404,
// });
// Invalid table ID // Invalid table ID
await ncAxiosDelete({ await ncAxiosDelete({
url: `/api/v1/tables/123456789/rows`, url: `/api/v1/tables/123456789/rows`,
@ -867,7 +853,7 @@ function textBased() {
status: 404, status: 404,
}); });
// Invalid row ID // Invalid row ID
await ncAxiosDelete({ body: { Id: 123456789 }, status: 400 }); await ncAxiosDelete({ body: { Id: '123456789' }, status: 422 });
}); });
} }
@ -1480,11 +1466,11 @@ function dateBased() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
export default function () { export default function () {
// describe('General', generalDb);
describe('Text based', textBased); describe('Text based', textBased);
describe('Numerical', numberBased); describe('Numerical', numberBased);
describe('Select based', selectBased); describe('Select based', selectBased);
describe('Date based', dateBased); describe('Date based', dateBased);
// describe('General', generalDb);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

Loading…
Cancel
Save