Fixed semgrep error
This commit is contained in:
@@ -36,6 +36,7 @@ vi.mock('../server/utils/logger.js', () => ({
|
||||
const authUtils = await import('../server/utils/auth.js')
|
||||
const memberUtils = await import('../server/utils/members.js')
|
||||
const pushUtils = await import('../server/utils/push-notifications.js')
|
||||
const spielplanUtils = await import('../server/utils/spielplan-data.js')
|
||||
|
||||
const { runNotificationSchedulerTick } = await import('../server/utils/notification-scheduler.js')
|
||||
|
||||
@@ -53,11 +54,22 @@ const recipient = {
|
||||
describe('Notification Scheduler', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.spyOn(fs, 'readFile').mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }))
|
||||
vi.spyOn(fs, 'readFile').mockImplementation(async (filePath) => {
|
||||
if (String(filePath).includes('mannschaften_25--26.csv')) {
|
||||
return [
|
||||
'Mannschaft,Liga,Staffelleiter,Telefon,Heimspieltag,Spielsystem,Mannschaftsführer,Spieler,Weitere Informationen Link,Letzte Aktualisierung',
|
||||
'Erwachsene 1,,,,,,Mannschaftsfuehrer,Max Spieler,,',
|
||||
'Erwachsene 2,,,,,,Andere Person,Andere Spieler,,'
|
||||
].join('\n')
|
||||
}
|
||||
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' })
|
||||
})
|
||||
vi.spyOn(fs, 'mkdir').mockResolvedValue(undefined)
|
||||
vi.spyOn(fs, 'writeFile').mockResolvedValue(undefined)
|
||||
memberUtils.readMembers.mockResolvedValue([])
|
||||
authUtils.readUsers.mockResolvedValue([recipient])
|
||||
spielplanUtils.getDefaultSpielplanSeason.mockResolvedValue('25--26')
|
||||
spielplanUtils.readSpielplanData.mockResolvedValue({ data: [] })
|
||||
})
|
||||
|
||||
it('sendet Geburtstags-Push nur fuer Mitglieder mit expliziter Geburtstagsfreigabe', async () => {
|
||||
@@ -90,4 +102,90 @@ describe('Notification Scheduler', () => {
|
||||
expect(payload.body).not.toMatch(/\b\d+\b/)
|
||||
expect(payload.body).not.toContain('Jahre')
|
||||
})
|
||||
|
||||
it('sendet Punktspiel-Push nur einmal, wenn alle, eigene und ausgewaehlte Mannschaft dasselbe Spiel treffen', async () => {
|
||||
const matchUser = {
|
||||
id: 'match-user',
|
||||
name: 'Max Spieler',
|
||||
active: true,
|
||||
notificationSettings: {
|
||||
allTeamMatches: true,
|
||||
ownTeamMatches: true,
|
||||
selectedTeamSlugs: ['erwachsene-1'],
|
||||
selectedTeamSeason: '25--26',
|
||||
notificationTime: '09:00'
|
||||
}
|
||||
}
|
||||
authUtils.readUsers.mockResolvedValue([matchUser])
|
||||
spielplanUtils.readSpielplanData.mockResolvedValue({
|
||||
data: [{
|
||||
Termin: '14.06.2026 20:15',
|
||||
BegegnungNr: 'spiel-1',
|
||||
Altersklasse: 'Erwachsene',
|
||||
HeimVereinName: 'Harheimer TC',
|
||||
HeimMannschaftAltersklasse: 'Erwachsene',
|
||||
HeimMannschaftNr: '1',
|
||||
HeimMannschaft: 'Harheimer TC',
|
||||
GastVereinName: 'Gastverein',
|
||||
GastMannschaftAltersklasse: 'Erwachsene',
|
||||
GastMannschaftNr: '1',
|
||||
GastMannschaft: 'Gastverein'
|
||||
}]
|
||||
})
|
||||
|
||||
await runNotificationSchedulerTick(schedulerNow)
|
||||
|
||||
expect(pushUtils.sendPushToUsers).toHaveBeenCalledTimes(1)
|
||||
const payload = pushUtils.sendPushToUsers.mock.calls[0][0]
|
||||
expect(payload.title).toBe('Punktspiele')
|
||||
expect(payload.predicate(matchUser, matchUser.notificationSettings)).toBe(true)
|
||||
expect(payload.bodyForUser(matchUser, matchUser.notificationSettings)).toContain('Harheimer TC - Gastverein')
|
||||
})
|
||||
|
||||
it('fasst eigene und ausgewaehlte Punktspiele in einer Benachrichtigung zusammen', async () => {
|
||||
const matchUser = {
|
||||
id: 'match-user',
|
||||
name: 'Max Spieler',
|
||||
active: true,
|
||||
notificationSettings: {
|
||||
allTeamMatches: false,
|
||||
ownTeamMatches: true,
|
||||
selectedTeamSlugs: ['erwachsene-2'],
|
||||
selectedTeamSeason: '25--26',
|
||||
notificationTime: '09:00'
|
||||
}
|
||||
}
|
||||
authUtils.readUsers.mockResolvedValue([matchUser])
|
||||
spielplanUtils.readSpielplanData.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
Termin: '14.06.2026 20:15',
|
||||
BegegnungNr: 'spiel-1',
|
||||
Altersklasse: 'Erwachsene',
|
||||
HeimVereinName: 'Harheimer TC',
|
||||
HeimMannschaftAltersklasse: 'Erwachsene',
|
||||
HeimMannschaftNr: '1',
|
||||
HeimMannschaft: 'Harheimer TC',
|
||||
GastMannschaft: 'Gastverein'
|
||||
},
|
||||
{
|
||||
Termin: '14.06.2026 20:30',
|
||||
BegegnungNr: 'spiel-2',
|
||||
Altersklasse: 'Erwachsene',
|
||||
HeimMannschaft: 'Gastverein II',
|
||||
GastVereinName: 'Harheimer TC',
|
||||
GastMannschaftAltersklasse: 'Erwachsene',
|
||||
GastMannschaftNr: '2',
|
||||
GastMannschaft: 'Harheimer TC II'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
await runNotificationSchedulerTick(schedulerNow)
|
||||
|
||||
expect(pushUtils.sendPushToUsers).toHaveBeenCalledTimes(1)
|
||||
const payload = pushUtils.sendPushToUsers.mock.calls[0][0]
|
||||
expect(payload.predicate(matchUser, matchUser.notificationSettings)).toBe(true)
|
||||
expect(payload.bodyForUser(matchUser, matchUser.notificationSettings)).toBe('2 Punktspiele am 14.06.2026')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user