From ed270fc6c8e0f2ee2b3f6e3853a985d7cce2cec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tymczuk?= Date: Fri, 9 Feb 2024 18:16:54 +0100 Subject: [PATCH] Merge pull request #5172 from novuhq/nv-3475-typeerror-cannot-create-property-buttons-on-string Nv 3475 - typeerror cannot create property buttons on string --- .../create-message-template.usecase.ts | 8 ++++-- .../e2e/update-notification-template.e2e.ts | 26 +++++++++++++++++++ .../preview/InAppWidgetPreview.tsx | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/message-template/usecases/create-message-template/create-message-template.usecase.ts b/apps/api/src/app/message-template/usecases/create-message-template/create-message-template.usecase.ts index 1fb46fac7af..1f6b4cd19b1 100644 --- a/apps/api/src/app/message-template/usecases/create-message-template/create-message-template.usecase.ts +++ b/apps/api/src/app/message-template/usecases/create-message-template/create-message-template.usecase.ts @@ -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 { @@ -18,6 +18,10 @@ export class CreateMessageTemplate { ) {} async execute(command: CreateMessageTemplateCommand): Promise { + 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, diff --git a/apps/api/src/app/workflows/e2e/update-notification-template.e2e.ts b/apps/api/src/app/workflows/e2e/update-notification-template.e2e.ts index 03b9cb12a9b..bd61020d5d7 100644 --- a/apps/api/src/app/workflows/e2e/update-notification-template.e2e.ts +++ b/apps/api/src/app/workflows/e2e/update-notification-template.e2e.ts @@ -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); + }); }); diff --git a/apps/web/src/pages/templates/components/in-app-editor/preview/InAppWidgetPreview.tsx b/apps/web/src/pages/templates/components/in-app-editor/preview/InAppWidgetPreview.tsx index 287f01d043f..465592b4672 100644 --- a/apps/web/src/pages/templates/components/in-app-editor/preview/InAppWidgetPreview.tsx +++ b/apps/web/src/pages/templates/components/in-app-editor/preview/InAppWidgetPreview.tsx @@ -41,7 +41,7 @@ export function InAppWidgetPreview({ function onRemoveTemplate() { setIsButtonsTemplateSelected(false); - onChange(''); + onChange({}); } const editableContent = (