Skip to content

Commit

Permalink
Merge pull request #4648 from novuhq/nv-3074-tidy-up-filters-operator…
Browse files Browse the repository at this point in the history
…-for-reusability

feat(shared): tidy up filters operators to reuse in events broadcast
  • Loading branch information
Pablo Fernández authored Oct 25, 2023
2 parents 11a4779 + ce525a5 commit 990542e
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 220 deletions.
13 changes: 10 additions & 3 deletions apps/api/src/app/blueprint/e2e/get-grouped-blueprints.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import * as sinon from 'sinon';

import { UserSession } from '@novu/testing';
import { NotificationTemplateRepository, EnvironmentRepository } from '@novu/dal';
import { EmailBlockTypeEnum, FilterPartTypeEnum, INotificationTemplate, StepTypeEnum } from '@novu/shared';
import {
EmailBlockTypeEnum,
FieldLogicalOperatorEnum,
FieldOperatorEnum,
FilterPartTypeEnum,
INotificationTemplate,
StepTypeEnum,
} from '@novu/shared';
import {
buildGroupedBlueprintsKey,
CacheService,
Expand Down Expand Up @@ -177,13 +184,13 @@ export async function createTemplateFromBlueprint({
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down
12 changes: 9 additions & 3 deletions apps/api/src/app/change/e2e/get-changes.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { expect } from 'chai';
import { ChangeRepository } from '@novu/dal';
import { EmailBlockTypeEnum, StepTypeEnum, FilterPartTypeEnum } from '@novu/shared';
import {
EmailBlockTypeEnum,
StepTypeEnum,
FilterPartTypeEnum,
FieldLogicalOperatorEnum,
FieldOperatorEnum,
} from '@novu/shared';
import { UserSession } from '@novu/testing';

import { CreateWorkflowRequestDto, UpdateWorkflowRequestDto } from '../../workflows/dto';
Expand Down Expand Up @@ -32,13 +38,13 @@ describe('Get changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down
54 changes: 31 additions & 23 deletions apps/api/src/app/change/e2e/promote-changes.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
ChangeEntityTypeEnum,
ChannelCTATypeEnum,
EmailBlockTypeEnum,
FieldLogicalOperatorEnum,
FieldOperatorEnum,
StepTypeEnum,
FilterPartTypeEnum,
TemplateVariableTypeEnum,
Expand Down Expand Up @@ -69,13 +71,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand All @@ -96,7 +98,7 @@ describe('Promote changes', () => {
_parentId: notificationTemplateId,
});

expect(prodVersion._notificationGroupId).to.eq(prodGroup._id);
expect(prodVersion?._notificationGroupId).to.eq(prodGroup._id);
});

it('should promote step variables default values', async () => {
Expand Down Expand Up @@ -204,13 +206,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -242,7 +244,7 @@ describe('Promote changes', () => {
_parentId: notificationTemplateId,
} as any);

expect(prodVersion.steps.length).to.eq(0);
expect(prodVersion?.steps.length).to.eq(0);
});

it('update active flag on notification template', async () => {
Expand Down Expand Up @@ -274,7 +276,7 @@ describe('Promote changes', () => {
_parentId: notificationTemplateId,
});

expect(prodVersion.active).to.eq(true);
expect(prodVersion?.active).to.eq(true);
});

it('update existing message', async () => {
Expand All @@ -295,13 +297,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -352,7 +354,7 @@ describe('Promote changes', () => {
_parentId: step._templateId,
});

expect(prodVersion.name).to.eq('test');
expect(prodVersion?.name).to.eq('test');
});

it('add one more message', async () => {
Expand All @@ -373,13 +375,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -431,13 +433,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'secondName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -479,13 +481,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -521,13 +523,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand Down Expand Up @@ -632,13 +634,13 @@ describe('Promote changes', () => {
{
isNegated: false,
type: 'GROUP',
value: 'AND',
value: FieldLogicalOperatorEnum.AND,
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
operator: FieldOperatorEnum.EQUAL,
},
],
},
Expand All @@ -659,7 +661,7 @@ describe('Promote changes', () => {
_parentId: notificationTemplateId,
});

expect(prodVersion.isBlueprint).to.equal(true);
expect(prodVersion?.isBlueprint).to.equal(true);
});

it('should merge creation, and status changes to one change', async () => {
Expand Down Expand Up @@ -724,9 +726,15 @@ describe('Promote changes', () => {
});
});

async function getProductionEnvironment() {
return await environmentRepository.findOne({
async function getProductionEnvironment(): Promise<EnvironmentEntity> {
const production = await environmentRepository.findOne({
_parentId: session.environment._id,
});

if (!production) {
throw new Error('No production environment');
}

return production;
}
});
Loading

1 comment on commit 990542e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.