Skip to content

Commit

Permalink
refactor: handle last code revue returns
Browse files Browse the repository at this point in the history
  • Loading branch information
adgeg authored and Joseph Robert committed Sep 20, 2022
1 parent f9c44c4 commit ad71615
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fixtures/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function mockedRendezVousService(
overrides: Partial<RendezVousService> = {}
): RendezVousService {
const defaults: RendezVousService = {
getRendezVousConseillerClientSide: jest.fn(),
getRendezVousConseiller: jest.fn(),
getRendezVousJeune: jest.fn(),
getDetailsRendezVous: jest.fn(),
getTypesRendezVous: jest.fn(),
Expand Down
6 changes: 3 additions & 3 deletions pages/mes-rendezvous.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ function MesRendezvous({

async function chargerRdvs7Jours(index7Jours: number) {
const rdvs7Jours =
await rendezVousService.getRendezVousConseillerClientSide(
await rendezVousService.getRendezVousConseiller(
conseiller!.id,
jourDeDebutDesRdvs(index7Jours),
jourDeFinDesRdvs(index7Jours)
)
if (rdvs7Jours) setRdvs(rdvs7Jours.map(rdvToListItem))
}

function jourDeDebutDesRdvs(index7Jours?: number) {
function jourDeDebutDesRdvs(index7Jours?: number): DateTime {
return AUJOURDHUI.plus({
day: 7 * (index7Jours ?? index7JoursAffiches),
})
}

function jourDeFinDesRdvs(index7Jours?: number) {
function jourDeFinDesRdvs(index7Jours?: number): DateTime {
return jourDeDebutDesRdvs(index7Jours ?? index7JoursAffiches)
.plus({ day: 6 })
.endOf('day')
Expand Down
4 changes: 2 additions & 2 deletions services/rendez-vous.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ApiError } from 'utils/httpClient'
import { DateTime } from 'luxon'

export interface RendezVousService {
getRendezVousConseillerClientSide(
getRendezVousConseiller(
idConseiller: string,
dateDebut: DateTime,
dateFin: DateTime
Expand All @@ -38,7 +38,7 @@ export interface RendezVousService {
export class RendezVousApiService implements RendezVousService {
constructor(private readonly apiClient: ApiClient) {}

async getRendezVousConseillerClientSide(
async getRendezVousConseiller(
idConseiller: string,
dateDebut: DateTime,
dateFin: DateTime
Expand Down
26 changes: 12 additions & 14 deletions tests/pages/MesRendezvous.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ describe('MesRendezvous', () => {
describe('rendez-vous', () => {
beforeEach(async () => {
rendezVousService = mockedRendezVousService({
getRendezVousConseillerClientSide: jest
.fn()
.mockImplementation(function (_, dateDebut) {
const rendezVous = unRendezVous({
date: dateDebut.plus({ day: 3 }).toISO(),
})
return [rendezVous]
}),
getRendezVousConseiller: jest
.fn()
.mockImplementation(function (_, dateDebut) {
const rendezVous = unRendezVous({
date: dateDebut.plus({ day: 3 }).toISO(),
})
return [rendezVous]
}),
})

await act(async () => {
Expand All @@ -98,7 +98,7 @@ describe('MesRendezvous', () => {
it('sont affichés par défaut', async () => {
// Then
expect(
rendezVousService.getRendezVousConseillerClientSide
rendezVousService.getRendezVousConseiller
).toHaveBeenCalledWith('1', SEPTEMBRE_1_0H, SEPTEMBRE_7_23H)

expect(screen.getByText('dimanche 4 septembre')).toBeInTheDocument()
Expand All @@ -114,9 +114,7 @@ describe('MesRendezvous', () => {
await userEvent.click(buttonRdvsSemaineCourante)

// Then service should be called twice: on page display and on button click
expect(
rendezVousService.getRendezVousConseillerClientSide
).toBeCalledTimes(2)
expect(rendezVousService.getRendezVousConseiller).toBeCalledTimes(2)
})
})

Expand All @@ -132,7 +130,7 @@ describe('MesRendezvous', () => {

// Then
expect(
rendezVousService.getRendezVousConseillerClientSide
rendezVousService.getRendezVousConseiller
).toHaveBeenLastCalledWith('1', AOUT_25_0H, AOUT_31_23H)

expect(screen.getByText('dimanche 28 août')).toBeInTheDocument()
Expand All @@ -151,7 +149,7 @@ describe('MesRendezvous', () => {

// Then
expect(
rendezVousService.getRendezVousConseillerClientSide
rendezVousService.getRendezVousConseiller
).toHaveBeenLastCalledWith('1', SEPTEMBRE_8_0H, SEPTEMBRE_14_23H)

expect(screen.getByText('dimanche 11 septembre')).toBeInTheDocument()
Expand Down
2 changes: 1 addition & 1 deletion tests/services/rendez-vous.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('RendezVousApiService', () => {
const dateFin = DateTime.fromISO('2022-09-07T23:59:59.999+02:00')

// When
const actual = await rendezVousService.getRendezVousConseillerClientSide(
const actual = await rendezVousService.getRendezVousConseiller(
accessToken,
dateDebut,
dateFin
Expand Down

0 comments on commit ad71615

Please sign in to comment.