Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
fix(admin): allow empty website
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Sep 29, 2022
1 parent 20fb78a commit 8f145cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/__tests__/psychologists-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,27 @@ describe("updateIfExists", () => {
await updateIfExists("1", "01", { ...valideInput, languages: "" });
await expectUpdatedPsy(null);
});

it("should empty website when website is empty", async () => {
async function expectUpdatedPsy(expected) {
const updatedPsy = (await models.Psychologist.findOne({
where: { email: valideInput.email },
})) as unknown as Psychologist;
expect(updatedPsy.website).toEqual(expected);
}
getAddressCoordinatesStub.returns({ latitude: 456, longitude: 123 });
// Should add website.
await updateIfExists("1", "01", {
...valideInput,
website: "https://example.org",
});
await expectUpdatedPsy("https://example.org");
// Should not alter website when nothing is provided.
const { website, ...inputWithoutWebsite } = valideInput;
await updateIfExists("1", "01", inputWithoutWebsite);
await expectUpdatedPsy("https://example.org");
// Should empty website when empty string is provided.
await updateIfExists("1", "01", { ...valideInput, website: "" });
await expectUpdatedPsy(null);
});
});
9 changes: 6 additions & 3 deletions src/services/format-psychologists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ const FORMATTERS = {
? undefined
: value.toLowerCase(),
languages: formatLanguage,
website: (value) =>
websiteSchema.validate({ website: value }).error
website: (value) => {
if (value === undefined) return;
if (!value) return null;
return websiteSchema.validate({ website: value }).error
? undefined
: value.toLowerCase(),
: value.toLowerCase();
},
};
const parseChampValue = (field, value) =>
FORMATTERS[field] ? FORMATTERS[field](value) : value;
Expand Down

0 comments on commit 8f145cf

Please sign in to comment.