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

feat: now you can add env type to env order #8442

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading