Skip to content

Commit

Permalink
Rydd videre i mocks (#22)
Browse files Browse the repository at this point in the history
* Rydd videre i mocks

* Fullfør SMS-mocks

* Begynn å flytte forespørsel-mock til msw

* Flytt mer av mockene

* Slett siste rester av kandidatmock, mock mocken for resten
  • Loading branch information
kjesvale authored Aug 10, 2023
1 parent ab7914f commit da838b1
Show file tree
Hide file tree
Showing 46 changed files with 428 additions and 2,321 deletions.
115 changes: 106 additions & 9 deletions mock/foresporsel-om-deling-av-cv-api/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,112 @@
import { addDays, startOfDay, subDays } from 'date-fns';
import { KandidatCv } from 'felles/domene/kandidat/Kandidat';
import { AktørId } from 'felles/domene/kandidatliste/KandidatIKandidatliste';
import Kandidatliste from 'felles/domene/kandidatliste/Kandidatliste';
import { rest } from 'msw';
import { api } from '../../src/felles/api';
import { Svarstatistikk } from '../../src/forside/statistikk/useSvarstatistikk';
import {
ForespørselDeltStatus,
ForespørselOmDelingAvCv,
IdentType,
TilstandPåForespørsel,
} from '../../src/kandidat/kandidatliste/knappe-rad/forespørsel-om-deling-av-cv/Forespørsel';
import { mockAlleKandidatCv } from '../kandidat-api/mockKandidatCv';
import { mockAlleKandidatlister } from '../kandidat-api/mockKandidatliste';
import { mockVeileder } from '../meg/mock';
import { mockStilling } from '../stilling-api/mockStilling';

export const forespørselOmDelingAvCvMock = [
rest.get(`${api.forespørselOmDelingAvCv}/foresporsler/:stillingsId`, (req, res, ctx) => {
const kandidatliste = mockAlleKandidatlister.find(
(liste) => liste.stillingId === req.params.stillingsId
);

if (!kandidatliste) {
return res(ctx.json([]));
}

const forespørslerForKandidatliste = opprettMockForespørslerOmDelingAvCv(
kandidatliste,
mockVeileder
);

return res(ctx.json(forespørslerForKandidatliste));
}),

rest.get(`${api.forespørselOmDelingAvCv}/foresporsler/kandidat/:aktorId`, (req, res, ctx) => {
const kandidat = mockAlleKandidatCv.find((cv) => cv.aktorId === req.params.aktorId);

if (!kandidat) {
return res(ctx.status(404));
}

const forespørslerForKandidat = opprettMockForespørslerOmDelingAvCvForKandidat(
kandidat,
mockStilling.uuid,
mockVeileder
);

return res(ctx.json(forespørslerForKandidat));
}),

rest.post(`${api.forespørselOmDelingAvCv}/foresporsler`, (_, res, ctx) => res(ctx.status(201))),
rest.post(`${api.forespørselOmDelingAvCv}/foresporsler/kandidat/:aktorId`, (_, res, ctx) =>
res(ctx.status(201))
),

rest.get(`${api.forespørselOmDelingAvCv}/statistikk`, (req, res, ctx) => {
const searchParams = req.url.searchParams;
const navKontor = searchParams.get('navKontor');

return res(ctx.json(hentForespørslerstatistikk(navKontor)));
}),
];

export const opprettMockForespørslerOmDelingAvCv = (
kandidatliste: Kandidatliste,
eier: any
): Record<AktørId, ForespørselOmDelingAvCv[]> => ({
[kandidatliste.kandidater[0].aktørid]: [
opprettMockForespørselOmDelingAvCv(
kandidatliste.kandidater[0].aktørid,
kandidatliste.stillingId,
eier
),
],
});

export const opprettMockForespørslerOmDelingAvCvForKandidat = (
kandidat: KandidatCv,
stillingsId: string,
eier: any
): ForespørselOmDelingAvCv[] => [
opprettMockForespørselOmDelingAvCv(kandidat.aktorId, stillingsId, eier),
];

const opprettMockForespørselOmDelingAvCv = (
aktørId: string,
stillingsId: string,
eier: any
): ForespørselOmDelingAvCv => ({
aktørId,
stillingsId,
deltAv: eier.navIdent,
navKontor: eier.navKontor,
deltTidspunkt: subDays(new Date(), 10).toISOString(),
deltStatus: ForespørselDeltStatus.Sendt,
svarfrist: startOfDay(addDays(new Date(), 5)).toISOString(),
tilstand: TilstandPåForespørsel.HarSvart,

svar: {
harSvartJa: false,
svarTidspunkt: startOfDay(subDays(new Date(), 1)).toISOString(),
svartAv: {
ident: eier.ident,
identType: IdentType.NavIdent,
},
},
});

export const hentForespørslerstatistikk = (navKontor?: string): Svarstatistikk => {
return navKontor === '0239'
Expand All @@ -17,12 +123,3 @@ export const hentForespørslerstatistikk = (navKontor?: string): Svarstatistikk
antallVenterPåSvar: 0,
};
};

export const forespørselOmDelingAvCvMock = [
rest.get(`${api.forespørselOmDelingAvCv}/statistikk`, (req, res, ctx) => {
const searchParams = req.url.searchParams;
const navKontor = searchParams.get('navKontor');

return res(ctx.json(hentForespørslerstatistikk(navKontor)));
}),
];
75 changes: 73 additions & 2 deletions mock/kandidat-api/mock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { rest } from 'msw';
import { ResponseFunction, RestContext, RestRequest, rest } from 'msw';
import { api } from '../../src/felles/api';
import { LagreKandidaterDto } from '../../src/kandidatsok/kandidatliste/LagreKandidaterIMineKandidatlisterModal';
import { mockAlleKandidatCv } from './mockKandidatCv';
import { mockAlleKandidatlister } from './mockKandidatliste';
import { mockAlleKandidatlister, opprettMockKandidatlisteForKandidat } from './mockKandidatliste';
import { mockMineKandidatlister } from './mockMineKandidatlister';

const todo = (req: RestRequest, res: ResponseFunction, ctx: RestContext) =>
res(ctx.status(500, 'Mock er ikke implementert'));

export const kandidatApiMock = [
rest.get(`${api.kandidat}/veileder/kandidatlister`, (_, res, ctx) =>
res(ctx.json(mockMineKandidatlister))
Expand Down Expand Up @@ -65,4 +68,72 @@ export const kandidatApiMock = [

return res(kandidatCv ? ctx.json(kandidatCv) : ctx.status(404));
}),

rest.get(`${api.kandidat}/veileder/kandidater/:kandidatnr/listeoversikt`, (req, res, ctx) => {
const kandidatlister = mockAlleKandidatlister.filter((liste) =>
liste.kandidater.some((kandidat) => kandidat.kandidatnr === req.params.kandidatnr)
);

const kandidatlisterMedKandidaten = kandidatlister.map((liste) =>
opprettMockKandidatlisteForKandidat(
liste,
liste.kandidater.find((kandidat) => kandidat.kandidatnr === req.params.kandidatnr)
)
);

return res(ctx.json(kandidatlisterMedKandidaten));
}),

rest.put(`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/eierskap`, todo),

rest.get(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/notater`,
todo
),

rest.post(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/notater`,
todo
),

rest.all(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/notater/:notatId`,
todo
),

rest.put(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/status`,
todo
),

rest.put(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/utfall`,
todo
),

rest.put(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/kandidater/:kandidatnr/arkivert`,
todo
),

rest.post(`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/deltekandidater`, todo),

rest.get(`${api.kandidat}/veileder/kandidater/navn`, todo),

rest.post(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/formidlingeravusynligkandidat`,
todo
),

rest.put(
`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/formidlingeravusynligkandidat/:formidlingId/utfall`,
todo
),

rest.put(`${api.kandidat}/veileder/kandidatlister/:kandidatlisteId/status`, todo),

rest.put(
`${api.kandidat}/veileder/kandidat/arbeidsgiverliste/:kandidatlisteId/:kandidatnummer`,
todo
),
];
26 changes: 26 additions & 0 deletions mock/kandidat-api/mockKandidatliste.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import KandidatIKandidatliste from 'felles/domene/kandidatliste/KandidatIKandidatliste';
import Kandidatliste, {
KanSletteKandidatliste,
KandidatlisteForKandidat,
Kandidatlistestatus,
} from 'felles/domene/kandidatliste/Kandidatliste';
import { Stillingskategori } from 'felles/domene/stilling/Stilling';
Expand Down Expand Up @@ -57,4 +59,28 @@ export const mockKandidatlisteMedStilling: Kandidatliste = {
},
};

export const opprettMockKandidatlisteForKandidat = (
kandidatliste: Kandidatliste,
kandidat: KandidatIKandidatliste
): KandidatlisteForKandidat => ({
uuid: kandidatliste.kandidatlisteId,
tittel: kandidatliste.tittel,
organisasjonReferanse: kandidatliste.organisasjonReferanse,
organisasjonNavn: kandidatliste.organisasjonNavn,
stillingId: kandidatliste.stillingId,
antallStillinger: kandidatliste.antallStillinger,
status: kandidat.status,
utfall: kandidat.utfall,

kandidatnr: kandidat.kandidatnr,
fornavn: kandidat.fornavn,
etternavn: kandidat.etternavn,
lagtTilTidspunkt: kandidat.lagtTilTidspunkt,
lagtTilAvIdent: kandidat.lagtTilAv.ident,
lagtTilAvEpost: 'epost',
lagtTilAvNavn: kandidat.lagtTilAv.navn,
utfallsendringer: kandidat.utfallsendringer,
slettet: kandidat.arkivert,
});

export const mockAlleKandidatlister = [mockKandidatlisteMedStilling, mockKandidatlisteUtenStilling];
9 changes: 8 additions & 1 deletion mock/meg/mock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { rest } from 'msw';
import { api } from '../../src/felles/api';

export const mockMeg = {
export const mockVeileder = {
fornavn: 'Varg',
etternavn: 'Veileder',
navKontor: '1209',
navIdent: 'Z994161',
};

export const mockMeg = {
navIdent: mockVeileder.navIdent,
};

export const innloggetBrukerMock = [
rest.get(api.innloggetBruker, (_, res, ctx) => res(ctx.json(mockMeg))),
];
14 changes: 9 additions & 5 deletions mock/setup.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { setupWorker } from 'msw';
import { modiaContextHolderMock } from './modiacontextholder/mock';
import { innloggetBrukerMock } from './meg/mock';
import { forespørselOmDelingAvCvMock } from './foresporsel-om-deling-av-cv-api/mock';
import { kandidatApiMock } from './kandidat-api/mock';
import { kandidatsøkMock } from './kandidatsok-proxy/mock';
import { forespørselOmDelingAvCvMock } from './foresporsel-om-deling-av-cv-api/mock';
import { innloggetBrukerMock } from './meg/mock';
import { modiaContextHolderMock } from './modiacontextholder/mock';
import { presenterteKandidaterApiMock } from './presenterte-kandidater-api/mock';
import { smsApiMock } from './sms-api/mock';
import { statistikkApiMock } from './statistikk-api/mock';
import { stillingApiMock } from './stilling-api/mock';
import { stillingssøkMock } from './stillingssok-proxy/mock';
import { presenterteKandidaterApiMock } from './presenterte-kandidater-api/mock';
import { synlighetApiMock } from './synlighet-api/mock';

const handlers = [
...innloggetBrukerMock,
...kandidatApiMock,
...statistikkApiMock,
...forespørselOmDelingAvCvMock,
...stillingApiMock,
...presenterteKandidaterApiMock,
...smsApiMock,
...synlighetApiMock,
...(import.meta.env.VITE_MOCK_MODIA ? modiaContextHolderMock : []),
...(import.meta.env.VITE_MOCK_AIVEN ? kandidatsøkMock : []),
...(import.meta.env.VITE_MOCK_AIVEN ? stillingssøkMock : []),
...presenterteKandidaterApiMock,
];

const worker = setupWorker(...handlers);
Expand Down
41 changes: 41 additions & 0 deletions mock/sms-api/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Sms, SmsStatus } from 'felles/domene/sms/Sms';
import { rest } from 'msw';
import { api } from '../../src/felles/api';
import { mockKandidatlisteMedStilling } from '../kandidat-api/mockKandidatliste';
import { mockMeg } from '../meg/mock';

export const smsApiMock = [
rest.get(`${api.sms}/:kandidatlisteId`, (req, res, ctx) => {
const sms = mockSms.filter((sms) => sms.kandidatlisteId === req.params.kandidatlisteId);

if (!sms) {
return res(ctx.status(404));
} else {
return res(ctx.json(sms));
}
}),

rest.get(`${api.sms}/fnr/:fnr`, (req, res, ctx) => {
const sms = mockSms.filter((sms) => sms.fnr === req.params.fnr);

if (!sms) {
return res(ctx.status(404));
} else {
return res(ctx.json(sms));
}
}),

rest.post(`${api.sms}`, (_, res, ctx) => res(ctx.status(201))),
];

const mockSms: Sms[] = [
{
id: 1,
kandidatlisteId: mockKandidatlisteMedStilling.kandidatlisteId,
fnr: '123', //mockKandidatlisteMedStilling.kandidater[0].fodselsnr,
opprettet: new Date().toISOString(),
sendt: new Date().toISOString(),
status: SmsStatus.Sendt,
navIdent: mockMeg.navIdent,
},
];
9 changes: 7 additions & 2 deletions mock/stilling-api/mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { rest } from 'msw';
import { mockStilling } from './mockStilling';
import { ResponseFunction, RestContext, RestRequest, rest } from 'msw';
import { api } from '../../src/felles/api';
import { mockPutStandardsøk, mockStandardsøk } from './mockStandardsøk';
import { mockStilling } from './mockStilling';

const todo = (req: RestRequest, res: ResponseFunction, ctx: RestContext) =>
res(ctx.status(500, 'Mock er ikke implementert'));

export const stillingApiMock = [
rest.get(`${api.stilling}/rekrutteringsbistandstilling/:stillingsId`, (_, res, ctx) =>
Expand All @@ -13,4 +16,6 @@ export const stillingApiMock = [
rest.put(`${api.stilling}/standardsok`, (req, res, ctx) =>
res(ctx.json(mockPutStandardsøk(req)))
),

rest.post(`${api.stilling}/search-api/underenhet/_search`, todo),
];
9 changes: 9 additions & 0 deletions mock/synlighet-api/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { rest } from 'msw';
import { api } from '../../src/felles/api';

export const synlighetApiMock = [
rest.get(
`${api.synlighet}/evaluering/:fnr`,
(_, res, ctx) => res(ctx.status(500)) // TODO
),
];
Loading

0 comments on commit da838b1

Please sign in to comment.