Skip to content

Commit

Permalink
Merge branch 'main' into import-job-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks authored Jan 3, 2025
2 parents d66fb26 + a16a9ad commit 2418d90
Showing 1 changed file with 27 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

const { describe, it, before, beforeEach, afterEach } = (exports.lab = Lab.script())
const { describe, it, before, beforeEach, after } = (exports.lab = Lab.script())
const { expect } = Code

// Test helpers
Expand All @@ -20,65 +20,33 @@ describe('Jobs - Return Logs - Fetch Current Return Cycle service', () => {

let allYearReturnCycle
let clock
let previousAllYearReturnCycle
let previousSummerReturnCycle
let summer
let summerReturnCycle

before(async () => {
allYearReturnCycle = await ReturnCycleHelper.select(0, false)
previousAllYearReturnCycle = await ReturnCycleHelper.select(1, false)
summerReturnCycle = await ReturnCycleHelper.select(1, true)
previousSummerReturnCycle = await ReturnCycleHelper.select(2, true)
})

afterEach(() => {
clock.restore()
summerReturnCycle = await ReturnCycleHelper.select(0, true)
})

describe('when summer is "false"', () => {
before(() => {
summer = false
})

describe('and the current date is after the end of April (20**-05-01)', () => {
beforeEach(() => {
clock = Sinon.useFakeTimers(new Date(`${year}-05-01`))
})

it('returns the correct "all year" return cycle', async () => {
const result = await FetchCurrentReturnCycleService.go(summer)

expect(result).to.equal({
dueDate: allYearReturnCycle.dueDate,
endDate: allYearReturnCycle.endDate,
id: allYearReturnCycle.id,
startDate: allYearReturnCycle.startDate,
summer: allYearReturnCycle.summer
})
})
})

describe('and the current date is before the end of April (20**-01-01)', () => {
beforeEach(() => {
clock = Sinon.useFakeTimers(new Date(`${year}-01-01`))
})

it('returns the correct "all year" return cycle', async () => {
const result = await FetchCurrentReturnCycleService.go(summer)
it('returns the correct "all year" return cycle details', async () => {
const result = await FetchCurrentReturnCycleService.go(false)

expect(result).to.equal({
dueDate: previousAllYearReturnCycle.dueDate,
endDate: previousAllYearReturnCycle.endDate,
id: previousAllYearReturnCycle.id,
startDate: previousAllYearReturnCycle.startDate,
summer: previousAllYearReturnCycle.summer
})
expect(result).to.equal({
dueDate: allYearReturnCycle.dueDate,
endDate: allYearReturnCycle.endDate,
id: allYearReturnCycle.id,
startDate: allYearReturnCycle.startDate,
summer: allYearReturnCycle.summer
})
})

describe('and the current date is for a return cycle that has not yet been created', () => {
beforeEach(() => {
before(() => {
clock = Sinon.useFakeTimers(new Date(`${year + 3}-01-01`))
})

Expand All @@ -87,6 +55,10 @@ describe('Jobs - Return Logs - Fetch Current Return Cycle service', () => {

expect(result).to.equal(undefined)
})

after(() => {
clock.restore()
})
})
})

Expand All @@ -95,39 +67,15 @@ describe('Jobs - Return Logs - Fetch Current Return Cycle service', () => {
summer = true
})

describe('and the current date is after the end of October (20**-12-01)', () => {
beforeEach(() => {
clock = Sinon.useFakeTimers(new Date(`${year - 1}-12-01`))
})

it('returns the correct "summer" return cycle', async () => {
const result = await FetchCurrentReturnCycleService.go(summer)
it('returns the correct "summer" return cycle details', async () => {
const result = await FetchCurrentReturnCycleService.go(summer)

expect(result).to.equal({
dueDate: summerReturnCycle.dueDate,
endDate: summerReturnCycle.endDate,
id: summerReturnCycle.id,
startDate: summerReturnCycle.startDate,
summer: summerReturnCycle.summer
})
})
})

describe('and the current date is before the end of October (20**-09-01)', () => {
beforeEach(() => {
clock = Sinon.useFakeTimers(new Date(`${year - 1}-09-01`))
})

it('returns the correct "summer" log cycle', async () => {
const result = await FetchCurrentReturnCycleService.go(summer)

expect(result).to.equal({
dueDate: previousSummerReturnCycle.dueDate,
endDate: previousSummerReturnCycle.endDate,
id: previousSummerReturnCycle.id,
startDate: previousSummerReturnCycle.startDate,
summer: previousSummerReturnCycle.summer
})
expect(result).to.equal({
dueDate: summerReturnCycle.dueDate,
endDate: summerReturnCycle.endDate,
id: summerReturnCycle.id,
startDate: summerReturnCycle.startDate,
summer: summerReturnCycle.summer
})
})

Expand All @@ -141,6 +89,10 @@ describe('Jobs - Return Logs - Fetch Current Return Cycle service', () => {

expect(result).to.equal(undefined)
})

after(() => {
clock.restore()
})
})
})
})

0 comments on commit 2418d90

Please sign in to comment.