Browse Source

test: many-many, belongs to error handling

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

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

@ -208,7 +208,7 @@ async function ncAxiosLinkGet({
if (debugMode && status !== 200) { if (debugMode && status !== 200) {
console.log('#### ', response.body.msg); console.log('#### ', response.body.msg);
} }
if (msg) expect(response.body.msg).to.equal(msg); if (!debugMode && msg) expect(response.body.msg).to.equal(msg);
return response; return response;
} }
@ -234,7 +234,7 @@ async function ncAxiosLinkAdd({
console.log('#### ', response.body.msg); console.log('#### ', response.body.msg);
} }
if (msg) expect(response.body.msg).to.equal(msg); if (!debugMode && msg) expect(response.body.msg).to.equal(msg);
return response; return response;
} }
@ -258,7 +258,7 @@ async function ncAxiosLinkRemove({
if (debugMode && status !== 200) { if (debugMode && status !== 200) {
console.log('#### ', response.body.msg); console.log('#### ', response.body.msg);
} }
if (msg) expect(response.body.msg).to.equal(msg); if (!debugMode && msg) expect(response.body.msg).to.equal(msg);
return response; return response;
} }
@ -2316,18 +2316,7 @@ function linkBased() {
} }
}); });
// Error handling (has-many) async function nestedAddTests(validParams, relationType?) {
it('Error handling : Nested ADD', async function () {
const validParams = {
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
};
// Link Add: Invalid table ID // Link Add: Invalid table ID
if (debugMode) console.log('Link Add: Invalid table ID'); if (debugMode) console.log('Link Add: Invalid table ID');
await ncAxiosLinkAdd({ await ncAxiosLinkAdd({
@ -2367,49 +2356,40 @@ function linkBased() {
status: 201, status: 201,
}); });
// Link Add: Invalid body parameter - row id invalid if (relationType === 'bt') {
if (debugMode) // Link Add: Invalid body parameter - row id invalid
console.log('Link Add: Invalid body parameter - row id invalid'); if (debugMode)
await ncAxiosLinkAdd({ console.log('Link Add: Invalid body parameter - row id invalid');
...validParams, await ncAxiosLinkAdd({
body: [999, 998, 997], ...validParams,
status: 422, body: [999, 998],
msg: 'Child record with id 999, 998, 997 not found', status: 422,
}); msg: 'Child record with id 999, 998 invalid for belongs-to relation field. Should contain only one value',
});
// Link Add: Invalid body parameter - repeated row id } else {
if (debugMode) // Link Add: Invalid body parameter - row id invalid
console.log('Link Add: Invalid body parameter - repeated row id'); if (debugMode)
await ncAxiosLinkAdd({ console.log('Link Add: Invalid body parameter - row id invalid');
...validParams, await ncAxiosLinkAdd({
body: [1, 2, 1, 2], ...validParams,
status: 422, body: [999, 998, 997],
msg: 'Child record with id 1, 2, 1, 2 contains duplicate value', status: 422,
}); msg: 'Child record with id 999, 998, 997 not found',
}); });
it('Error handling : Nested REMOVE', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = { // Link Add: Invalid body parameter - repeated row id
urlParams: { if (debugMode)
tableId: tblCountry.id, console.log('Link Add: Invalid body parameter - repeated row id');
linkId: getColumnId(columnsCountry, 'Cities'), await ncAxiosLinkAdd({
rowId: 1, ...validParams,
}, body: [1, 2, 1, 2],
body: [1, 2, 3], status: 422,
status: 200, msg: 'Child record with id 1, 2, 1, 2 contains duplicate value',
}; });
}
}
async function nestedRemoveTests(validParams, relationType?) {
// Link Remove: Invalid table ID // Link Remove: Invalid table ID
if (debugMode) console.log('Link Remove: Invalid table ID'); if (debugMode) console.log('Link Remove: Invalid table ID');
await ncAxiosLinkRemove({ await ncAxiosLinkRemove({
@ -2449,52 +2429,40 @@ function linkBased() {
status: 200, status: 200,
}); });
// Link Remove: Invalid body parameter - row id invalid if (relationType === 'bt') {
if (debugMode) // Link Remove: Invalid body parameter - row id invalid
console.log('Link Remove: Invalid body parameter - row id invalid'); if (debugMode)
await ncAxiosLinkRemove({ console.log('Link Remove: Invalid body parameter - row id invalid');
...validParams, await ncAxiosLinkRemove({
body: [999, 998], ...validParams,
status: 422, body: [999, 998],
msg: 'Child record with id 999, 998 not found', status: 422,
}); msg: 'Child record with id 999, 998 invalid for belongs-to relation field. Should contain only one value',
});
// Link Remove: Invalid body parameter - repeated row id } else {
if (debugMode) // Link Remove: Invalid body parameter - row id invalid
console.log('Link Remove: Invalid body parameter - repeated row id'); if (debugMode)
await ncAxiosLinkRemove({ console.log('Link Remove: Invalid body parameter - row id invalid');
...validParams, await ncAxiosLinkRemove({
body: [1, 2, 1, 2], ...validParams,
status: 422, body: [999, 998],
msg: 'Child record with id 1, 2, 1, 2 contains duplicate value', status: 422,
}); msg: 'Child record with id 999, 998 not found',
}); });
it('Error handling : Nested List', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = { // Link Remove: Invalid body parameter - repeated row id
urlParams: { if (debugMode)
tableId: tblCountry.id, console.log('Link Remove: Invalid body parameter - repeated row id');
linkId: getColumnId(columnsCountry, 'Cities'), await ncAxiosLinkRemove({
rowId: 1, ...validParams,
}, body: [1, 2, 1, 2],
query: { status: 422,
offset: 0, msg: 'Child record with id 1, 2, 1, 2 contains duplicate value',
limit: 10, });
}, }
status: 200, }
};
async function nestedListTests(validParams) {
// Link List: Invalid table ID // Link List: Invalid table ID
if (debugMode) console.log('Link List: Invalid table ID'); if (debugMode) console.log('Link List: Invalid table ID');
await ncAxiosLinkGet({ await ncAxiosLinkGet({
@ -2578,6 +2546,210 @@ function linkBased() {
query: { ...validParams.query, limit: 9999 }, query: { ...validParams.query, limit: 9999 },
status: 200, status: 200,
}); });
}
// Error handling (has-many)
it('Error handling : HM: Nested ADD', async function () {
const validParams = {
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
};
await nestedAddTests(validParams);
});
it('Error handling : HM: Nested REMOVE', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3],
status: 200,
};
await nestedRemoveTests(validParams);
});
it('Error handling : HM: Nested List', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
query: {
offset: 0,
limit: 10,
},
status: 200,
};
await nestedListTests(validParams);
});
// Error handling (belongs to)
it('Error handling : BT: Nested ADD', async function () {
const validParams = {
urlParams: {
tableId: tblCity.id,
linkId: getColumnId(columnsCity, 'Country'),
rowId: 1,
},
body: [1],
status: 201,
};
await nestedAddTests(validParams, 'bt');
});
it('Error handling : BT: Nested REMOVE', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCity.id,
linkId: getColumnId(columnsCity, 'Country'),
rowId: 1,
},
body: [1],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblCity.id,
linkId: getColumnId(columnsCity, 'Country'),
rowId: 1,
},
body: [1],
status: 200,
};
await nestedRemoveTests(validParams, 'bt');
});
it('Error handling : BT: Nested List', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblCity.id,
linkId: getColumnId(columnsCity, 'Country'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblCity.id,
linkId: getColumnId(columnsCity, 'Country'),
rowId: 1,
},
query: {
offset: 0,
limit: 10,
},
status: 200,
};
await nestedListTests(validParams);
});
// Error handling (many-many)
it('Error handling : MM: Nested ADD', async function () {
const validParams = {
urlParams: {
tableId: tblActor.id,
linkId: getColumnId(columnsActor, 'Films'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
};
await nestedAddTests(validParams);
});
it('Error handling : MM: Nested REMOVE', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblActor.id,
linkId: getColumnId(columnsActor, 'Films'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblCountry.id,
linkId: getColumnId(columnsCountry, 'Cities'),
rowId: 1,
},
body: [1, 2, 3],
status: 200,
};
await nestedRemoveTests(validParams);
});
it('Error handling : MM: Nested List', async function () {
// Prepare data
await ncAxiosLinkAdd({
urlParams: {
tableId: tblActor.id,
linkId: getColumnId(columnsActor, 'Films'),
rowId: 1,
},
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
status: 201,
});
const validParams = {
urlParams: {
tableId: tblActor.id,
linkId: getColumnId(columnsActor, 'Films'),
rowId: 1,
},
query: {
offset: 0,
limit: 10,
},
status: 200,
};
await nestedListTests(validParams);
}); });
} }

Loading…
Cancel
Save