Skip to content

Commit

Permalink
feat: now you can add env type to env order (#8442)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Oct 14, 2024
1 parent a3dd517 commit 735e6f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/lib/services/email-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,28 @@ test('Can send order environments email', async () => {
} as unknown as IUnleashConfig);

const customerId = 'customer133';
const environments = ['development', 'production'];
const environments = [
{ name: 'test', type: 'development' },
{ name: 'live', type: 'production' },
];

const content = await emailService.sendOrderEnvironmentEmail(
'[email protected]',
customerId,
environments,
);
expect(content.from).toBe('[email protected]');
expect(content.subject).toBe('Unleash - ordered environments successfully');
expect(content.html.includes(`<li>${environments[0]}</li>`)).toBe(true);
expect(content.html.includes(`<li>${environments[1]}</li>`)).toBe(true);
expect(
content.html.includes(
`<li>Name: ${environments[0].name}, Type: ${environments[0].type}</li>`,
),
).toBe(true);
expect(
content.html.includes(
`<li>Name: ${environments[1].name}, Type: ${environments[1].type}</li>`,
),
).toBe(true);
expect(content.html.includes(customerId)).toBe(true);
expect(content.bcc).toBe('[email protected]');
});
15 changes: 11 additions & 4 deletions src/lib/services/email-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export type ChangeRequestScheduleConflictData =
environment: string;
};

export type OrderEnvironmentData = {
name: string;
type: string;
};

export class EmailService {
private logger: Logger;
private config: IUnleashConfig;
Expand Down Expand Up @@ -453,16 +458,18 @@ export class EmailService {
async sendOrderEnvironmentEmail(
userEmail: string,
customerId: string,
environmentNames: string[],
environments: OrderEnvironmentData[],
): Promise<IEmailEnvelope> {
if (this.configured()) {
const context = {
userEmail,
customerId,
environments: environmentNames.map((name) =>
this.stripSpecialCharacters(name),
),
environments: environments.map((data) => ({
name: this.stripSpecialCharacters(data.name),
type: this.stripSpecialCharacters(data.type),
})),
};

const bodyHtml = await this.compileTemplate(
'order-environments',
TemplateFormat.HTML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
<p>An order for additional environments has been successfully submitted by <strong>{{{ userEmail }}}</strong> for customer ID <strong>{{{ customerId }}}</strong>. Below are the details of the environments requested:</p>
<ul>
{{#environments}}
<li>{{.}}</li>
<li>Name: {{name}}, Type: {{type}}</li>
{{/environments}}
</ul>
<p>Please note that it may take up to 24 hours for these changes to come into effect.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Hello,
An order for additional environments has been successfully submitted by {{ userEmail }} for customer ID {{ customerId }}. Below are the details of the environments requested:

{{#environments}}
- {{.}}
- Name: {{name}}, Type: {{type}}
{{/environments}}

Please note that it may take up to 24 hours for these changes to come into effect.
Expand Down

0 comments on commit 735e6f0

Please sign in to comment.