Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into nv-3519-translations-…
Browse files Browse the repository at this point in the history
…changes-not-showing-details
  • Loading branch information
ainouzgali committed Feb 28, 2024
2 parents 85b094b + df51622 commit a60cb9c
Show file tree
Hide file tree
Showing 102 changed files with 16,819 additions and 784 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@
"livemode",
"spyon",
"restapi",
"ringcentral"
"ringcentral",
"reshard"
],
"flagWords": [],
"patterns": [
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
'@typescript-eslint/lines-between-class-members': 'off',
'react/jsx-wrap-multilines': 'off',
'react/jsx-filename-extension': 'off',
'multiline-comment-style': ['error', 'starred-block'],
'multiline-comment-style': ['warn', 'starred-block'],
'promise/catch-or-return': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-web-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
echo REACT_APP_MAIL_SERVER_DOMAIN=${{ inputs.react_app_mail_server_domain }} >> .env
echo REACT_APP_LAUNCH_DARKLY_CLIENT_SIDE_ID=${{ secrets.LAUNCH_DARKLY_CLIENT_SIDE_ID }} >> .env
echo REACT_APP_HUBSPOT_EMBED=${{ inputs.react_app_hubspot_embed }} >> .env
echo REACT_APP_STRIPE_CLIENT_KEY=${{ secrets.STRIPE_CLIENT_KEY }} >> .env
- name: Envsetup
working-directory: apps/web
Expand Down
2 changes: 1 addition & 1 deletion .source
5 changes: 5 additions & 0 deletions apps/api/e2e/setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { DalService } from '@novu/dal';
import { testServer } from '@novu/testing';
import * as sinon from 'sinon';
import * as chai from 'chai';

import { bootstrap } from '../src/bootstrap';

const dalService = new DalService();

before(async () => {
/**
* disable truncating for better error messages - https://www.chaijs.com/guide/styles/#configtruncatethreshold
*/
chai.config.truncateThreshold = 0;
await testServer.create(await bootstrap());
await dalService.connect(process.env.MONGO_URL);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MessageRepository, MessageTemplateRepository } from '@novu/dal';

export async function normalizeMessageCtaAction() {
// eslint-disable-next-line no-console
console.log('start migration - normalize message cta action');

const messageRepository = new MessageRepository();
const messages = await messageRepository._model
.find({ 'cta.action': '' } as any)
.read('secondaryPreferred')
.lean();

for (const message of messages) {
// eslint-disable-next-line no-console
console.log(`message ${message._id}`);

await messageRepository.update(
{ _id: message._id, _organizationId: message._organizationId, _environmentId: message._environmentId } as any,
{
$set: { 'cta.action': {} },
}
);
// eslint-disable-next-line no-console
console.log(`message ${message._id} - cta action updated`);
}

// eslint-disable-next-line no-console
console.log('end migration');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { expect } from 'chai';
import { faker } from '@faker-js/faker';

import { UserSession } from '@novu/testing';
import { MessageRepository, MessageTemplateRepository } from '@novu/dal';
import { StepTypeEnum } from '@novu/shared';

import { normalizeMessageTemplateCtaAction } from './normalize-message-template-cta-action-migration';
import { normalizeMessageCtaAction } from './normalize-message-cta-action-migration';

describe('Normalize cta action', function () {
let session: UserSession;
const messageTemplateRepository = new MessageTemplateRepository();
const messageRepository = new MessageRepository();

beforeEach(async () => {
session = new UserSession();
await session.initialize();
});

it('normalize message template cta action', async function () {
await messageTemplateRepository.create({
_organizationId: session.organization._id,
_environmentId: session.environment._id,
_creatorId: session.user._id,
type: StepTypeEnum.IN_APP,
content: 'noise',
cta: {
action: {
buttons: [
{
title: faker.lorem.words(3),
url: faker.internet.url(),
},
],
},
},
});

await messageTemplateRepository.create({
_organizationId: session.organization._id,
_environmentId: session.environment._id,
_creatorId: session.user._id,
type: StepTypeEnum.IN_APP,
content: 'invalid action state',
cta: {
action: '',
},
});

const messages = await messageTemplateRepository.find({ 'cta.action': '' } as any);

expect(messages.length).to.equal(1);
expect(messages[0]?.cta?.action).to.equal('');
expect(messages[0]?.content).to.equal('invalid action state');

await normalizeMessageTemplateCtaAction();

const normalizedMessages = await messageTemplateRepository.find({ 'cta.action': '' } as any);

expect(normalizedMessages.length).to.equal(0);
});

it('normalize message cta action', async function () {
await messageRepository.create({
_organizationId: session.organization._id,
_environmentId: session.environment._id,
content: 'noise',
cta: {
action: {
buttons: [
{
title: faker.lorem.words(3),
url: faker.internet.url(),
},
],
},
},
});

const createdMessage = await messageRepository.create({
_organizationId: session.organization._id,
_environmentId: session.environment._id,
content: 'invalid action state',
cta: {
action: '',
},
});
await messageRepository.update(
{
_id: createdMessage._id,
_organizationId: createdMessage._organizationId,
_environmentId: createdMessage._environmentId,
} as any,
{
$set: { 'cta.action': '' },
}
);

const messages = await messageRepository.find({ 'cta.action': '' } as any);

expect(messages.length).to.equal(1);
expect(messages[0]?.cta?.action).to.equal('');
expect(messages[0]?.content).to.equal('invalid action state');

await normalizeMessageCtaAction();

const normalizedMessages = await messageRepository.find({ 'cta.action': '' } as any);

expect(normalizedMessages.length).to.equal(0);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { MessageTemplateRepository } from '@novu/dal';

export async function normalizeMessageTemplateCtaAction() {
// eslint-disable-next-line no-console
console.log('start migration - normalize message template cta action');

const messageTemplateRepository = new MessageTemplateRepository();
const messageTemplates = await messageTemplateRepository._model
.find({ 'cta.action': '' } as any)
.read('secondaryPreferred');

for (const message of messageTemplates) {
// eslint-disable-next-line no-console
console.log(`message ${message._id}`);

await messageTemplateRepository.update(
{ _id: message._id, _organizationId: message._organizationId, _environmentId: message._environmentId } as any,
{
$set: { 'cta.action': {} },
}
);
// eslint-disable-next-line no-console
console.log(`message ${message._id} - cta action updated`);
}

// eslint-disable-next-line no-console
console.log('end migration');
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class PromoteMessageTemplateChange {
content: newItem.content,
contentType: newItem.contentType,
title: newItem.title,
preheader: newItem.preheader,
senderName: newItem.senderName,
cta: newItem.cta,
active: newItem.active,
actor: newItem.actor,
Expand Down Expand Up @@ -87,6 +89,8 @@ export class PromoteMessageTemplateChange {
contentType: newItem.contentType,
title: newItem.title,
cta: newItem.cta,
preheader: newItem.preheader,
senderName: newItem.senderName,
active: newItem.active,
actor: newItem.actor,
variables: newItem.variables,
Expand Down
Loading

0 comments on commit a60cb9c

Please sign in to comment.