Skip to content

Commit

Permalink
Merge pull request #708 from tsa321/mention_extras_fields
Browse files Browse the repository at this point in the history
Modify mention user and mention report extras field names in ExpensiMark htmlToText and htmlToMarkdown rules
  • Loading branch information
luacmartins authored May 28, 2024
2 parents c5ad053 + 0cf9492 commit ea61a12
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions __tests__/ExpensiMark-HTMLToText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test('Mention user html to text', () => {
expect(parser.htmlToText(testString)).toBe('@Hidden');

const extras = {
accountIdToName: {
accountIDToName: {
'1234': '[email protected]',
},
};
Expand Down Expand Up @@ -180,7 +180,7 @@ test('Mention report html to text', () => {
expect(parser.htmlToText(testString)).toBe('#Hidden');

const extras = {
reportIdToName: {
reportIDToName: {
'1234': '#room-name',
},
};
Expand Down
4 changes: 2 additions & 2 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ test('Mention user html to markdown', () => {
expect(parser.htmlToMarkdown(testString)).toBe('@Hidden');

const extras = {
accountIdToName: {
accountIDToName: {
'1234': '[email protected]',
},
};
Expand Down Expand Up @@ -794,7 +794,7 @@ test('Mention report html to markdown', () => {
expect(parser.htmlToText(testString)).toBe('#Hidden');

const extras = {
reportIdToName: {
reportIDToName: {
'1234': '#room-name',
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare type Rule = {
};

declare type ExtrasObject = {
reportIdToName?: Record<string, string>;
reportIDToName?: Record<string, string>;
accountIDToName?: Record<string, string>;
};
export default class ExpensiMark {
Expand Down
13 changes: 6 additions & 7 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export default class ExpensiMark {
name: 'reportMentions',
regex: /<mention-report reportID="(\d+)" *\/>/gi,
replacement: (match, g1, offset, string, extras) => {
const reportToNameMap = extras.reportIdToName;
const reportToNameMap = extras.reportIDToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing report name', {reportID: g1});
return '#Hidden';
Expand All @@ -478,13 +478,13 @@ export default class ExpensiMark {
regex: /(?:<mention-user accountID="(\d+)" *\/>)|(?:<mention-user>(.*?)<\/mention-user>)/gi,
replacement: (match, g1, g2, offset, string, extras) => {
if (g1) {
const accountToNameMap = extras.accountIdToName;
const accountToNameMap = extras.accountIDToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
}

return `@${extras.accountIdToName[g1]}`;
return `@${extras.accountIDToName[g1]}`;
}
return Str.removeSMSDomain(g2);
},
Expand Down Expand Up @@ -536,7 +536,7 @@ export default class ExpensiMark {
name: 'reportMentions',
regex: /<mention-report reportID="(\d+)" *\/>/gi,
replacement: (match, g1, offset, string, extras) => {
const reportToNameMap = extras.reportIdToName;
const reportToNameMap = extras.reportIDToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing report name', {reportID: g1});
return '#Hidden';
Expand All @@ -549,13 +549,12 @@ export default class ExpensiMark {
name: 'userMention',
regex: /<mention-user accountID="(\d+)" *\/>/gi,
replacement: (match, g1, offset, string, extras) => {
const accountToNameMap = extras.accountIdToName;
const accountToNameMap = extras.accountIDToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
}

return `@${extras.accountIdToName[g1]}`;
return `@${extras.accountIDToName[g1]}`;
},
},
{
Expand Down

0 comments on commit ea61a12

Please sign in to comment.