From a3ef1b15fa09bfb573a636fccf5109943d6c694d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=B6derberg?= Date: Thu, 14 Sep 2023 13:03:46 +0200 Subject: [PATCH] feat: adding api tests for digest and delay filters --- .../src/app/events/e2e/trigger-event.e2e.ts | 323 ++++++++++++++++++ 1 file changed, 323 insertions(+) diff --git a/apps/api/src/app/events/e2e/trigger-event.e2e.ts b/apps/api/src/app/events/e2e/trigger-event.e2e.ts index 9fcc3c6e593..64f6641a924 100644 --- a/apps/api/src/app/events/e2e/trigger-event.e2e.ts +++ b/apps/api/src/app/events/e2e/trigger-event.e2e.ts @@ -35,6 +35,7 @@ import { } from '@novu/shared'; import { EmailEventStatusEnum } from '@novu/stateless'; import { createTenant } from '../../tenant/e2e/create-tenant.e2e'; +import { DetailEnum } from '@novu/application-generic'; const axiosInstance = axios.create(); @@ -66,6 +67,328 @@ describe(`Trigger event - ${eventTriggerPath} (POST)`, function () { subscriber = await subscriberService.createSubscriber(); }); + it('should filter delay step', async function () { + const firstStepUuid = uuid(); + template = await session.createTemplate({ + steps: [ + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + uuid: firstStepUuid, + }, + { + type: StepTypeEnum.DELAY, + content: '', + metadata: { + unit: DigestUnitEnum.SECONDS, + amount: 1, + type: DelayTypeEnum.REGULAR, + }, + filters: [ + { + isNegated: false, + type: 'GROUP', + value: 'AND', + children: [ + { + on: FilterPartTypeEnum.PAYLOAD, + operator: 'IS_DEFINED', + field: 'exclude', + value: '', + }, + ], + }, + ], + }, + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + }, + ], + }); + + await axiosInstance.post( + `${session.serverUrl}${eventTriggerPath}`, + { + name: template.triggers[0].identifier, + to: [subscriber.subscriberId], + payload: { + customVar: 'Testing of User Name', + }, + }, + { + headers: { + authorization: `ApiKey ${session.apiKey}`, + }, + } + ); + + await session.awaitRunningJobs(template?._id, true, 0); + + const messagesAfter = await messageRepository.find({ + _environmentId: session.environment._id, + _subscriberId: subscriber._id, + channel: StepTypeEnum.EMAIL, + }); + + expect(messagesAfter.length).to.equal(2); + + const executionDetails = await executionDetailsRepository.find({ + _environmentId: session.environment._id, + _notificationTemplateId: template?._id, + channel: StepTypeEnum.DELAY, + detail: DetailEnum.FILTER_STEPS, + }); + + expect(executionDetails.length).to.equal(1); + }); + + it('should filter digest step', async function () { + const firstStepUuid = uuid(); + template = await session.createTemplate({ + steps: [ + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + uuid: firstStepUuid, + }, + { + type: StepTypeEnum.DIGEST, + content: '', + metadata: { + unit: DigestUnitEnum.SECONDS, + amount: 1, + type: DelayTypeEnum.REGULAR, + }, + filters: [ + { + isNegated: false, + type: 'GROUP', + value: 'AND', + children: [ + { + on: FilterPartTypeEnum.PAYLOAD, + operator: 'IS_DEFINED', + field: 'exclude', + value: '', + }, + ], + }, + ], + }, + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + }, + ], + }); + + await axiosInstance.post( + `${session.serverUrl}${eventTriggerPath}`, + { + name: template.triggers[0].identifier, + to: [subscriber.subscriberId], + payload: { + customVar: 'Testing of User Name', + }, + }, + { + headers: { + authorization: `ApiKey ${session.apiKey}`, + }, + } + ); + + await session.awaitRunningJobs(template?._id, true, 0); + + const messagesAfter = await messageRepository.find({ + _environmentId: session.environment._id, + _subscriberId: subscriber._id, + channel: StepTypeEnum.EMAIL, + }); + + expect(messagesAfter.length).to.equal(2); + + const executionDetails = await executionDetailsRepository.find({ + _environmentId: session.environment._id, + _notificationTemplateId: template?._id, + channel: StepTypeEnum.DIGEST, + detail: DetailEnum.FILTER_STEPS, + }); + + expect(executionDetails.length).to.equal(1); + }); + + it('should not filter digest step', async function () { + const firstStepUuid = uuid(); + template = await session.createTemplate({ + steps: [ + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + uuid: firstStepUuid, + }, + { + type: StepTypeEnum.DIGEST, + content: '', + metadata: { + unit: DigestUnitEnum.SECONDS, + amount: 1, + type: DelayTypeEnum.REGULAR, + }, + filters: [ + { + isNegated: false, + type: 'GROUP', + value: 'AND', + children: [ + { + on: FilterPartTypeEnum.PAYLOAD, + operator: 'IS_DEFINED', + field: 'exclude', + value: '', + }, + ], + }, + ], + }, + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + }, + ], + }); + + await axiosInstance.post( + `${session.serverUrl}${eventTriggerPath}`, + { + name: template.triggers[0].identifier, + to: [subscriber.subscriberId], + payload: { + customVar: 'Testing of User Name', + exclude: false, + }, + }, + { + headers: { + authorization: `ApiKey ${session.apiKey}`, + }, + } + ); + + await session.awaitRunningJobs(template?._id, true, 0); + + const messagesAfter = await messageRepository.find({ + _environmentId: session.environment._id, + _subscriberId: subscriber._id, + channel: StepTypeEnum.EMAIL, + }); + + expect(messagesAfter.length).to.equal(2); + + const executionDetails = await executionDetailsRepository.findOne({ + _environmentId: session.environment._id, + _notificationTemplateId: template?._id, + channel: StepTypeEnum.DIGEST, + detail: DetailEnum.FILTER_STEPS, + }); + + expect(executionDetails).to.not.be.ok; + }); + + it('should not filter delay step', async function () { + const firstStepUuid = uuid(); + template = await session.createTemplate({ + steps: [ + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + uuid: firstStepUuid, + }, + { + type: StepTypeEnum.DELAY, + content: '', + metadata: { + unit: DigestUnitEnum.SECONDS, + amount: 1, + type: DelayTypeEnum.REGULAR, + }, + filters: [ + { + isNegated: false, + type: 'GROUP', + value: 'AND', + children: [ + { + on: FilterPartTypeEnum.PAYLOAD, + operator: 'IS_DEFINED', + field: 'exclude', + value: '', + }, + ], + }, + ], + }, + { + type: StepTypeEnum.EMAIL, + name: 'Message Name', + subject: 'Test email subject', + content: [{ type: EmailBlockTypeEnum.TEXT, content: 'This is a sample text block' }], + }, + ], + }); + + await axiosInstance.post( + `${session.serverUrl}${eventTriggerPath}`, + { + name: template.triggers[0].identifier, + to: [subscriber.subscriberId], + payload: { + customVar: 'Testing of User Name', + exclude: false, + }, + }, + { + headers: { + authorization: `ApiKey ${session.apiKey}`, + }, + } + ); + + await session.awaitRunningJobs(template?._id, true, 0); + + const messagesAfter = await messageRepository.find({ + _environmentId: session.environment._id, + _subscriberId: subscriber._id, + channel: StepTypeEnum.EMAIL, + }); + + expect(messagesAfter.length).to.equal(2); + + const executionDetails = await executionDetailsRepository.findOne({ + _environmentId: session.environment._id, + _notificationTemplateId: template?._id, + channel: StepTypeEnum.DELAY, + detail: DetailEnum.FILTER_STEPS, + }); + + expect(executionDetails).to.not.be.ok; + }); + it('should use conditions to select integration', async function () { const payload = { providerId: EmailProviderIdEnum.Mailgun,