-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/next' into nv-3519-translations-…
…changes-not-showing-details
- Loading branch information
Showing
102 changed files
with
16,819 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule .source
updated
from 22ebf8 to e4a7b1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...igrations/normalize-message-template-cta-action/normalize-message-cta-action-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
112 changes: 112 additions & 0 deletions
112
...alize-message-template-cta-action/normalize-message-template-cta-action-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
.../normalize-message-template-cta-action/normalize-message-template-cta-action-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.