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

fix: so empty string can not be used as default value #2757

Merged
merged 3 commits into from
Feb 14, 2023

Conversation

davidsoderberg
Copy link
Contributor

What change does this PR introduce?

so empty string can not be used as default value

Why was this change needed?

To be more logical with how we handle default values

@linear
Copy link

linear bot commented Feb 14, 2023

NV-1598 🐛 Bug Report: Template variables are given a default empty string value even when nothing is entered in the default value form

📜 Description

When creating a template, even when you do not set a default variable, the value is set to an empty string.

👟 Reproduction steps

Create a template and use a variable named testVar but do not enter a default value. Send testVar in your payload as null or undefined.

👍 Expected behavior

Novu should not overwrite with an empty string if there is no default value set.

👎 Actual Behavior with Screenshots

Note that when inspecting the "payload" in the activity feed Novu will have sent an empty string as a default value for testVar.

You can also check by getting the template from the API and seeing this in the variables:

            {
              "name": "testVar",
              "type": "String",
              "required": false,
              "defaultValue": "",
              "_id": "63d5ccb3a9b6cc61d4cdce39"
            },```

### 📃 Provide any additional context for the Bug.

_No response_

### 👀 Have you spent some time to check if this bug has been raised before?

- [X] I checked and didn't find similar issue

### 🏢 Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/novuhq/novu/blob/main/CONTRIBUTING.md)

### Are you willing to submit PR?

None

Copy link
Contributor

@scopsy scopsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, Is it possible to add a test for this functionality?

Copy link
Contributor

@p-fernandez p-fernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟

@davidsoderberg davidsoderberg added this pull request to the merge queue Feb 14, 2023
Merged via the queue into next with commit 31f35ba Feb 14, 2023
@davidsoderberg davidsoderberg deleted the nv-1598-bug-report-template-variables-are-given branch February 14, 2023 12:26
Comment on lines +68 to +69
expect(result.variables?.length).to.eql(1);
expect(result.variables?.at(0)?.defaultValue).to.eql('test');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the message be created with the variable even if the default value is false? And we just shouldn't override the sent message with this information?

Because this variable is still was used in the template (if that's the usage of the variables array)

And only during trigger we should filter out to not override it with a string. Or maybe I'm missing something @davidsoderberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants