Skip to content

Commit

Permalink
Add tests for isPeriodBetweenStartAndEnd
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Baratta <[email protected]>
  • Loading branch information
giovannibaratta committed May 19, 2024
1 parent ef4eff1 commit a0746e4
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/utils/date.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {isSamePeriod} from "./date.ts"
import {Period} from "../model/monthly-report.ts"
import {isPeriodBetweenStartAndEnd} from "./date"

describe("isSamePeriod", () => {
it("should return true if the dates are in the same period", () => {
Expand Down Expand Up @@ -48,3 +49,109 @@ describe("isSamePeriod", () => {
expect(result).toBe(false)
})
})

describe("isPeriodBetweenStartAndEnd", () => {
it("should return true if the period is between the start and end periods (inclusive)", () => {
// Given
const period = {year: 2023, month: 2}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end)

// Expect
expect(result).toBe(true)
})

it("should return true if the period is equal to the start period (inclusive)", () => {
// Given
const period = {year: 2023, month: 1}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end, {includeStart: true})

// Expect
expect(result).toBe(true)
})

it("should return true if the period is equal to the end period (inclusive)", () => {
// Given
const period = {year: 2023, month: 3}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end, {includeEnd: true})

// Expect
expect(result).toBe(true)
})

it("should return false if the period is before the start period", () => {
// Given
const period = {year: 2023, month: 1}
const start = {year: 2023, month: 2}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end)

// Expect
expect(result).toBe(false)
})

it("should return false if the period is after the end period", () => {
// Given
const period = {year: 2023, month: 4}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end)

// Expect
expect(result).toBe(false)
})

it("should handle different years correctly", () => {
// Given
const period = {year: 2024, month: 1}
const start = {year: 2023, month: 12}
const end = {year: 2024, month: 2}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end)

// Expect
expect(result).toBe(true)
})

it("should return false if the period is equal to the start period but includeStart is false", () => {
// Given
const period = {year: 2023, month: 1}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end, {includeStart: false})

// Expect
expect(result).toBe(false)
})

it("should return false if the period is equal to the end period but includeEnd is false", () => {
// Given
const period = {year: 2023, month: 3}
const start = {year: 2023, month: 1}
const end = {year: 2023, month: 3}

// When
const result = isPeriodBetweenStartAndEnd(period, start, end, {includeEnd: false})

// Expect
expect(result).toBe(false)
})
})

0 comments on commit a0746e4

Please sign in to comment.