Skip to content

Commit

Permalink
Use ubehandletStatus object in check
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed Oct 12, 2023
1 parent 4a356eb commit 50a2eca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/data/personoversiktHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ import { minutesToMillis } from '@/utils/timeUtils';
import { useMemo } from 'react';
import { PERSONOVERSIKT_ROOT } from '@/apiConstants';

type UbehandletKey = keyof PersonOversiktUbehandletStatusDTO;

const isUbehandlet = (ubehandletStatus: PersonOversiktUbehandletStatusDTO) => {
return Object.keys(ubehandletStatus).some((key) => {
return ubehandletStatus[key as UbehandletKey];
});
return Object.values(ubehandletStatus).some((value) => value);
};

const filteredPersonOversiktStatusList = (
personOversiktStatusList: PersonOversiktStatusDTO[]
): PersonOversiktStatusDTO[] => {
return personOversiktStatusList.filter((personOversiktStatus) =>
isUbehandlet(personOversiktStatus)
);
return personOversiktStatusList.filter((personOversiktStatus) => {
const ubehandletStatus = {
aktivitetskravVurderStansUbehandlet:
personOversiktStatus.aktivitetskravVurderStansUbehandlet,
behandlerdialogUbehandlet: personOversiktStatus.behandlerdialogUbehandlet,
dialogmotekandidat: personOversiktStatus.dialogmotekandidat,
dialogmotesvarUbehandlet: personOversiktStatus.dialogmotesvarUbehandlet,
huskelappActive: personOversiktStatus.huskelappActive,
motebehovUbehandlet: personOversiktStatus.motebehovUbehandlet,
oppfolgingsplanLPSBistandUbehandlet:
personOversiktStatus.oppfolgingsplanLPSBistandUbehandlet,
aktivitetskravActive: personOversiktStatus.aktivitetskravActive,
};
return isUbehandlet(ubehandletStatus);
});
};

export const personoversiktQueryKeys = {
Expand Down
30 changes: 30 additions & 0 deletions test/query/personoversiktHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,34 @@ describe('personoversiktHooks tests', () => {
expect(actual[0]).to.not.be.undefined;
expect(actual[0]?.fnr).to.eq(personoversiktEnhetMock[0]?.fnr);
});

it('contains only personer with ubehandlet oppgave', async () => {
stubModiaContext();
stubPersonoversikt();

const wrapper = ({ children }: never) => (
<NotificationProvider>
<AktivEnhetContext.Provider
value={{
aktivEnhet: aktivEnhetMock.aktivEnhet,
handleAktivEnhetChanged: () => void 0,
}}
>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</AktivEnhetContext.Provider>
</NotificationProvider>
);

const { result, waitFor } = renderHook(() => usePersonoversiktQuery(), {
wrapper,
});

await waitFor(() => result.current.isSuccess);

const actual: PersonOversiktStatusDTO[] = result.current.data || [];

expect(actual.length).to.be.lessThan(personoversiktEnhetMock.length);
});
});

0 comments on commit 50a2eca

Please sign in to comment.