-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(boards): send mail to new board members (#714)
* fix(boards): send mail to new board members * chore: work on stuff * chore: revert changes to config * fix: add cron for sending new board emails * chore: fix starting the job * chore: fix typo * Update test/assets/core-permissions-full.json --------- Co-authored-by: Rik Smale <WikiRik@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
311 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
MAIL_SUBJECTS: { | ||
NEW_BOARD_EMAIL: 'MyAEGEE: Congratulations on the start of your board term!' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { CronJob } = require('cron'); | ||
const { Board } = require('../models'); | ||
const boards = require('./boards'); | ||
|
||
module.exports.sendAllEmails = async () => { | ||
const allBoards = await Board.findAll({}); | ||
for (const board of allBoards) { | ||
boards.sendNewBoardEmail(board.id); | ||
} | ||
}; | ||
|
||
module.exports.job = new CronJob('0 10 * * *', async () => { | ||
await module.exports.sendAllEmails(); | ||
}, null, true, 'Europe/Brussels'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"success": true, | ||
"data": [{ | ||
"id": 1, | ||
"notification_email": "admin@example.com" | ||
},{ | ||
"id": 2, | ||
"notification_email": "test@example.com" | ||
},{ | ||
"id": 3, | ||
"notification_email": "example@example.com" | ||
},{ | ||
"id": 4, | ||
"notification_email": "mail@example.com" | ||
},{ | ||
"id": 5, | ||
"notification_email": "testing@example.com" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { Board } = require('../../models'); | ||
const boards = require('../../lib/boards'); | ||
const cron = require('../../lib/cron'); | ||
|
||
jest.mock('../../models'); | ||
jest.mock('../../lib/boards'); | ||
|
||
describe('Cron Job Tests', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('sendAllEmails should fetch all boards and send emails', async () => { | ||
const mockBoards = [{ id: 1 }, { id: 2 }]; | ||
Board.findAll.mockResolvedValue(mockBoards); | ||
|
||
await cron.sendAllEmails(); | ||
|
||
expect(Board.findAll).toHaveBeenCalledTimes(1); | ||
expect(boards.sendNewBoardEmail).toHaveBeenCalledTimes(mockBoards.length); | ||
expect(boards.sendNewBoardEmail).toHaveBeenCalledWith(1); | ||
expect(boards.sendNewBoardEmail).toHaveBeenCalledWith(2); | ||
}); | ||
}); |
Oops, something went wrong.