Skip to content

Commit

Permalink
chore: Handle boolean type variables
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Dec 20, 2023
1 parent ae83040 commit 9286747
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@chatwoot/utils",
"version": "0.0.19",
"version": "0.0.20",
"description": "Chatwoot utils",
"private": false,
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/canned.ts
Expand Up @@ -111,6 +111,6 @@ export const getUndefinedVariablesInMessage = ({
.trim();
})
.filter(variable => {
return !variables[variable];
return variables[variable] === undefined;
});
};
2 changes: 1 addition & 1 deletion src/types/conversation.ts
Expand Up @@ -33,7 +33,7 @@ export interface Assignee {
}

export interface Variables {
[key: string]: string | number;
[key: string]: string | number| boolean
}

export interface CustomAttributes {
Expand Down
5 changes: 3 additions & 2 deletions test/canned.test.ts
Expand Up @@ -17,6 +17,7 @@ const variables = {
'agent.first_name': 'Samuel',
'agent.last_name': 'Smith',
'agent.email': 'samuel@gmail.com',
'contact.custom_attribute.cloud_customer': false,
};

describe('#replaceVariablesInMessage', () => {
Expand Down Expand Up @@ -135,12 +136,12 @@ describe('#getMessageVariables', () => {

describe('#getUndefinedVariablesInMessage', () => {
it('returns the undefined variables', () => {
const message = 'Please dm me at {{contact.twitter}}';
const message = 'It seems like you are facing issues with {{contact.integration}}, the cloud customer is {{contact.custom_attribute.cloud_customer}}';
expect(
getUndefinedVariablesInMessage({ message, variables }).length
).toEqual(1);
expect(getUndefinedVariablesInMessage({ message, variables })).toEqual(
expect.arrayContaining(['contact.twitter'])
expect.arrayContaining(['contact.integration'])
);
});
it('skip variables in string with code blocks', () => {
Expand Down

0 comments on commit 9286747

Please sign in to comment.