Skip to content

Commit

Permalink
Merge pull request #5172 from novuhq/nv-3475-typeerror-cannot-create-…
Browse files Browse the repository at this point in the history
…property-buttons-on-string

Nv 3475 - typeerror cannot create property buttons on string
  • Loading branch information
LetItRock authored Feb 9, 2024
2 parents d6cb908 + aa341b7 commit dd09d68
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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

0 comments on commit dd09d68

Please sign in to comment.