From d4cf3e8de626720ce55ed4c58e75c3570fcec00b Mon Sep 17 00:00:00 2001 From: developomp Date: Sun, 30 Jul 2023 21:31:44 +0900 Subject: [PATCH] test: improve test structure --- apps/main/src/utils/getAge.test.ts | 93 ++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/apps/main/src/utils/getAge.test.ts b/apps/main/src/utils/getAge.test.ts index f1b8122..c563549 100644 --- a/apps/main/src/utils/getAge.test.ts +++ b/apps/main/src/utils/getAge.test.ts @@ -9,37 +9,72 @@ describe("getAge tests", () => { }) test("isOverBirthDay to work", () => { - expect( - isOverBirthDay(new Date("2022-12-31, 00:00:00.000 +09:00")) - ).toEqual(true) + const testCases: { + timestamp: string + overBD: boolean + year: number + monthIndex: number + date: number + }[] = [ + { + timestamp: "2022-12-31, 00:00:00.000 +09:00", + overBD: true, + year: 2022, + monthIndex: 11, + date: 31, + }, + { + timestamp: "2023-01-01, 00:00:00.000 +09:00", + overBD: false, + year: 2023, + monthIndex: 0, + date: 1, + }, + { + timestamp: "2023-07-29, 00:00:00.000 +09:00", + overBD: false, + year: 2023, + monthIndex: 6, + date: 29, + }, + { + timestamp: "2023-07-30, 00:00:00.000 +09:00", + overBD: true, + year: 2023, + monthIndex: 6, + date: 30, + }, + { + timestamp: "2023-07-31, 00:00:00.000 +09:00", + overBD: true, + year: 2023, + monthIndex: 6, + date: 31, + }, + { + timestamp: "2023-12-31, 00:00:00.000 +09:00", + overBD: true, + year: 2023, + monthIndex: 11, + date: 31, + }, + { + timestamp: "2024-01-01, 00:00:00.000 +09:00", + overBD: false, + year: 2024, + monthIndex: 0, + date: 1, + }, + ] - expect( - isOverBirthDay(new Date("2023-01-01, 00:00:00.000 +09:00")) - ).toEqual(false) + for (const testCase of testCases) { + const date = new Date(testCase.timestamp) - // - - expect( - isOverBirthDay(new Date("2023-07-29, 00:00:00.000 +09:00")) - ).toEqual(false) - - expect( - isOverBirthDay(new Date("2023-07-30, 00:00:00.000 +09:00")) - ).toEqual(true) - - expect( - isOverBirthDay(new Date("2023-07-31, 00:00:00.000 +09:00")) - ).toEqual(true) - - // - - expect( - isOverBirthDay(new Date("2023-12-31, 00:00:00.000 +09:00")) - ).toEqual(true) - - expect( - isOverBirthDay(new Date("2024-01-01, 00:00:00.000 +09:00")) - ).toEqual(false) + expect(date.getFullYear()).toEqual(testCase.year) + expect(date.getMonth()).toEqual(testCase.monthIndex) + expect(date.getDate()).toEqual(testCase.date) + expect(isOverBirthDay(date)).toEqual(testCase.overBD) + } }) test("dateFormatOption to work properly", () => {