Skip to content

Commit

Permalink
Merge branch 'next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
sagnik3788 authored Oct 2, 2023
2 parents d21da29 + 2c4f548 commit 41c424b
Show file tree
Hide file tree
Showing 104 changed files with 1,317 additions and 858 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/prod-deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "main"
- uses: ./.github/actions/setup-project

- name: build api
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/prod-deploy-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "main"
- uses: ./.github/actions/setup-project

- name: build worker
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prod-deploy-ws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 80
environment: Production
needs:
- test_ws
strategy:
matrix:
name: [ 'novu/ws-ee', 'novu/ws' ]
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-api-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-inbound-mail-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
steps:
# checkout with submodules if token is provided
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-web-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ jobs:
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
id: setup-project
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/reusable-widget-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}

- uses: ./.github/actions/setup-project
id: setup-project
with:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/reusable-worker-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}

- uses: ./.github/actions/setup-project

- uses: ./.github/actions/setup-redis-cluster
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/reusable-ws-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ jobs:
echo "has_token=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: mansagroup/nrwl-nx-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ You can open a new issue with this [issue form](https://github.com/novuhq/novu/i

The project is a monorepo, meaning that it is a collection of multiple packages managed in the same repository.

To learn more about the project structure visit [https://docs.novu.co/community/monorepo-structure](https://docs.novu.co/community/monorepo-structure).

To learn more about the project structure and running the project locally, please have a look [here](https://docs.novu.co/community-support/introduction#run-novu-locally).
After cloning your fork, you will need to run the `npm run setup:project` command to install and build all dependencies.

To learn a detailed guide on running the project locally, checkout our guide on [how to run novu in local machine](https://docs.novu.co/community/run-in-local-machine).
Expand Down
18 changes: 10 additions & 8 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@novu/api",
"version": "0.19.0",
"version": "0.20.0-alpha.0",
"description": "description",
"author": "",
"private": "true",
Expand Down Expand Up @@ -38,12 +38,12 @@
"@nestjs/platform-express": "^10.2.2",
"@nestjs/swagger": "^7.1.8",
"@nestjs/terminus": "^10.0.1",
"@novu/application-generic": "^0.19.0",
"@novu/dal": "^0.19.0",
"@novu/node": "^0.19.0",
"@novu/shared": "^0.19.0",
"@novu/stateless": "^0.19.0",
"@novu/testing": "^0.19.0",
"@novu/application-generic": "^0.20.0-alpha.0",
"@novu/dal": "^0.20.0-alpha.0",
"@novu/node": "^0.20.0-alpha.0",
"@novu/shared": "^0.20.0-alpha.0",
"@novu/stateless": "^0.20.0-alpha.0",
"@novu/testing": "^0.20.0-alpha.0",
"@sendgrid/mail": "^7.6.0",
"@sentry/hub": "^7.40.0",
"@sentry/node": "^7.40.0",
Expand Down Expand Up @@ -113,7 +113,9 @@
"@novu/ee-auth": "^0.19.0"
},
"nx": {
"implicitDependencies": ["@novu/ee-auth"]
"implicitDependencies": [
"@novu/ee-auth"
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { v4 as uuid } from 'uuid';

import { SubscribersService, UserSession } from '@novu/testing';
import { SubscriberRepository, NotificationTemplateEntity } from '@novu/dal';
import { TriggerRecipients } from '@novu/shared';

import { SharedModule } from '../../../shared/shared.module';
import { EventsModule } from '../../events.module';
import { ParseEventRequestCommand } from './parse-event-request.command';
import { ParseEventRequest } from './parse-event-request.usecase';

describe('ParseEventRequest Usecase', () => {
let session: UserSession;
let subscribersService: SubscribersService;
let parseEventRequestUsecase: ParseEventRequest;
let template: NotificationTemplateEntity;

beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [SharedModule, EventsModule],
providers: [],
}).compile();

session = new UserSession();
await session.initialize();

template = await session.createTemplate();
parseEventRequestUsecase = moduleRef.get<ParseEventRequest>(ParseEventRequest);
subscribersService = new SubscribersService(session.organization._id, session.environment._id);
});

it('should throw exception when subscriber id sent as array', async () => {
const transactionId = uuid();
const subscriberId = [SubscriberRepository.createObjectId()];

const command = buildCommand(
session,
transactionId,
[{ subscriberId: subscriberId } as unknown as string],
template.triggers[0].identifier
);

try {
await parseEventRequestUsecase.execute(command);
} catch (error) {
expect(error.message).to.be.eql(
'subscriberId under property to is type array, which is not allowed please make sure all subscribers ids are strings'
);
}
});
});

const buildCommand = (
session: UserSession,
transactionId: string,
to: TriggerRecipients,
identifier: string
): ParseEventRequestCommand => {
return ParseEventRequestCommand.create({
organizationId: session.organization._id,
environmentId: session.environment._id,
to,
transactionId,
userId: session.user._id,
identifier,
payload: {},
overrides: {},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export class ParseEventRequest {
for (const subscriber of to) {
const subscriberIdExists = typeof subscriber === 'string' ? subscriber : subscriber.subscriberId;

if (Array.isArray(subscriberIdExists)) {
throw new ApiException(
'subscriberId under property to is type array, which is not allowed please make sure all subscribers ids are strings'
);
}

if (!subscriberIdExists) {
throw new ApiException(
'subscriberId under property to is not configured, please make sure all subscribers contains subscriberId property'
Expand Down
45 changes: 22 additions & 23 deletions apps/api/src/app/inbound-parse/e2e/inbound-email-parse.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,38 @@ describe('Should handle the new arrived mail', () => {
});

it('should not send webhook request with missing transactionId', async () => {
const message = await triggerEmail();

const mail = getMailData(message, false);

const getStub = sandbox.stub(axios, 'post').resolves();

await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));

sinon.assert.notCalled(getStub);
try {
const message = await triggerEmail();
const mail = getMailData(message, false);

await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));
} catch (e) {
expect(e.message).to.contains('Missing transactionId on address');
}
});

it('should not send webhook request with when domain white list', async () => {
const message = await triggerEmail(true, false);
try {
const message = await triggerEmail(true, false);

const mail = getMailData(message);
const mail = getMailData(message);

const getStub = sandbox.stub(axios, 'post').resolves();

await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));

sinon.assert.notCalled(getStub);
await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));
} catch (e) {
expect(e.message).to.equal('Domain is not in environment white list');
}
});

it('should not send webhook request when missing replay callback url', async () => {
const message = await triggerEmail(true, true, true, false);

const mail = getMailData(message);

const getStub = sandbox.stub(axios, 'post').resolves();
try {
const message = await triggerEmail(true, true, true, false);

await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));
const mail = getMailData(message);

sinon.assert.notCalled(getStub);
await inboundEmailParseUsecase.execute(InboundEmailParseCommand.create(mail));
} catch (e) {
expect(e.message).to.contains('Missing parse webhook on template');
}
});

async function triggerEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
WorkerOptions,
} from '@novu/application-generic';
import { JobTopicNameEnum } from '@novu/shared';
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';

import { InboundEmailParse } from '../usecases/inbound-email-parse/inbound-email-parse.usecase';
import { InboundEmailParseCommand } from '../usecases/inbound-email-parse/inbound-email-parse.command';

const LOG_CONTEXT = 'InboundParseQueueService';

@Injectable()
export class InboundParseQueueService {
public readonly queue: Queue;
Expand All @@ -35,6 +37,7 @@ export class InboundParseQueueService {

public getWorkerProcessor() {
return async ({ data }: { data: InboundEmailParseCommand }) => {
Logger.verbose({ data }, 'Processing the inbound parsed email', LOG_CONTEXT);
await this.emailParseUsecase.execute(InboundEmailParseCommand.create({ ...data }));
};
}
Expand Down
Loading

0 comments on commit 41c424b

Please sign in to comment.