-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
Email template for Productivity Report #8532
Changes from all commits
68387cb
49e909f
6e645b6
c0a04eb
38bb4eb
8f042af
415bd46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,9 @@ test('Can send order environments email', async () => { | |
|
||
test('Can send productivity report email', async () => { | ||
const emailService = new EmailService({ | ||
server: { | ||
unleashUrl: 'http://localhost', | ||
}, | ||
email: { | ||
host: 'test', | ||
port: 587, | ||
|
@@ -157,15 +160,17 @@ test('Can send productivity report email', async () => { | |
getLogger: noLoggerProvider, | ||
} as unknown as IUnleashConfig); | ||
|
||
const customerId = 'customer133'; | ||
|
||
const content = await emailService.sendProductivityReportEmail( | ||
'[email protected]', | ||
customerId, | ||
'customerId', | ||
{ | ||
flagsCreated: 1, | ||
productionUpdates: 2, | ||
health: 99, | ||
}, | ||
); | ||
console.log(content); | ||
expect(content.from).toBe('[email protected]'); | ||
expect(content.subject).toBe('Unleash - productivity report'); | ||
expect( | ||
content.html.includes(`<b>Productivity report for customer133</b>`), | ||
).toBe(true); | ||
expect(content.html.includes(`Productivity Report`)).toBe(true); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,11 @@ export interface IEmailEnvelope { | |
subject: string; | ||
html: string; | ||
text: string; | ||
attachments?: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the rationale for this? what did we do before? |
||
filename: string; | ||
path: string; | ||
cid: string; | ||
}[]; | ||
} | ||
|
||
const RESET_MAIL_SUBJECT = 'Unleash - Reset your password'; | ||
|
@@ -522,32 +527,48 @@ export class EmailService { | |
} | ||
|
||
async sendProductivityReportEmail( | ||
userName: string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will be a breaking change for my enterprise PR so we need to cordinate |
||
userEmail: string, | ||
customerId: string, | ||
metrics: { | ||
Tymek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
health: number; | ||
flagsCreated: number; | ||
productionUpdates: number; | ||
}, | ||
): Promise<IEmailEnvelope> { | ||
if (this.configured()) { | ||
const context = { | ||
userName, | ||
userEmail, | ||
customerId, | ||
...metrics, | ||
unleashUrl: this.config.server.unleashUrl, | ||
}; | ||
|
||
const template = 'productivity-report'; | ||
|
||
const bodyHtml = await this.compileTemplate( | ||
'productivity-report', | ||
template, | ||
TemplateFormat.HTML, | ||
context, | ||
); | ||
const bodyText = await this.compileTemplate( | ||
'productivity-report', | ||
template, | ||
TemplateFormat.PLAIN, | ||
context, | ||
); | ||
const email = { | ||
const email: IEmailEnvelope = { | ||
from: this.sender, | ||
to: userEmail, | ||
bcc: '', | ||
subject: PRODUCTIVITY_REPORT, | ||
html: bodyHtml, | ||
text: bodyText, | ||
attachments: [ | ||
this.resolveTemplateAttachment( | ||
template, | ||
'unleash-logo.png', | ||
'unleashLogo', | ||
), | ||
], | ||
}; | ||
process.nextTick(() => { | ||
this.mailer!.sendMail(email).then( | ||
|
@@ -613,6 +634,28 @@ export class EmailService { | |
throw new NotFoundError('Could not find template'); | ||
} | ||
|
||
private resolveTemplateAttachment( | ||
templateName: string, | ||
filename: string, | ||
cid: string, | ||
): { | ||
filename: string; | ||
path: string; | ||
cid: string; | ||
} { | ||
const topPath = path.resolve(__dirname, '../../mailtemplates'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to check if everything works with base paths in sandbox There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the same as templates, but yes, we can check |
||
const attachment = path.join(topPath, templateName, filename); | ||
if (existsSync(attachment)) { | ||
return { | ||
filename, | ||
path: attachment, | ||
cid, | ||
}; | ||
} | ||
|
||
throw new NotFoundError('Could not find email attachment'); | ||
} | ||
|
||
configured(): boolean { | ||
return this.sender !== 'not-configured' && this.mailer !== undefined; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what else did we copy before?