diff --git a/.idea/runConfigurations/_template__of_mocha_javascript_test_runner.xml b/.idea/runConfigurations/_template__of_mocha_javascript_test_runner.xml
index a1c4872b604..3feb4656ed2 100644
--- a/.idea/runConfigurations/_template__of_mocha_javascript_test_runner.xml
+++ b/.idea/runConfigurations/_template__of_mocha_javascript_test_runner.xml
@@ -8,6 +8,7 @@
+
--timeout 30000 --require ts-node/register --exit --file e2e/setup.ts
diff --git a/apps/api/src/app/testing/echo/echo-sync.e2e-ee.ts b/apps/api/src/app/testing/echo/echo-sync.e2e-ee.ts
new file mode 100644
index 00000000000..87322d34721
--- /dev/null
+++ b/apps/api/src/app/testing/echo/echo-sync.e2e-ee.ts
@@ -0,0 +1,162 @@
+import { UserSession } from '@novu/testing';
+import { expect } from 'chai';
+import { EnvironmentRepository, NotificationTemplateRepository } from '@novu/dal';
+import { StepTypeEnum } from '@novu/shared';
+
+describe('Echo Sync - /echo/sync (POST)', async () => {
+ let session: UserSession;
+ const environmentRepository = new EnvironmentRepository();
+ const workflowsRepository = new NotificationTemplateRepository();
+ beforeEach(async () => {
+ session = new UserSession();
+ await session.initialize();
+ });
+
+ it('should update echo url', async () => {
+ const result = await session.testAgent.post(`/v1/echo/sync`).send({
+ chimeraUrl: 'https://chimera.novu.com',
+ workflows: [],
+ });
+
+ expect(result.body.data?.length).to.equal(0);
+
+ const environment = await environmentRepository.findOne({ _id: session.environment._id });
+
+ expect(environment?.echo.url).to.equal('https://chimera.novu.com');
+
+ const workflows = await workflowsRepository.find({ _environmentId: session.environment._id });
+ expect(workflows.length).to.equal(0);
+ });
+
+ it('should create a workflow', async () => {
+ const result = await session.testAgent.post(`/v1/echo/sync`).send({
+ chimeraUrl: 'https://chimera.novu.com',
+ workflows: [
+ {
+ workflowId: 'test-workflow',
+ steps: [
+ {
+ stepId: 'send-email',
+ type: StepTypeEnum.EMAIL,
+ inputs: {},
+ outputs: {},
+ options: {},
+ code: 'testCode',
+ },
+ ],
+ code: 'testCode',
+ inputs: {},
+ options: {},
+ },
+ ],
+ });
+ expect(result.body.data?.length).to.equal(1);
+
+ const workflows = await workflowsRepository.find({ _environmentId: session.environment._id });
+ expect(workflows.length).to.equal(1);
+
+ const workflow = workflows[0];
+
+ expect(workflow.name).to.equal('test-workflow');
+ expect(workflow.type).to.equal('ECHO');
+ expect(workflow.rawData.workflowId).to.equal('test-workflow');
+ expect(workflow.triggers[0].identifier).to.equal('test-workflow');
+
+ expect(workflow.steps.length).to.equal(1);
+ expect(workflow.steps[0].stepId).to.equal('send-email');
+ expect(workflow.steps[0].uuid).to.equal('send-email');
+ expect(workflow.steps[0].name).to.equal('send-email');
+ });
+
+ it('should update a workflow', async () => {
+ await session.testAgent.post(`/v1/echo/sync`).send({
+ chimeraUrl: 'https://chimera.novu.com',
+ workflows: [
+ {
+ workflowId: 'test-workflow',
+ steps: [
+ {
+ stepId: 'send-email',
+ type: StepTypeEnum.EMAIL,
+ inputs: {},
+ outputs: {},
+ options: {},
+ code: 'testCode',
+ },
+ ],
+ code: 'testCode',
+ inputs: {},
+ options: {},
+ },
+ ],
+ });
+
+ await session.testAgent.post(`/v1/echo/sync`).send({
+ chimeraUrl: 'https://chimera.novu.com',
+ workflows: [
+ {
+ workflowId: 'test-workflow',
+ steps: [
+ {
+ stepId: 'send-email-2',
+ type: StepTypeEnum.EMAIL,
+ inputs: {},
+ outputs: {},
+ options: {},
+ code: 'testCode',
+ },
+ {
+ stepId: 'send-sms',
+ type: StepTypeEnum.SMS,
+ inputs: {},
+ outputs: {},
+ options: {},
+ code: 'testCode',
+ },
+ ],
+ code: 'testCode',
+ inputs: {},
+ options: {},
+ },
+ ],
+ });
+
+ const workflows = await workflowsRepository.find({ _environmentId: session.environment._id });
+ expect(workflows.length).to.equal(1);
+
+ const workflow = workflows[0];
+
+ expect(workflow.name).to.equal('test-workflow');
+ expect(workflow.type).to.equal('ECHO');
+ expect(workflow.rawData.workflowId).to.equal('test-workflow');
+ expect(workflow.triggers[0].identifier).to.equal('test-workflow');
+
+ expect(workflow.steps.length).to.equal(2);
+ expect(workflow.steps[0].stepId).to.equal('send-email-2');
+ expect(workflow.steps[0].uuid).to.equal('send-email-2');
+ /*
+ * TODO: There is an issue with the update of the name, need to verify
+ * expect(workflow.steps[0].name).to.equal('send-email-2');
+ */
+
+ expect(workflow.steps[1].stepId).to.equal('send-sms');
+ expect(workflow.steps[1].uuid).to.equal('send-sms');
+
+ await session.testAgent.post(`/v1/echo/sync`).send({
+ chimeraUrl: 'https://chimera.novu.com',
+ workflows: [
+ {
+ workflowId: 'test-workflow',
+ steps: [],
+ code: 'testCode',
+ inputs: {},
+ options: {},
+ },
+ ],
+ });
+
+ const updatedWorkflows = await workflowsRepository.find({ _environmentId: session.environment._id });
+ const updatedWorkflow = updatedWorkflows[0];
+ expect(updatedWorkflow.steps.length).to.equal(0);
+ });
+});
diff --git a/apps/api/src/config/cors.ts b/apps/api/src/config/cors.ts
index 0ff6af7cea6..434bd422c11 100644
--- a/apps/api/src/config/cors.ts
+++ b/apps/api/src/config/cors.ts
@@ -1,4 +1,4 @@
-import { INestApplication, Request } from '@nestjs/common';
+import { INestApplication, Logger } from '@nestjs/common';
import { HttpRequestHeaderKeysEnum } from '../app/shared/framework/types';
export const corsOptionsDelegate: Parameters[0] = function (req: Request, callback) {
@@ -25,7 +25,14 @@ export const corsOptionsDelegate: Parameters[0]
process.env.NODE_ENV === 'dev' &&
host.includes(process.env.PR_PREVIEW_ROOT_URL);
+ Logger.verbose(`Should allow deploy preview? ${shouldDisableCorsForPreviewUrls ? 'Yes' : 'No'}.`, {
+ curEnv: process.env.NODE_ENV,
+ previewUrlRoot: process.env.PR_PREVIEW_ROOT_URL,
+ host,
+ });
+
if (shouldDisableCorsForPreviewUrls) {
+ Logger.verbose(`Allowing deploy previews.`);
corsOptions.origin.push('*');
}
}