-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mara Martini
committed
Dec 7, 2023
1 parent
48ebb08
commit 18cae9a
Showing
8 changed files
with
330 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"cSpell.words": [ | ||
"CDRN", | ||
"Jeudi", | ||
"Lundi", | ||
"Mercredi", | ||
"mockdate", | ||
"NEWWEEK", | ||
"Semaine", | ||
"Vendredi", | ||
"vvxx", | ||
"xxvv" | ||
] | ||
} |
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,44 @@ | ||
async function newWeek(client) { | ||
const today = new Date(); | ||
const weekDay = today.toLocaleString('en-us', { weekday: 'long' }); | ||
let mondayDate; | ||
|
||
// eslint-disable-next-line unicorn/prefer-switch | ||
if (weekDay === 'Monday') { | ||
mondayDate = today; | ||
} else if (weekDay === 'Tuesday') { | ||
mondayDate = new Date(); | ||
mondayDate.setDate(mondayDate.getDate() - 1); | ||
} else if (weekDay === 'Wednesday') { | ||
mondayDate = new Date(); | ||
mondayDate.setDate(mondayDate.getDate() - 2); | ||
} else if (weekDay === 'Thursday') { | ||
mondayDate = new Date(); | ||
mondayDate.setDate(mondayDate.getDate() - 3); | ||
} else if (weekDay === 'Friday' || weekDay === 'Saturday' || weekDay === 'Sunday') { | ||
mondayDate = new Date(); | ||
mondayDate.setDate(mondayDate.getDate() + ((8 - today.getDay()) % 7)); | ||
} | ||
|
||
const nextFriday = new Date(mondayDate); | ||
nextFriday.setDate(mondayDate.getDate() + 4); | ||
const formattedStartDate = formatDate(mondayDate); | ||
const formattedEndDate = formatDate(nextFriday); | ||
const weekMessage = `Semaine du ${formattedStartDate} au ${formattedEndDate} [NEWWEEK]`; | ||
|
||
await client.chat.postMessage({ | ||
channel: process.env.SLACK_CHANNEL, | ||
text: weekMessage, | ||
}); | ||
return weekMessage; | ||
} | ||
|
||
function formatDate(date) { | ||
return date.toLocaleDateString('fr-FR', { | ||
day: 'numeric', | ||
month: 'numeric', | ||
year: 'numeric', | ||
}); | ||
} | ||
|
||
module.exports = { newWeek }; |
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,60 @@ | ||
const { newWeek } = require('./newweek'); | ||
const MockDate = require('mockdate'); | ||
const fakeClient = { | ||
chat: { | ||
postMessage: () => { | ||
/*nothing to do*/ | ||
}, | ||
}, | ||
}; | ||
|
||
const currentWeekMessage = 'Semaine du 04/12/2023 au 08/12/2023 [NEWWEEK]'; | ||
const nextWeekMessage = 'Semaine du 11/12/2023 au 15/12/2023 [NEWWEEK]'; | ||
|
||
test('Test today is tuesday', async () => { | ||
MockDate.set('2023-12-05'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(currentWeekMessage); | ||
}); | ||
|
||
test('Test today is wednesday', async () => { | ||
MockDate.set('2023-12-06'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(currentWeekMessage); | ||
}); | ||
|
||
test('Test today is monday', async () => { | ||
MockDate.set('2023-12-04'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(currentWeekMessage); | ||
}); | ||
|
||
test('Test today is thursday', async () => { | ||
MockDate.set('2023-12-07'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(currentWeekMessage); | ||
}); | ||
|
||
test('Test today is friday', async () => { | ||
MockDate.set('2023-12-08'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(nextWeekMessage); | ||
}); | ||
|
||
test('Test today is saturday', async () => { | ||
MockDate.set('2023-12-09'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(nextWeekMessage); | ||
}); | ||
|
||
test('Test today is sunday', async () => { | ||
MockDate.set('2023-12-10'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(nextWeekMessage); | ||
}); | ||
|
||
test('Test today is monday', async () => { | ||
MockDate.set('2023-12-11'); | ||
const weekMessage = await newWeek(fakeClient); | ||
expect(weekMessage).toBe(nextWeekMessage); | ||
}); |
Oops, something went wrong.