Skip to content

Commit

Permalink
🚧 progress: Add more tests for eid drag-and-drop.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Jan 7, 2025
1 parent 62fa689 commit d92d53f
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 18 deletions.
43 changes: 35 additions & 8 deletions imports/api/_dev/populate/eids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,62 @@ export const newEidData = makeTemplate({
});

export const exampleEidXML = (options?: {
nationalnumber?: string;
dateofbirth?: string;
name?: string;
firstname?: string;
middlenames?: string;
nationality?: string;
placeofbirth?: string;
gender?: 'male' | 'female';
photo?: string;
streetandnumber?: string;
zip?: string;
municipality?: string;
}) => {
const {name, firstname, middlenames, nationality, placeofbirth} = {
const {
nationalnumber,
dateofbirth,
name,
firstname,
middlenames,
nationality,
placeofbirth,
gender,
photo,
streetandnumber,
zip,
municipality,
} = {
nationalnumber: '70010112345',
dateofbirth: '19700101',
name: 'Name',
firstname: 'First Name',
middlenames: 'M',
nationality: 'Belge',
placeofbirth: 'Bruxelles',
gender: 'female',
photo: randomPNGBase64(),
streetandnumber: 'Rue de la montagne 58 ',
zip: '1000',
municipality: 'Bruxelles',
...options,
};
// TODO: Generalizes and escape values.
return `<?xml version="1.0" encoding="UTF-8"?>
<eid version="4.3" graphpersoversion="00">
<identity
nationalnumber="70010112345"
dateofbirth="19700101"
gender="male"
nationalnumber="${nationalnumber}"
dateofbirth="${dateofbirth}"
gender="${gender}"
specialstatus="NO_STATUS"
>
<name>${name}</name>
<firstname>${firstname}</firstname>
<middlenames>${middlenames}</middlenames>
<nationality>${nationality}</nationality>
<placeofbirth>${placeofbirth}</placeofbirth>
<photo>${randomPNGBase64()}</photo>
<photo>${photo}</photo>
</identity>
<card
documenttype="belgian_citizen"
Expand All @@ -95,9 +122,9 @@ export const exampleEidXML = (options?: {
<deliverymunicipality>Bruxelles</deliverymunicipality>
</card>
<address>
<streetandnumber>Rue de la montagne 58 </streetandnumber>
<zip>1000</zip>
<municipality>Bruxelles</municipality>
<streetandnumber>${streetandnumber}</streetandnumber>
<zip>${zip}</zip>
<municipality>${municipality}</municipality>
</address>
<certificates>
<root>ROOT</root>
Expand Down
2 changes: 1 addition & 1 deletion imports/api/eidParseXML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import schema from '../lib/schema';
import {type EidFields} from './collection/eids';

const text = schema.object({
_text: schema.string(),
_text: schema.string().optional(),
});

export const eidXml = schema.object({
Expand Down
116 changes: 107 additions & 9 deletions test/app/client/patient/eids.app-tests.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {fireEvent} from '@testing-library/dom';

import call from '../../../../imports/api/endpoint/call';
import insert from '../../../../imports/api/endpoint/patients/insert';
import createUserWithPassword from '../../../../imports/api/user/createUserWithPassword';

import {exampleEidXML} from '../../../../imports/api/_dev/populate/eids';
import {newPatientFormData} from '../../../../imports/api/_dev/populate/patients';

import {
client,
randomPassword,
randomUserId,
} from '../../../../imports/_test/fixtures';
import {
setupApp,
createUserWithPasswordAndLogin,
searchForPatient,
} from '../fixtures';
import {setupApp, searchForPatient} from '../fixtures';

type Item = string | File;

Expand Down Expand Up @@ -95,7 +96,7 @@ client(__filename, () => {
const username = randomUserId();
const password = randomPassword();
const app = setupApp();
await createUserWithPasswordAndLogin(app, username, password);
await createUserWithPassword(username, password);

const {findByRole, findByText, user} = app;

Expand All @@ -112,7 +113,7 @@ client(__filename, () => {
const username = randomUserId();
const password = randomPassword();
const app = setupApp();
await createUserWithPasswordAndLogin(app, username, password);
await createUserWithPassword(username, password);

const {findByRole, user} = app;

Expand All @@ -132,8 +133,105 @@ client(__filename, () => {
await findByRole('button', {name: 'Create a new patient'}),
);

await searchForPatient(app, `Jane Doe`, {
name: `Jane Doe`,
await searchForPatient(app, 'Jane Doe', {
name: 'Jane Doe',
});
});

it('should allow to open a patient from eid', async () => {
const username = randomUserId();
const password = randomPassword();
const app = setupApp();
await createUserWithPassword(username, password);

const {findAllByRole, findByRole, findByText, user} = app;

const sex = 'female';

const formData = newPatientFormData({sex});

const {
niss,
firstname,
lastname,
birthdate,
photo,
streetandnumber,
zip,
municipality,
} = formData;

const patientId = await call(insert, formData);

const eidXML = exampleEidXML({
nationalnumber: niss,
dateofbirth: birthdate.replaceAll('-', ''),
photo,
name: lastname,
gender: sex,
firstname,
streetandnumber,
zip,
municipality,
});

await dropFiles(app, eidXML);

await findByRole('heading', {name: 'Select record to work with.'});

const buttons = await findAllByRole('button', {
name: new RegExp(` ${lastname} ${firstname} `, 'i'),
});
await user.click(buttons[0]!);

await user.click(await findByRole('button', {name: 'Next (1)'}));

await user.click(
await findByText(/^open$/i, {selector: 'button:not([disabled])'}),
);

await findByRole('heading', {name: `/patient/${patientId}`});
});

it('should allow to update a patient from eid', async () => {
const username = randomUserId();
const password = randomPassword();
const app = setupApp();
await createUserWithPassword(username, password);

const {findAllByRole, findByRole, findByText, user} = app;

const formData = newPatientFormData({
streetandnumber: 'streetandnumber-initial',
});

const {firstname, lastname} = formData;

const patientId = await call(insert, formData);

const eidXML = exampleEidXML({
name: lastname,
firstname,
streetandnumber: 'streetandnumber-eid',
});

await dropFiles(app, eidXML);

await findByRole('heading', {name: 'Select record to work with.'});

const buttons = await findAllByRole('button', {
name: new RegExp(` ${lastname} ${firstname} `, 'i'),
});
await user.click(buttons[0]!);

await user.click(await findByRole('button', {name: 'Next (1)'}));

await user.click(await findByRole('button', {name: 'Next'}));

await user.click(await findByRole('button', {name: 'Update'}));

await findByRole('heading', {name: `/patient/${patientId}`});

await findByText('streetandnumber-eid');
});
});

0 comments on commit d92d53f

Please sign in to comment.