-
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.
Merge branch 'main' into refactor-convert-to-csv
- Loading branch information
Showing
4 changed files
with
127 additions
and
42 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
app/services/notifications/setup/determine-returns-period.service.js
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,58 @@ | ||
'use strict' | ||
|
||
/** | ||
* Determines the returns period data for the provided returns period | ||
* @module DetermineReturnsPeriod | ||
*/ | ||
|
||
const { determineUpcomingReturnPeriods } = require('../../../lib/return-periods.lib.js') | ||
|
||
/** | ||
* Determines the returns period data for the provided returns period | ||
* | ||
* All the returns periods will be calculated from the upcoming return periods. | ||
* | ||
* The `returnsPeriod` will be found and returned | ||
* | ||
* @param {string} returnsPeriod | ||
* | ||
* @returns {object} - the returns period and the if the period is `summer` | ||
*/ | ||
function go(returnsPeriod) { | ||
return { | ||
returnsPeriod: _returnsPeriod(returnsPeriod), | ||
summer: _summer(returnsPeriod) | ||
} | ||
} | ||
|
||
/** | ||
* Finds the provided returns period from the determined upcoming return periods. | ||
* | ||
* @private | ||
*/ | ||
function _returnsPeriod(returnsPeriod) { | ||
const periods = determineUpcomingReturnPeriods() | ||
|
||
return periods.find((period) => { | ||
return period.name === returnsPeriod | ||
}) | ||
} | ||
|
||
/** | ||
* When the returns period is summer then need return 'true' | ||
* | ||
* The string value is used when querying crm which expects a string and not a boolean | ||
* | ||
* @param {string} returnsPeriod | ||
* | ||
* @returns {string} - CRM expects a string of the boolean value ("true" | "false") | ||
* | ||
* @private | ||
*/ | ||
function _summer(returnsPeriod) { | ||
return returnsPeriod === 'summer' ? 'true' : 'false' | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
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
65 changes: 65 additions & 0 deletions
65
test/services/notifications/setup/determine-returns-period.service.test.js
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,65 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
const Sinon = require('sinon') | ||
|
||
const { describe, it, afterEach, before, beforeEach } = (exports.lab = Lab.script()) | ||
const { expect } = Code | ||
|
||
// Thing under test | ||
const DetermineReturnsPeriodService = require('../../../../app/services/notifications/setup/determine-returns-period.service.js') | ||
|
||
describe('Notifications Setup - Determine returns period service', () => { | ||
const year = 2025 | ||
|
||
let clock | ||
let returnsPeriod | ||
|
||
before(async () => { | ||
clock = Sinon.useFakeTimers(new Date(`${year}-01-01`)) | ||
|
||
returnsPeriod = 'quarterFour' | ||
}) | ||
|
||
afterEach(() => { | ||
clock.restore() | ||
}) | ||
|
||
describe('when the returns period is not for summer', () => { | ||
it('should return the returns period and summer "false"', () => { | ||
const result = DetermineReturnsPeriodService.go(returnsPeriod) | ||
|
||
expect(result).to.equal({ | ||
returnsPeriod: { | ||
dueDate: new Date('2025-04-28'), | ||
endDate: new Date('2025-03-31'), | ||
name: 'quarterFour', | ||
startDate: new Date('2025-01-01') | ||
}, | ||
summer: 'false' | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the returns period is for summer', () => { | ||
beforeEach(async () => { | ||
returnsPeriod = 'summer' | ||
}) | ||
|
||
it('should return the returns period and summer "true"', () => { | ||
const result = DetermineReturnsPeriodService.go(returnsPeriod) | ||
|
||
expect(result).to.equal({ | ||
returnsPeriod: { | ||
dueDate: new Date('2025-11-28'), | ||
endDate: new Date('2025-10-31'), | ||
name: 'summer', | ||
startDate: new Date('2024-11-01') | ||
}, | ||
summer: 'true' | ||
}) | ||
}) | ||
}) | ||
}) |
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