diff --git a/myteamwallet_backend/src/mail/mail-config.service.ts b/myteamwallet_backend/src/mail/mail-config.service.ts index 4a6cba6..cf71903 100644 --- a/myteamwallet_backend/src/mail/mail-config.service.ts +++ b/myteamwallet_backend/src/mail/mail-config.service.ts @@ -36,6 +36,15 @@ export class MailConfigService implements MailerOptionsFactory { adapter: new HandlebarsAdapter(), options: { strict: true, + partials: { + dir: path.join( + this.configService.get('app.workingDirectory'), + 'src', + 'mail', + 'mail-templates', + 'partials', + ), + }, }, }, } as MailerOptions; diff --git a/myteamwallet_backend/src/mail/mail-templates/activation.hbs b/myteamwallet_backend/src/mail/mail-templates/activation.hbs index edee05e..b4f3c47 100644 --- a/myteamwallet_backend/src/mail/mail-templates/activation.hbs +++ b/myteamwallet_backend/src/mail/mail-templates/activation.hbs @@ -1,33 +1,8 @@ - - - - - - - {{title}} - - - - - - - - - - - - - -
- {{app_name}} -
- {{text1}}
- {{text2}} {{app_name}}.
- {{text3}} -
- {{actionTitle}} -
- - - \ No newline at end of file +{{#> layout}} +

Hallo{{#if firstName}} {{firstName}}{{/if}},

+

schön, dass du bei TeamWallet dabei bist! Bestätige deine E-Mail-Adresse, um dein Konto zu aktivieren.

+
+ {{actionTitle}} +
+

Falls der Button nicht funktioniert, kopiere diesen Link in deinen Browser:
{{url}}

+{{/layout}} \ No newline at end of file diff --git a/myteamwallet_backend/src/mail/mail-templates/mail-templates.spec.ts b/myteamwallet_backend/src/mail/mail-templates/mail-templates.spec.ts new file mode 100644 index 0000000..0caa9e1 --- /dev/null +++ b/myteamwallet_backend/src/mail/mail-templates/mail-templates.spec.ts @@ -0,0 +1,63 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import * as Handlebars from 'handlebars'; + +describe('mail templates rendering', () => { + const templatesDir = __dirname; + + beforeAll(() => { + const layoutSource = fs.readFileSync( + path.join(templatesDir, 'partials', 'layout.hbs'), + 'utf-8', + ); + Handlebars.registerPartial('layout', layoutSource); + }); + + const baseContext = { + title: 'Test-Betreff', + year: 2026, + firstName: 'Max', + url: 'https://app.example.com/confirm-email/abc123', + actionTitle: 'Jetzt bestätigen', + }; + + it('renders activation.hbs with greeting, link and button text', () => { + const source = fs.readFileSync( + path.join(templatesDir, 'activation.hbs'), + 'utf-8', + ); + const html = Handlebars.compile(source, { strict: true })(baseContext); + + expect(html).toContain('TeamWallet'); + expect(html).toContain('Hallo Max,'); + expect(html).toContain(baseContext.url); + expect(html).toContain(baseContext.actionTitle); + }); + + it('renders reset-password.hbs with greeting, link and button text', () => { + const source = fs.readFileSync( + path.join(templatesDir, 'reset-password.hbs'), + 'utf-8', + ); + const html = Handlebars.compile(source, { strict: true })(baseContext); + + expect(html).toContain('TeamWallet'); + expect(html).toContain('Hallo Max,'); + expect(html).toContain(baseContext.url); + expect(html).toContain(baseContext.actionTitle); + }); + + it('falls back to a generic greeting when firstName is missing', () => { + const source = fs.readFileSync( + path.join(templatesDir, 'activation.hbs'), + 'utf-8', + ); + const html = Handlebars.compile(source, { strict: true })({ + ...baseContext, + firstName: undefined, + }); + + expect(html).toContain('Hallo,'); + expect(html).not.toContain('Hallo Max,'); + }); +}); diff --git a/myteamwallet_backend/src/mail/mail-templates/partials/layout.hbs b/myteamwallet_backend/src/mail/mail-templates/partials/layout.hbs new file mode 100644 index 0000000..723775e --- /dev/null +++ b/myteamwallet_backend/src/mail/mail-templates/partials/layout.hbs @@ -0,0 +1,36 @@ + + + + + +{{title}} + + + +
+
+
+ TeamWallet +
+
+ {{> @partial-block }} +
+
+ +
+ + diff --git a/myteamwallet_backend/src/mail/mail-templates/reset-password.hbs b/myteamwallet_backend/src/mail/mail-templates/reset-password.hbs index 3c0e405..d66c58c 100644 --- a/myteamwallet_backend/src/mail/mail-templates/reset-password.hbs +++ b/myteamwallet_backend/src/mail/mail-templates/reset-password.hbs @@ -1,38 +1,9 @@ - - - - - - - {{title}} - - - - - - - - - - - - - - - - -
- {{app_name}} -
- {{text1}}
- {{text2}}
- {{text3}} -
- {{actionTitle}} -
- {{text4}} -
- - - \ No newline at end of file +{{#> layout}} +

Hallo{{#if firstName}} {{firstName}}{{/if}},

+

du hast angefragt, dein TeamWallet-Passwort zurückzusetzen. Klicke auf den Button, um ein neues Passwort zu vergeben.

+
+ {{actionTitle}} +
+

Falls du diese Anfrage nicht gestellt hast, kannst du diese E-Mail einfach ignorieren — es wird nichts verändert.

+

Falls der Button nicht funktioniert, kopiere diesen Link in deinen Browser:
{{url}}

+{{/layout}} \ No newline at end of file