This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: psy admin form : format input values + update fields (#190)
- Loading branch information
1 parent
a99c0a1
commit 1944469
Showing
12 changed files
with
442 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { stub } from "sinon"; | ||
|
||
import { models } from "../db/models"; | ||
import { getOnePsychologist } from "../db/seeds/psychologist"; | ||
import { updateIfExists } from "../pages/api/admin/psychologists/[id]"; | ||
import * as address from "../services/getAddressCoordinates"; | ||
import { Psychologist } from "../types/psychologist"; | ||
|
||
describe("updateIfExists", () => { | ||
let getAddressCoordinatesStub; | ||
beforeAll(async () => { | ||
await models.Psychologist.destroy({ where: {} }); | ||
|
||
const psy = await getOnePsychologist({ id: 1, department: "01" }); | ||
// @ts-ignore | ||
await models.Psychologist.create(psy); | ||
}); | ||
beforeEach(() => { | ||
getAddressCoordinatesStub = stub(address, "default"); | ||
}); | ||
|
||
afterEach(() => { | ||
getAddressCoordinatesStub.restore(); | ||
}); | ||
const valideInput = { | ||
address: "My new adress", | ||
addressAdditional: "Mon complément d'adresse", | ||
cdsmsp: "optio", | ||
displayEmail: true, | ||
email: "updated@example.net", | ||
firstName: "CaRmen", | ||
lastName: "strOMan", | ||
phone: "02 71 94 65 55", | ||
displayPhone: false, | ||
public: "Adultes et enfants/adolescents", | ||
teleconsultation: true, | ||
visible: true, | ||
website: "grotesque-proximity.info", | ||
shouldBeIgnored: "should not failed", | ||
}; | ||
|
||
it("update should undefined if does not exists", async () => { | ||
expect(await updateIfExists("1111", "", {})).toEqual(undefined); | ||
}); | ||
it("update should undefined if the department does not match", async () => { | ||
expect(await updateIfExists("1111", "99", {})).toEqual(undefined); | ||
}); | ||
it("update should return error if wrong params", async () => { | ||
let exception; | ||
await updateIfExists("1", "01", {}).catch((e) => (exception = e)); | ||
expect(exception.details.length).toEqual(9); | ||
expect(exception.details[0].message).toEqual('"address" is required'); | ||
}); | ||
it("update should update psy in db", async () => { | ||
let exception; | ||
getAddressCoordinatesStub.returns({ latitude: 456, longitude: 123 }); | ||
|
||
const result = await updateIfExists("1", "01", valideInput).catch( | ||
(e) => (exception = e) | ||
); | ||
expect(exception).toEqual(undefined); | ||
expect(result).toEqual([1]); | ||
|
||
// @ts-ignore | ||
const updatedPsy: Psychologist = await models.Psychologist.findOne({ | ||
raw: true, | ||
where: { email: valideInput.email }, | ||
}); | ||
expect(updatedPsy.firstName).toEqual("Carmen"); | ||
expect(updatedPsy.lastName).toEqual("STROMAN"); | ||
expect(updatedPsy.phone).toEqual("02 71 94 65 55"); | ||
expect(updatedPsy.displayPhone).toEqual(false); | ||
expect(updatedPsy.public).toEqual("Adultes et enfants/adolescents"); | ||
expect(updatedPsy.addressAdditional).toEqual("Mon complément d'adresse"); | ||
expect(updatedPsy.coordinates.coordinates).toEqual([123, 456]); | ||
expect(updatedPsy.coordinates.type).toEqual("Point"); | ||
|
||
// @ts-ignore | ||
expect(updatedPsy.shouldBeIgnored).toEqual(undefined); | ||
}); | ||
it("update should coordinate with null if API returns null", async () => { | ||
let exception; | ||
getAddressCoordinatesStub.returns(null); | ||
|
||
const result = await updateIfExists("1", "01", valideInput).catch( | ||
(e) => (exception = e) | ||
); | ||
expect(exception).toEqual(undefined); | ||
expect(result).toEqual([1]); | ||
|
||
// @ts-ignore | ||
const updatedPsy: Psychologist = await models.Psychologist.findOne({ | ||
raw: true, | ||
where: { email: valideInput.email }, | ||
}); | ||
expect(updatedPsy.coordinates).toEqual(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.