Browse Source

test: webhook for bulk apis

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5349/head
Raju Udava 2 years ago
parent
commit
73b7168011
  1. 65
      tests/playwright/tests/01-webhook.spec.ts

65
tests/playwright/tests/01-webhook.spec.ts

@ -423,20 +423,30 @@ test.describe.serial('Webhook', () => {
}); });
test('Bulk operations', async ({ request, page }) => { test('Bulk operations', async ({ request, page }) => {
async function verifyBulkOperationTrigger(rsp, type, valueCounter, oldValueCounter?) { async function verifyBulkOperationTrigger(rsp, type) {
for (let i = 0; i < rsp.length; i++) { for (let i = 0; i < rsp.length; i++) {
expect(rsp[i].type === type); expect(rsp[i].type).toBe(type);
expect(rsp[i].data.table_name === 'numberBased'); expect(rsp[i].data.table_name).toBe('numberBased');
expect(rsp[i].data.view_name === 'numberBased'); expect(rsp[i].data.view_name).toBe('numberBased');
expect(rsp[i].data.rows.length === 25);
for (let j = 0; j < rsp[i].data.rows.length; j++) { // only for insert, rows inserted will not be returned in response. just count
expect(rsp[i].data.rows[j].Number === (i * 25 + j + 1) * valueCounter); if (type === 'records.after.bulkInsert') {
} expect(rsp[i].data.rows_inserted).toBe(50);
} else if (type === 'records.after.bulkUpdate') {
expect(rsp[i].data.rows.length).toBe(50);
expect(rsp[i].data.previous_rows.length).toBe(50);
// verify records
for (let j = 0; j < rsp[i].data.rows.length; j++) {
expect(rsp[i].data.rows[j].Number).toBe(111 * (j + 1));
expect(rsp[i].data.previous_rows[j].Number).toBe(100 * (j + 1) - 111);
}
} else if (type === 'records.after.bulkDelete') {
expect(rsp[i].data.rows.length).toBe(50);
if (oldValueCounter) { // verify records
expect(rsp[i].data.previous_rows.length === 25); for (let j = 0; j < rsp[i].data.rows.length; j++) {
for (let j = 0; j < rsp[i].data.previous_rows.length; j++) { expect(rsp[i].data.rows[j].Number).toBe(111 * (j + 1));
expect(rsp[i].data.previous_rows[j].Number === (i * 25 + j + 1) * oldValueCounter);
} }
} }
} }
@ -479,15 +489,15 @@ test.describe.serial('Webhook', () => {
// create after insert webhook // create after insert webhook
await webhook.create({ await webhook.create({
title: 'hook-1', title: 'hook-1',
event: 'After Insert', event: 'After Bulk Insert',
}); });
await webhook.create({ await webhook.create({
title: 'hook-1', title: 'hook-1',
event: 'After Update', event: 'After Bulk Update',
}); });
await webhook.create({ await webhook.create({
title: 'hook-1', title: 'hook-1',
event: 'After Delete', event: 'After Bulk Delete',
}); });
await clearServerData({ request }); await clearServerData({ request });
@ -498,8 +508,8 @@ test.describe.serial('Webhook', () => {
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributesForInsert); await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributesForInsert);
await page.reload(); await page.reload();
// 50 records inserted, we expect 2 webhook responses // 50 records inserted, we expect 2 webhook responses
let rsp = await getWebhookResponses({ request, count: 2 }); let rsp = await getWebhookResponses({ request, count: 1 });
await verifyBulkOperationTrigger(rsp, 'records.after.insert', 100); await verifyBulkOperationTrigger(rsp, 'records.after.bulkInsert');
// bulk update all rows // bulk update all rows
await clearServerData({ request }); await clearServerData({ request });
@ -512,8 +522,8 @@ test.describe.serial('Webhook', () => {
await api.dbTableRow.bulkUpdate('noco', context.project.id, table.id, rowAttributesForUpdate); await api.dbTableRow.bulkUpdate('noco', context.project.id, table.id, rowAttributesForUpdate);
await page.reload(); await page.reload();
// 50 records updated, we expect 2 webhook responses // 50 records updated, we expect 2 webhook responses
rsp = await getWebhookResponses({ request, count: 2 }); rsp = await getWebhookResponses({ request, count: 1 });
await verifyBulkOperationTrigger(rsp, 'records.after.update', 111, 100); await verifyBulkOperationTrigger(rsp, 'records.after.bulkUpdate');
// bulk delete all rows // bulk delete all rows
await clearServerData({ request }); await clearServerData({ request });
@ -521,8 +531,8 @@ test.describe.serial('Webhook', () => {
await api.dbTableRow.bulkDelete('noco', context.project.id, table.id, rowAttributesForDelete); await api.dbTableRow.bulkDelete('noco', context.project.id, table.id, rowAttributesForDelete);
await page.reload(); await page.reload();
rsp = await getWebhookResponses({ request, count: 2 }); rsp = await getWebhookResponses({ request, count: 1 });
await verifyBulkOperationTrigger(rsp, 'records.after.delete', 111); await verifyBulkOperationTrigger(rsp, 'records.after.bulkDelete');
}); });
test('Virtual columns', async ({ request, page }) => { test('Virtual columns', async ({ request, page }) => {
@ -655,7 +665,6 @@ test.describe.serial('Webhook', () => {
// edit first record // edit first record
await dashboard.grid.editRow({ index: 0, columnHeader: 'Country', value: 'INDIA', networkValidation: false }); await dashboard.grid.editRow({ index: 0, columnHeader: 'Country', value: 'INDIA', networkValidation: false });
const rsp = await getWebhookResponses({ request, count: 1 }); const rsp = await getWebhookResponses({ request, count: 1 });
console.log(rsp);
const expectedData = { const expectedData = {
type: 'records.after.update', type: 'records.after.update',
@ -666,8 +675,8 @@ test.describe.serial('Webhook', () => {
{ {
Id: 1, Id: 1,
Country: 'India', Country: 'India',
CountryCode: 1, CountryCode: '1',
CityCodeRollup: 2, CityCodeRollup: '2',
CityCodeFormula: 100, CityCodeFormula: 100,
CityList: [ CityList: [
{ {
@ -679,15 +688,15 @@ test.describe.serial('Webhook', () => {
City: 'Pune', City: 'Pune',
}, },
], ],
CityCodeLookup: [23, 33], CityCodeLookup: ['23', '33'],
}, },
], ],
rows: [ rows: [
{ {
Id: 1, Id: 1,
Country: 'INDIA', Country: 'INDIA',
CountryCode: 1, CountryCode: '1',
CityCodeRollup: 2, CityCodeRollup: '2',
CityCodeFormula: 100, CityCodeFormula: 100,
CityList: [ CityList: [
{ {
@ -699,7 +708,7 @@ test.describe.serial('Webhook', () => {
City: 'Pune', City: 'Pune',
}, },
], ],
CityCodeLookup: [23, 33], CityCodeLookup: ['23', '33'],
}, },
], ],
}, },

Loading…
Cancel
Save