Browse Source

test: many-many list/add/remove

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

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

@ -207,7 +207,7 @@ async function ncAxiosLinkGet({
async function ncAxiosLinkAdd({ async function ncAxiosLinkAdd({
urlParams: { tableId, linkId, rowId }, urlParams: { tableId, linkId, rowId },
body = {}, body = {},
status = 200, status = 201,
}: { urlParams?: any; body?: any; status?: number } = {}) { }: { urlParams?: any; body?: any; status?: number } = {}) {
const urlParams = { tableId, linkId, rowId }; const urlParams = { tableId, linkId, rowId };
const url = `/api/v1/tables/${urlParams.tableId}/links/${urlParams.linkId}/rows/${urlParams.rowId}`; const url = `/api/v1/tables/${urlParams.tableId}/links/${urlParams.linkId}/rows/${urlParams.rowId}`;
@ -2000,7 +2000,7 @@ function linkBased() {
await ncAxiosLinkAdd({ await ncAxiosLinkAdd({
urlParams: { urlParams: {
tableId: tblFilm.id, tableId: tblFilm.id,
linkId: getColumnId(columnsFilm, 'Actor'), linkId: getColumnId(columnsFilm, 'Actor List'),
rowId: 1, rowId: 1,
}, },
body: initializeArrayFromSequence(1, 20), body: initializeArrayFromSequence(1, 20),
@ -2014,21 +2014,55 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
}); });
expect(rsp.body).to.deep.equal({
links: initializeArrayFromSequence(1, 20), // page info
const pageInfo = {
totalRows: 20,
page: 1,
pageSize: 25,
isFirstPage: true,
isLastPage: true,
};
expect(rsp.body.pageInfo).to.deep.equal(pageInfo);
// Links
expect(rsp.body.list.length).to.equal(20);
for (let i = 1; i <= 20; i++) {
expect(rsp.body.list[i - 1]).to.deep.equal({
Id: i,
Film: `Film ${i}`,
});
}
// Second record
rsp = await ncAxiosLinkGet({
urlParams: {
tableId: tblActor.id,
linkId: getColumnId(columnsActor, 'Films'),
rowId: 2,
},
});
expect(rsp.body.list.length).to.equal(1);
expect(rsp.body.list[0]).to.deep.equal({
Id: 1,
Film: `Film 1`,
}); });
// verify in Film table // verify in Film table
rsp = await ncAxiosLinkGet({ rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
tableId: tblFilm.id, tableId: tblFilm.id,
linkId: getColumnId(columnsFilm, 'Actor'), linkId: getColumnId(columnsFilm, 'Actor List'),
rowId: 1, rowId: 1,
}, },
}); });
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(20);
links: initializeArrayFromSequence(1, 20), for (let i = 1; i <= 20; i++) {
}); expect(rsp.body.list[i - 1]).to.deep.equal({
Id: i,
Actor: `Actor ${i}`,
});
}
// Update mm link between Actor and Film // Update mm link between Actor and Film
// List them for a record & verify in both tables // List them for a record & verify in both tables
@ -2038,7 +2072,7 @@ function linkBased() {
linkId: getColumnId(columnsActor, 'Films'), linkId: getColumnId(columnsActor, 'Films'),
rowId: 1, rowId: 1,
}, },
body: initializeArrayFromSequence(21, 30), body: initializeArrayFromSequence(21, 10),
}); });
// verify in Actor table // verify in Actor table
@ -2049,21 +2083,28 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
}); });
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(25);
links: initializeArrayFromSequence(1, 30), // paginated response, limit to 25
}); for (let i = 1; i <= 25; i++) {
expect(rsp.body.list[i - 1]).to.deep.equal({
Id: i,
Film: `Film ${i}`,
});
}
// verify in Film table // verify in Film table
for (let i = 21; i <= 30; i++) { for (let i = 21; i <= 30; i++) {
const rsp = await ncAxiosLinkGet({ const rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
tableId: tblFilm.id, tableId: tblFilm.id,
linkId: getColumnId(columnsFilm, 'Actor'), linkId: getColumnId(columnsFilm, 'Actor List'),
rowId: i, rowId: i,
}, },
}); });
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(1);
links: initializeArrayFromSequence(1, 1), expect(rsp.body.list[0]).to.deep.equal({
Id: 1,
Actor: `Actor 1`,
}); });
} }
@ -2086,27 +2127,31 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
}); });
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(15);
links: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30], for (let i = 2; i <= 30; i += 2) {
}); expect(rsp.body.list[i / 2 - 1]).to.deep.equal({
Id: i,
Film: `Film ${i}`,
});
}
// verify in Film table // verify in Film table
for (let i = 2; i <= 30; i++) { for (let i = 2; i <= 30; i++) {
const rsp = await ncAxiosLinkGet({ const rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
tableId: tblFilm.id, tableId: tblFilm.id,
linkId: getColumnId(columnsFilm, 'Actor'), linkId: getColumnId(columnsFilm, 'Actor List'),
rowId: i, rowId: i,
}, },
}); });
if (i % 2 === 0) { if (i % 2 === 0) {
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(1);
links: [1], expect(rsp.body.list[0]).to.deep.equal({
Id: 1,
Actor: `Actor 1`,
}); });
} else { } else {
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(0);
links: [],
});
} }
} }
}); });
@ -2142,7 +2187,12 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
}); });
expect(rsp.body).to.deep.equal({ links: [1] }); let subResponse = rsp.body.list.map(({ Id, City }) => ({ Id, City }));
expect(subResponse.length).to.equal(1);
expect(subResponse[0]).to.deep.equal({
Id: 1,
City: 'City 1',
});
rsp = await ncAxiosLinkGet({ rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
@ -2151,7 +2201,14 @@ function linkBased() {
rowId: 2, rowId: 2,
}, },
}); });
expect(rsp.body).to.deep.equal({ links: [2, 3] }); expect(rsp.body.list.length).to.equal(2);
subResponse = rsp.body.list.map(({ Id, City }) => ({ Id, City }));
for (let i = 2; i <= 3; i++) {
expect(subResponse[i - 2]).to.deep.equal({
Id: i,
City: `City ${i}`,
});
}
}); });
// limit & offset verification // limit & offset verification
@ -2178,9 +2235,14 @@ function linkBased() {
offset: 0, offset: 0,
}, },
}); });
expect(rsp.body).to.deep.equal({ expect(rsp.body.list.length).to.equal(10);
links: initializeArrayFromSequence(1, 10), let subResponse = rsp.body.list.map(({ Id, City }) => ({ Id, City }));
}); for (let i = 1; i <= 10; i++) {
expect(subResponse[i - 1]).to.deep.equal({
Id: i,
City: `City ${i}`,
});
}
rsp = await ncAxiosLinkGet({ rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
@ -2193,9 +2255,14 @@ function linkBased() {
offset: 10, offset: 10,
}, },
}); });
expect(rsp.body).to.deep.equal({ subResponse = rsp.body.list.map(({ Id, City }) => ({ Id, City }));
links: initializeArrayFromSequence(11, 20), expect(subResponse.length).to.equal(10);
}); for (let i = 11; i <= 20; i++) {
expect(subResponse[i - 11]).to.deep.equal({
Id: i,
City: `City ${i}`,
});
}
rsp = await ncAxiosLinkGet({ rsp = await ncAxiosLinkGet({
urlParams: { urlParams: {
@ -2204,13 +2271,18 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
query: { query: {
limit: 10, limit: 100,
offset: 40, offset: 40,
}, },
}); });
expect(rsp.body).to.deep.equal({ subResponse = rsp.body.list.map(({ Id, City }) => ({ Id, City }));
links: initializeArrayFromSequence(41, 50), expect(subResponse.length).to.equal(10);
}); for (let i = 41; i <= 50; i++) {
expect(subResponse[i - 41]).to.deep.equal({
Id: i,
City: `City ${i}`,
});
}
}); });
// invalid link id // invalid link id
@ -2223,11 +2295,11 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
body: [9999], body: [9999],
status: 400, status: 404,
}); });
// Invalid link field ID // Invalid link field ID
const rsp = await ncAxiosLinkGet({ await ncAxiosLinkGet({
urlParams: { urlParams: {
tableId: tblCountry.id, tableId: tblCountry.id,
linkId: 9999, linkId: 9999,
@ -2235,7 +2307,6 @@ function linkBased() {
}, },
status: 400, status: 400,
}); });
expect(rsp.body).to.deep.equal({ links: [] });
// Link Remove: Invalid link ID // Link Remove: Invalid link ID
await ncAxiosLinkRemove({ await ncAxiosLinkRemove({
@ -2245,7 +2316,7 @@ function linkBased() {
rowId: 1, rowId: 1,
}, },
body: [9999], body: [9999],
status: 400, status: 404,
}); });
}); });
} }

Loading…
Cancel
Save