diff --git a/tests/playwright/pages/Dashboard/WebhookForm/index.ts b/tests/playwright/pages/Dashboard/WebhookForm/index.ts index 232a1a90c9..5df5bc7960 100644 --- a/tests/playwright/pages/Dashboard/WebhookForm/index.ts +++ b/tests/playwright/pages/Dashboard/WebhookForm/index.ts @@ -93,6 +93,15 @@ export class WebhookFormPage extends BasePage { } } + async toggleIncludeUser({ save }: { save: boolean }) { + await this.get().locator(`.nc-check-box-include-user`).click(); + + if (save) { + await this.save(); + await this.close(); + } + } + async deleteCondition(p: { save: boolean }) { await this.get().locator(`.nc-filter-item-remove-btn`).click(); if (p.save) { diff --git a/tests/playwright/tests/db/features/webhook.spec.ts b/tests/playwright/tests/db/features/webhook.spec.ts index aa2c3c0c4a..961c61ca7f 100644 --- a/tests/playwright/tests/db/features/webhook.spec.ts +++ b/tests/playwright/tests/db/features/webhook.spec.ts @@ -836,4 +836,86 @@ test.describe.serial('Webhook', () => { await verifyDeleteOperation(rsp, 'records.after.bulkDelete', 2); }); + + test('Include user option', async ({ request }) => { + await clearServerData({ request }); + await dashboard.treeView.createTable({ title: 'Test', baseTitle: context.base.title }); + + // Test webhook without include_user option (default) + await webhook.create({ + title: 'hook-without-user', + event: 'On Record Insert', + }); + + await clearServerData({ request }); + await dashboard.grid.addNewRow({ + index: 0, + columnHeader: 'Title', + value: 'Test Record', + }); + + let rsp = await getWebhookResponses({ request, count: 1 }); + + // Verify webhook response doesn't include user information + expect(rsp[0].type).toBe('records.after.insert'); + expect(rsp[0].data.table_name).toBe('Test'); + expect(rsp[0].user).toBeUndefined(); + + // Create webhook with include_user option enabled + await webhook.open({ index: 0 }); + await webhook.toggleIncludeUser({ save: true }); + + await clearServerData({ request }); + await dashboard.grid.addNewRow({ + index: 1, + columnHeader: 'Title', + value: 'Test Record 2', + }); + + rsp = await getWebhookResponses({ request, count: 1 }); + + // Verify webhook response includes user information + expect(rsp[0].type).toBe('records.after.insert'); + expect(rsp[0].data.table_name).toBe('Test'); + expect(rsp[0].user).toBeDefined(); + expect(rsp[0].user).toMatchObject({ + id: expect.any(String), + email: expect.any(String), + }); + + // Test webhook without include_user option (default) + await webhook.create({ + title: 'hook-without-user-update', + event: 'On Record Update', + }); + + await clearServerData({ request }); + await dashboard.grid.editRow({ index: 1, value: 'Updated Record' }); + + rsp = await getWebhookResponses({ request, count: 1 }); + + // Verify webhook response doesn't include user information after disabling + expect(rsp[0].type).toBe('records.after.update'); + expect(rsp[0].data.table_name).toBe('Test'); + expect(rsp[0].user).toBeUndefined(); + + // Test disabling include_user option + await webhook.open({ index: 1 }); + await webhook.toggleIncludeUser({ save: true }); + + // Test with update operation + await clearServerData({ request }); + await dashboard.grid.editRow({ index: 0, value: 'Updated Record 2' }); + + rsp = await getWebhookResponses({ request, count: 1 }); + + // Verify webhook response includes user information for update + expect(rsp[0].type).toBe('records.after.update'); + expect(rsp[0].data.table_name).toBe('Test'); + expect(rsp[0].user).toBeDefined(); + expect(rsp[0].user).toMatchObject({ + id: expect.any(String), + email: expect.any(String), + }); + }); });