Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev local : les tests unitaires API qui manipulent des dates échouent #291

Closed
florimondmanca opened this issue Nov 4, 2022 · 0 comments · Fixed by #292
Closed

Dev local : les tests unitaires API qui manipulent des dates échouent #291

florimondmanca opened this issue Nov 4, 2022 · 0 comments · Fixed by #292

Comments

@florimondmanca
Copy link
Contributor

florimondmanca commented Nov 4, 2022

Comportement attendu

En local, tous les tests lancés avec make test devraient passer, comme c'est le cas sur la CI

Comportement réel

On a 9 tests unitaires côté API qui échouent (côté client c'est OK).

Pour reproduire

  • git checkout master
  • make test-api

Pistes de résolution

Puisque ça concerne les tests qui manipulent des dates, c'est peut-être un problème de timezone pas définie (les serveurs de GitHub sont qq part dans le monde où les tests passent)

Debug

Sortie de make test :

 FAIL  src/Application/Common/MonthDate.spec.ts
  ● MonthDate › testFirstDayOfMonth

    expect(received).toBe(expected) // Object.is equality

    Expected: "2022-12-01"
    Received: "2022-11-30"

       5 |     const month = new MonthDate(2022, 12);
       6 |     const firstDay = month.getFirstDay();
    >  7 |     expect(firstDay.toISOString().substring(0, 10)).toBe('2022-12-01');
         |                                                     ^
       8 |   });
       9 |
      10 |   it('testLastDayOfMonth', async () => {

      at Object.<anonymous> (Application/Common/MonthDate.spec.ts:7:53)

  ● MonthDate › testLastDayOfMonth

    expect(received).toBe(expected) // Object.is equality

    Expected: "2022-12-31"
    Received: "2022-12-30"

      11 |     const month = new MonthDate(2022, 12);
      12 |     const lastDay = month.getLastDay();
    > 13 |     expect(lastDay.toISOString().substring(0, 10)).toBe('2022-12-31');
         |                                                    ^
      14 |   });
      15 | });
      16 |

      at Object.<anonymous> (Application/Common/MonthDate.spec.ts:13:52)

 PASS  src/Infrastructure/Common/Utils/Array.spec.ts
 PASS  src/Domain/File/File.entity.spec.ts
 PASS  src/Infrastructure/HumanResource/Leave/DTO/ModerationDTO.spec.ts
 PASS  src/Domain/Accounting/QuoteItem.entity.spec.ts
 PASS  src/Domain/Task/Task.entity.spec.ts
 PASS  src/Domain/HumanResource/Savings/InterestRate.entity.spec.ts

Summary of all failing tests
 FAIL  Application/HumanResource/Payslip/Query/GetUserElementsQueryHandler.spec.ts
  ● GetUserElementsQueryHandler › testGetUserElements

    expect(received).toMatchObject(expected)

    - Expected  - 6
    + Received  + 6

    @@ -1,7 +1,7 @@
      Array [
    -   UserElementsView {
    +   Object {
          "annualEarnings": 20000,
          "contract": "cdi",
          "exceptionalLeaves": UserLeavesView {
            "leaves": Array [],
            "totalDays": 0,
    @@ -11,22 +11,22 @@
          "isExecutivePosition": true,
          "joiningDate": "2022-11-04T10:05:03.143Z",
          "lastName": "Doe",
          "mealTickets": 5,
          "monthlyEarnings": 1666.6666666666667,
    -     "paidLeaves": UserLeavesView {
    +     "paidLeaves": Object {
            "leaves": Array [
              LeaveRequestSlotView {
                "endDate": "2022-05-11",
                "startDate": "2022-05-09",
              },
    -         LeaveRequestSlotView {
    +         Object {
                "endDate": "2022-05-02",
    -           "startDate": "2022-05-01T00:00:00.000Z",
    +           "startDate": "2022-04-30T22:00:00.000Z",
              },
    -         LeaveRequestSlotView {
    -           "endDate": "2022-05-31T00:00:00.000Z",
    +         Object {
    +           "endDate": "2022-05-30T22:00:00.000Z",
                "startDate": "2022-05-29",
              },
            ],
            "totalDays": 0,
          },

      143 |     const transportFee = rawTransportFee * 0.01;
      144 |
    > 145 |     expect(await queryHandler.execute(query)).toMatchObject([
          |                                               ^
      146 |       new UserElementsView(
      147 |         'John',
      148 |         'Doe',

      at Object.<anonymous> (Application/HumanResource/Payslip/Query/GetUserElementsQueryHandler.spec.ts:145:47)

 FAIL  Infrastructure/Adapter/DateUtilsAdapter.spec.ts
  ● DateUtilsAdapter › testGetWorkedDaysDuringAPeriod

    expect(received).toMatchObject(expected)

    - Expected  - 6
    + Received  + 8

      Array [
    -   2020-12-24T00:00:00.000Z,
    -   2020-12-28T00:00:00.000Z,
    -   2020-12-29T00:00:00.000Z,
    -   2020-12-30T00:00:00.000Z,
    -   2020-12-31T00:00:00.000Z,
    -   2021-01-04T00:00:00.000Z,
    +   2020-12-23T23:00:00.000Z,
    +   2020-12-24T23:00:00.000Z,
    +   2020-12-27T23:00:00.000Z,
    +   2020-12-28T23:00:00.000Z,
    +   2020-12-29T23:00:00.000Z,
    +   2020-12-30T23:00:00.000Z,
    +   2020-12-31T23:00:00.000Z,
    +   2021-01-03T23:00:00.000Z,
      ]

      64 |     expect(
      65 |       dateUtils.getWorkedDaysDuringAPeriod(startDate, endDate)
    > 66 |     ).toMatchObject([
         |       ^
      67 |       new Date('2020-12-24'),
      68 |       new Date('2020-12-28'),
      69 |       new Date('2020-12-29'),

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:66:7)

  ● DateUtilsAdapter › testGetWorkedFreeDays

    expect(received).toMatchObject(expected)

    - Expected  - 2
    + Received  + 2

    @@ -5,8 +5,8 @@
        2020-07-14T00:00:00.000Z,
        2020-08-15T00:00:00.000Z,
        2020-11-01T00:00:00.000Z,
        2020-11-11T00:00:00.000Z,
        2020-12-25T00:00:00.000Z,
    -   2020-04-13T00:00:00.000Z,
    -   2020-05-21T00:00:00.000Z,
    +   2020-04-12T22:00:00.000Z,
    +   2020-05-20T22:00:00.000Z,
      ]

      77 |     const dateUtils = new DateUtilsAdapter();
      78 |
    > 79 |     expect(dateUtils.getWorkedFreeDays(2020)).toMatchObject([
         |                                               ^
      80 |       new Date(`2020-01-01T00:00:00.000Z`),
      81 |       new Date(`2020-05-01T00:00:00.000Z`),
      82 |       new Date(`2020-05-08T00:00:00.000Z`),

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:79:47)

  ● DateUtilsAdapter › testGetEasterDate

    expect(received).toMatchObject(expected)

    Expected: 2020-04-12T00:00:00.000Z
    Received: 2020-04-11T22:00:00.000Z

      107 |     const dateUtils = new DateUtilsAdapter();
      108 |
    > 109 |     expect(dateUtils.getEasterDate(2020)).toMatchObject(
          |                                           ^
      110 |       new Date(`2020-04-12T00:00:00.000Z`)
      111 |     );
      112 |     expect(dateUtils.getEasterDate(2021)).toMatchObject(

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:109:43)

  ● DateUtilsAdapter › testGetLeaveDuration

    expect(received).toBe(expected) // Object.is equality

    Expected: 7
    Received: 8

      126 |     expect(
      127 |       dateUtils.getLeaveDuration('2020-05-05', false, '2020-05-15', false)
    > 128 |     ).toBe(7);
          |       ^
      129 |   });
      130 |
      131 |   it('testGetMinimumLeaveDuration', () => {

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:128:7)

  ● DateUtilsAdapter › testGetLastDayOfYear

    expect(received).toStrictEqual(expected) // deep equality

    Expected: 2021-12-31T00:00:00.000Z
    Received: 2021-12-30T23:00:00.000Z

      147 |     const now = new Date('2021-12-12');
      148 |     const result = dateUtils.getLastDayOfYear(now);
    > 149 |     expect(result).toStrictEqual(new Date('2021-12-31'));
          |                    ^
      150 |   });
      151 |
      152 |   it('getFirstDayOfYear', () => {

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:149:20)

  ● DateUtilsAdapter › getFirstDayOfYear

    expect(received).toStrictEqual(expected) // deep equality

    Expected: 2021-01-01T00:00:00.000Z
    Received: 2020-12-31T23:00:00.000Z

      154 |     const now = new Date('2021-12-12');
      155 |     const result = dateUtils.getFirstDayOfYear(now);
    > 156 |     expect(result).toStrictEqual(new Date('2021-01-01'));
          |                    ^
      157 |   });
      158 |
      159 |   it('getMonth', () => {

      at Object.<anonymous> (Infrastructure/Adapter/DateUtilsAdapter.spec.ts:156:20)

 FAIL  Application/Common/MonthDate.spec.ts
  ● MonthDate › testFirstDayOfMonth

    expect(received).toBe(expected) // Object.is equality

    Expected: "2022-12-01"
    Received: "2022-11-30"

       5 |     const month = new MonthDate(2022, 12);
       6 |     const firstDay = month.getFirstDay();
    >  7 |     expect(firstDay.toISOString().substring(0, 10)).toBe('2022-12-01');
         |                                                     ^
       8 |   });
       9 |
      10 |   it('testLastDayOfMonth', async () => {

      at Object.<anonymous> (Application/Common/MonthDate.spec.ts:7:53)

  ● MonthDate › testLastDayOfMonth

    expect(received).toBe(expected) // Object.is equality

    Expected: "2022-12-31"
    Received: "2022-12-30"

      11 |     const month = new MonthDate(2022, 12);
      12 |     const lastDay = month.getLastDay();
    > 13 |     expect(lastDay.toISOString().substring(0, 10)).toBe('2022-12-31');
         |                                                    ^
      14 |   });
      15 | });
      16 |

      at Object.<anonymous> (Application/Common/MonthDate.spec.ts:13:52)


Test Suites: 3 failed, 120 passed, 123 total
Tests:       9 failed, 285 passed, 294 total
Snapshots:   0 total
Time:        25.719s
Ran all test suites
@florimondmanca florimondmanca changed the title Dev local : les tests unitaires API manipulant des dates échouent Dev local : les tests unitaires API qui manipulent des dates échouent Nov 4, 2022
@florimondmanca florimondmanca added this to Backlog in Permacoop via automation Nov 4, 2022
Permacoop automation moved this from Backlog to Done Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Permacoop
  
Done
Development

Successfully merging a pull request may close this issue.

1 participant