Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: NV-3475 #5176

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@nestjs/common';
import { MessageTemplateEntity, MessageTemplateRepository } from '@novu/dal';
import { ChangeEntityTypeEnum } from '@novu/shared';
import { ChangeEntityTypeEnum, IMessageAction } from '@novu/shared';

import { CreateMessageTemplateCommand } from './create-message-template.command';
import { sanitizeMessageContent } from '../../shared/sanitizer.service';
import { UpdateChange } from '../../../change/usecases/update-change/update-change';
import { UpdateChangeCommand } from '../../../change/usecases/update-change/update-change.command';
import { UpdateMessageTemplate } from '../update-message-template/update-message-template.usecase';
import { CreateChange, CreateChangeCommand } from '@novu/application-generic';
import { ApiException, CreateChange, CreateChangeCommand } from '@novu/application-generic';

@Injectable()
export class CreateMessageTemplate {
Expand All @@ -18,6 +18,10 @@ export class CreateMessageTemplate {
) {}

async execute(command: CreateMessageTemplateCommand): Promise<MessageTemplateEntity> {
if ((command?.cta?.action as IMessageAction | undefined | '') === '') {
throw new ApiException('Please provide a valid CTA action');
}

let item: MessageTemplateEntity = await this.messageTemplateRepository.create({
cta: command.cta,
name: command.name,
Expand Down
26 changes: 26 additions & 0 deletions apps/api/src/app/workflows/e2e/update-notification-template.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,30 @@ describe('Update workflow by id - /workflows/:workflowId (PUT)', async () => {
expect(updatedTemplate.steps[0].replyCallback?.active).to.equal(true);
expect(updatedTemplate.steps[0].replyCallback?.url).to.equal('acme-corp.com/webhook');
});

it('should not able to update step with invalid action', async function () {
const notificationTemplateService = new NotificationTemplateService(
session.user._id,
session.organization._id,
session.environment._id
);
const workflow = await notificationTemplateService.createTemplate();
const invalidAction = '';
const update: IUpdateNotificationTemplateDto = {
steps: [
{
template: {
type: StepTypeEnum.IN_APP,
cta: { action: invalidAction } as any,
content: 'This is new content for notification',
},
},
],
};

const { body } = await session.testAgent.put(`/v1/workflows/${workflow._id}`).send(update);

expect(body.message).to.equal('Please provide a valid CTA action');
expect(body.statusCode).to.equal(400);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function InAppWidgetPreview({

function onRemoveTemplate() {
setIsButtonsTemplateSelected(false);
onChange('');
onChange({});
}

const editableContent = (
Expand Down
Loading