Skip to content

Commit

Permalink
feat: adding api tests for digest and delay filters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsoderberg committed Sep 14, 2023
1 parent 2fb6d29 commit a3ef1b1
Showing 1 changed file with 323 additions and 0 deletions.
323 changes: 323 additions & 0 deletions apps/api/src/app/events/e2e/trigger-event.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a3ef1b1

Please sign in to comment.