-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1945: add unit test for card initialization with card params
- Loading branch information
Showing
1 changed file
with
108 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,19 +11,44 @@ import createCards, { CreateCardsError, CreateCardsResult } from '../../../cards | |
import deleteCards from '../../../cards/deleteCards' | ||
import { DynamicActivationCode, StaticVerificationCode } from '../../../generated/card_pb' | ||
import { Region } from '../../../generated/graphql' | ||
import { ProjectConfigProvider } from '../../../project-configs/ProjectConfigContext' | ||
import bayernConfig from '../../../project-configs/bayern/config' | ||
import { ProjectConfig } from '../../../project-configs/getProjectConfig' | ||
import koblenzConfig from '../../../project-configs/koblenz/config' | ||
import nuernbergConfig from '../../../project-configs/nuernberg/config' | ||
import showcaseConfig from '../../../project-configs/showcase/config' | ||
import downloadDataUri from '../../../util/downloadDataUri' | ||
import { AppToasterProvider } from '../../AppToaster' | ||
import useCardGenerator from './useCardGenerator' | ||
|
||
const wrapper = ({ children }: { children: ReactNode }) => ( | ||
<MemoryRouter> | ||
<AppToasterProvider> | ||
<ApolloProvider>{children}</ApolloProvider> | ||
</AppToasterProvider> | ||
const wrapper = ({ | ||
children, | ||
initialRoutes, | ||
projectConfig, | ||
}: { | ||
children: ReactNode | ||
projectConfig?: ProjectConfig | ||
initialRoutes?: string[] | ||
}) => ( | ||
<MemoryRouter initialEntries={initialRoutes}> | ||
<ProjectConfigProvider projectConfig={projectConfig ?? showcaseConfig}> | ||
<AppToasterProvider> | ||
<ApolloProvider>{children}</ApolloProvider> | ||
</AppToasterProvider> | ||
</ProjectConfigProvider> | ||
</MemoryRouter> | ||
) | ||
|
||
const withCustomWrapper = | ||
(initialRoutes: string[], projectConfig: ProjectConfig) => | ||
// @ts-expect-error any is okay here | ||
({ children }) => | ||
wrapper({ | ||
children, | ||
initialRoutes, | ||
projectConfig, | ||
}) | ||
|
||
jest.mock('../../../cards/PdfFactory', () => ({ | ||
...jest.requireActual('../../../cards/PdfFactory'), | ||
generatePdf: jest.fn(), | ||
|
@@ -134,4 +159,82 @@ describe('useCardGenerator', () => { | |
expect(result.current.cardGenerationStep).toBe('input') | ||
expect(result.current.cards).toEqual([]) | ||
}) | ||
|
||
it('should successfully initialize cards with searchParams for bavaria', async () => { | ||
mocked(createCards).mockReturnValueOnce(Promise.resolve(codes)) | ||
const { result } = renderHook(() => useCardGenerator({ region }), { | ||
wrapper: withCustomWrapper( | ||
[ | ||
'?Name=Thea+Test&Ablaufdatum=26.02.2028&MailNotification=thea.test%40gmail.com&applicationIdToMarkAsProcessed=1', | ||
], | ||
bayernConfig | ||
), | ||
}) | ||
|
||
expect(result.current.cards).toEqual([ | ||
{ | ||
expirationDate: { day: 26, isoMonth: 2, isoYear: 2028 }, | ||
extensions: { bavariaCardType: 'Standard', regionId: 0, emailNotification: '[email protected]' }, | ||
fullName: 'Thea Test', | ||
id: expect.any(Number), | ||
}, | ||
]) | ||
}) | ||
|
||
it('should successfully initialize cards with searchParams for koblenz', async () => { | ||
mocked(createCards).mockReturnValueOnce(Promise.resolve(codes)) | ||
const { result } = renderHook(() => useCardGenerator({ region }), { | ||
wrapper: withCustomWrapper(['?Name=Karla Koblenz&Referenznummer=123K&Geburtsdatum=10.06.2003'], koblenzConfig), | ||
}) | ||
|
||
expect(result.current.cards).toEqual([ | ||
{ | ||
expirationDate: { day: 26, isoMonth: 2, isoYear: 2026 }, | ||
extensions: { | ||
birthday: { | ||
day: 10, | ||
isoMonth: 6, | ||
isoYear: 2003, | ||
}, | ||
koblenzReferenceNumber: '123K', | ||
}, | ||
fullName: 'Karla Koblenz', | ||
id: expect.any(Number), | ||
}, | ||
]) | ||
}) | ||
|
||
it('should successfully initialize cards with searchParams for nuernberg', async () => { | ||
mocked(createCards).mockReturnValueOnce(Promise.resolve(codes)) | ||
const { result } = renderHook(() => useCardGenerator({ region }), { | ||
wrapper: withCustomWrapper( | ||
[ | ||
'?Name=Thea+Test&Ablaufdatum=03.3.2026&Geburtsdatum=01.01.2000&Passnummer=12345678&Pass-ID=123&Adresszeile+1=Teststraße+3&Adresszeile+2=EG+Rechts&PLZ=86111&Ort=Musterstadt', | ||
], | ||
nuernbergConfig | ||
), | ||
}) | ||
|
||
expect(result.current.cards).toEqual([ | ||
{ | ||
expirationDate: { day: 3, isoMonth: 3, isoYear: 2026 }, | ||
extensions: { | ||
birthday: { | ||
day: 1, | ||
isoMonth: 1, | ||
isoYear: 2000, | ||
}, | ||
addressLine1: 'Teststraße 3', | ||
addressLine2: 'EG Rechts', | ||
addressLocation: 'Musterstadt', | ||
addressPlz: '86111', | ||
nuernbergPassId: 123, | ||
regionId: 0, | ||
startDay: { day: 26, isoMonth: 2, isoYear: 2025 }, | ||
}, | ||
fullName: 'Thea Test', | ||
id: expect.any(Number), | ||
}, | ||
]) | ||
}) | ||
}) |