Merge branch 'master' into ui_success_message_creation_like_transfer

This commit is contained in:
einhornimmond 2025-11-28 16:12:08 +01:00 committed by GitHub
commit ae5bd1b251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 68 additions and 80 deletions

View File

@ -14,7 +14,6 @@ import { GRADIDO_REALM, LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import { AppDatabase } from 'database'
import { context as serverContext } from './context'
import { cors } from './cors'
import { i18n } from './localization'
import { plugins } from './plugins'
import { jwks, openidConfiguration } from '@/openIDConnect'
// TODO implement
@ -73,9 +72,6 @@ export const createServer = async (
app.use(json())
// bodyparser urlencoded for elopage
app.use(urlencoded({ extended: true }))
// i18n
app.use(i18n.init)
// Elopage Webhook

View File

@ -1,33 +0,0 @@
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
import i18n from 'i18n'
import { getLogger } from 'log4js'
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.server.localization`)
i18n.configure({
locales: ['en', 'de'],
defaultLocale: 'en',
retryInDefaultLocale: false,
staticCatalog: {
en: { general: { decimalSeparator: "." } },
de: { general: { decimalSeparator: "," } },
},
// autoReload: true, // if this is activated the seeding hangs at the very end
updateFiles: false,
objectNotation: true,
logDebugFn: (msg) => logger.debug(msg),
logWarnFn: (msg) => logger.info(msg),
logErrorFn: (msg) => logger.error(msg),
// this api is needed for email-template pug files
api: {
__: 't', // now req.__ becomes req.t
__n: 'tn', // and req.__n can be called as req.tn
},
register: global,
mustacheConfig: {
tags: ['{', '}'],
disable: false,
},
})
export { i18n }

View File

@ -22,8 +22,8 @@
"typecheck": "tsc --noEmit",
"lint": "biome check --error-on-warnings .",
"lint:fix": "biome check --error-on-warnings . --write",
"locales": "scripts/sort.sh src/emails/locales",
"locales:fix": "scripts/sort.sh src/emails/locales --fix",
"locales": "scripts/sort.sh src/locales",
"locales:fix": "scripts/sort.sh src/locales --fix",
"clear": "rm -rf node_modules && rm -rf build && rm -rf .turbo"
},
"dependencies": {

View File

@ -1,6 +1,6 @@
import { createTransport } from 'nodemailer'
import { CONFIG } from '../config'
import { i18n } from './localization'
import { i18n } from '../locales/localization'
import { getLogger } from '../../../config-schema/test/testSetup.bun'
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
import { sendEmailTranslated } from './sendEmailTranslated'
@ -41,7 +41,7 @@ const spySetLocale = jest.spyOn(i18n, 'setLocale')
const spyTranslate = jest.spyOn(i18n, '__')
describe('sendEmailTranslated', () => {
let result: Record<string, unknown> | boolean | null
let result: Record<string, unknown> | boolean | Error | null
describe('config email is false', () => {
beforeEach(async () => {

View File

@ -1,6 +1,6 @@
import path from 'path'
import Email from 'email-templates'
import { i18n } from './localization'
import { i18n } from '../locales/localization'
import { createTransport } from 'nodemailer'
import { CONFIG } from '../config'
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
@ -113,7 +113,6 @@ export const sendEmailTranslated = async ({
})
.catch((error: unknown) => {
logger.error('Error sending notification email', error)
return error
})
return resultSend

View File

@ -47,6 +47,10 @@ describe('sendEmailVariants', () => {
const contributionFrontendLink =
'https://gradido.net/contributions/own-contributions/1#contributionListItem-1'
afterEach(() => {
sendEmailTranslatedSpy.mockClear()
})
describe('sendAddedContributionMessageEmail', () => {
beforeAll(async () => {
result = await sendAddedContributionMessageEmail({
@ -162,7 +166,7 @@ describe('sendEmailVariants', () => {
})
})
/*
describe('sendAccountMultiRegistrationEmail', () => {
beforeAll(async () => {
@ -181,20 +185,22 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'accountMultiRegistration',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
communityURL: CONFIG.COMMUNITY_URL,
},
}),
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -235,24 +241,26 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'contributionConfirmed',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
contributionMemo: 'My contribution.',
contributionAmount: '23.54',
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
contributionFrontendLink,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -292,24 +300,26 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'contributionChangedByModerator',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
contributionMemo: 'My contribution.',
contributionMemoUpdated: 'This is a better contribution memo.',
contributionFrontendLink,
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -348,23 +358,25 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'contributionDenied',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
contributionMemo: 'My contribution.',
contributionFrontendLink,
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
},
}),
})
})
})
describe('result', () => {
it('has expected result', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -403,23 +415,25 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'contributionDeleted',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
contributionMemo: 'My contribution.',
contributionFrontendLink,
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -456,23 +470,25 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'resetPassword',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
resetLink: 'http://localhost/reset-password/3762660021544901417',
timeDurationObject: { hours: 23, minutes: 30 },
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
communityURL: CONFIG.COMMUNITY_URL,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -512,10 +528,10 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'transactionLinkRedeemed',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
senderEmail: 'bibi@bloxberg.de',
@ -523,14 +539,16 @@ describe('sendEmailVariants', () => {
transactionAmount: '17.65',
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
communityURL: CONFIG.COMMUNITY_URL,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -570,10 +588,10 @@ describe('sendEmailVariants', () => {
to: 'Peter Lustig <peter@lustig.de>',
},
template: 'transactionReceived',
locals: {
locals: expect.objectContaining({
firstName: 'Peter',
lastName: 'Lustig',
locale: 'en',
language: 'en',
memo: 'Du bist schon lustiger ;)',
senderFirstName: 'Bibi',
senderLastName: 'Bloxberg',
@ -581,14 +599,16 @@ describe('sendEmailVariants', () => {
transactionAmount: '37.40',
supportEmail: CONFIG.COMMUNITY_SUPPORT_MAIL,
communityURL: CONFIG.COMMUNITY_URL,
},
}),
})
})
})
describe('result', () => {
it('is the expected object', () => {
expect(result).toMatchObject({
// bun testrunner bug, toMatchObject mess with 'result'
const resultClone = JSON.parse(JSON.stringify(result))
expect(resultClone).toMatchObject({
originalMessage: expect.objectContaining({
to: 'Peter Lustig <peter@lustig.de>',
from: 'Gradido (emails.general.doNotAnswer) <info@gradido.net>',
@ -605,5 +625,4 @@ describe('sendEmailVariants', () => {
})
})
})
*/
})

View File

@ -1,6 +1,10 @@
import en from './locales/en.json'
import de from './locales/de.json'
import en from './en.json'
import de from './de.json'
import { I18n } from 'i18n'
import { getLogger } from 'log4js'
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.emails.localization`)
function flatten(obj: any, prefix: string = ''): any {
const result: any = {}
@ -18,6 +22,9 @@ export const i18n = new I18n({
locales: ['en', 'de'],
defaultLocale: 'en',
staticCatalog: { en: flatten(en), de: flatten(de) },
logDebugFn: (msg) => logger.debug(msg),
logWarnFn: (msg) => logger.info(msg),
logErrorFn: (msg) => logger.error(msg),
api: {
__: 't', // now req.__ becomes req.t
__n: 'tn', // and req.__n can be called as req.tn

View File

@ -1,7 +1,7 @@
import { promisify } from 'util'
import { Decimal } from 'decimal.js-light'
import i18n from 'i18n'
import { i18n } from '../locales/localization'
export const objectValuesToArray = (obj: Record<string, string>): string[] =>
Object.keys(obj).map((key) => obj[key])