Skip to content

Commit

Permalink
fix: resolve profil failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarc-RAJAONARIVELONA committed Dec 12, 2024
1 parent 13e83a4 commit 3316220
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cypress/e2e/profile.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Manager} from "@haapi/typescript-client";
import {toUTC} from "../../src/utils/date";
import {manager1Mock} from "../fixtures/api_mocks/managers-mocks";
import {statsMocks} from "../fixtures/api_mocks/letters-mocks";

const editedManager1: Required<Manager> = {
...manager1Mock,
Expand Down Expand Up @@ -28,8 +29,9 @@ describe("Profil test", () => {
cy.getByTestid("latitude-input")
.click()
.type(editedManager1.coordinates.latitude!.toString());
cy.intercept("GET", `students/letters/stats`, statsMocks).as("getStats");

cy.intercept("PUT", `/managers/${manager1Mock.id}`, editedManager1).as(
cy.intercept("PUT", `*/managers/${manager1Mock.id}`, editedManager1).as(
"modifyProfile"
);

Expand Down
4 changes: 3 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Cypress.Commands.add("login", (options: LoginConfig) => {
role,
};

cy.intercept(`**/${role.toLowerCase()}s/${user.id}`, user).as("getProfile");
cy.intercept("GET", `**/${role.toLowerCase()}s/${user.id}`, user).as(
"getProfile"
);
cy.intercept("**/health/db", "OK").as("getHealthDb");
cy.intercept("POST", "https://cognito-idp.eu-west-3.amazonaws.com").as(
"postCognito"
Expand Down
10 changes: 6 additions & 4 deletions src/operations/profile/ProfileEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import {toUTC} from "../../utils/date";
const userToUserApi = ({
birth_date,
entrance_datetime,
ending_service,
coordinates = {},
...data
}: User & Required<Student>["coordinates"] & Required<StaffMember>) => {
const {latitude, longitude} = coordinates;
const {isStaffMember} = useRole();

if (isStaffMember() && data.ending_service) {
data.ending_service = toUTC(new Date(data.ending_service!));
}

return {
...data,
birth_date: toUTC(new Date(birth_date!)).toISOString(),
entrance_datetime: toUTC(new Date(entrance_datetime!)).toISOString(),
ending_service: ending_service
? toUTC(new Date(ending_service!)).toISOString()
: null,
coordinates: {latitude: +latitude!, longitude: +longitude!},
};
};
Expand Down

0 comments on commit 3316220

Please sign in to comment.