Skip to content

Commit 1738cea

Browse files
committed
Tests #57
1 parent a575936 commit 1738cea

File tree

4 files changed

+4712
-2705
lines changed

4 files changed

+4712
-2705
lines changed

test/Client.test.js

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,316 @@ describe("FHIR.client", () => {
134134
}
135135
});
136136

137+
describe("patient.request", () => {
138+
describe("rejects with no patient", () => {
139+
crossPlatformTest(async (env) => {
140+
const client = new Client(env, {
141+
serverUrl: mockUrl,
142+
tokenResponse: {}
143+
});
144+
await expect(client.patient.request("Observation")).to.reject(
145+
Error, "Patient is not available"
146+
);
147+
});
148+
});
149+
150+
describe("rejects for not supported resource types", () => {
151+
crossPlatformTest(async (env) => {
152+
const client = new Client(env, {
153+
serverUrl: mockUrl,
154+
tokenResponse: {
155+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
156+
}
157+
});
158+
159+
// Mock the conformance statement
160+
mockServer.mock({
161+
headers: { "content-type": "application/json" },
162+
status: 200,
163+
body: {}
164+
});
165+
166+
mockServer.mock({
167+
headers: { "content-type": "application/json" },
168+
status: 200,
169+
body: {
170+
resourceType: "Observation",
171+
id: "whatever"
172+
}
173+
});
174+
175+
await expect(client.patient.request("Observation")).to.reject(
176+
Error,
177+
"Resource not supported"
178+
);
179+
});
180+
});
181+
182+
describe("rejects if a search param cannot be determined", () => {
183+
crossPlatformTest(async (env) => {
184+
const client = new Client(env, {
185+
serverUrl: mockUrl,
186+
tokenResponse: {
187+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
188+
}
189+
});
190+
191+
// Mock the conformance statement
192+
mockServer.mock({
193+
headers: { "content-type": "application/json" },
194+
status: 200,
195+
body: {
196+
rest: [{
197+
resource: [{
198+
type: "Observation"
199+
}]
200+
}]
201+
}
202+
});
203+
204+
mockServer.mock({
205+
headers: { "content-type": "application/json" },
206+
status: 200,
207+
body: {
208+
resourceType: "Observation",
209+
id: "whatever"
210+
}
211+
});
212+
213+
await expect(client.patient.request("Observation")).to.reject(
214+
Error,
215+
"No search parameters supported for \"Observation\" on this FHIR server"
216+
);
217+
});
218+
});
219+
220+
describe("rejects if a resource is not in the patient compartment", () => {
221+
crossPlatformTest(async (env) => {
222+
const client = new Client(env, {
223+
serverUrl: mockUrl,
224+
tokenResponse: {
225+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
226+
}
227+
});
228+
229+
// Mock the conformance statement
230+
mockServer.mock({
231+
headers: { "content-type": "application/json" },
232+
status: 200,
233+
body: {
234+
rest: [{
235+
resource: [{
236+
type: "Test"
237+
}]
238+
}]
239+
}
240+
});
241+
242+
mockServer.mock({
243+
headers: { "content-type": "application/json" },
244+
status: 200,
245+
body: {
246+
resourceType: "Test",
247+
id: "whatever"
248+
}
249+
});
250+
251+
await expect(client.patient.request("Test")).to.reject(
252+
Error,
253+
"Cannot filter \"Test\" resources by patient"
254+
);
255+
});
256+
});
257+
258+
describe("works as expected with a string URL", () => {
259+
crossPlatformTest(async (env) => {
260+
const client = new Client(env, {
261+
serverUrl: mockUrl,
262+
tokenResponse: {
263+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
264+
}
265+
});
266+
267+
// Mock the conformance statement
268+
mockServer.mock({
269+
headers: { "content-type": "application/json" },
270+
status: 200,
271+
body: {
272+
rest: [{
273+
resource: [{
274+
type: "Observation",
275+
searchParam: [
276+
{ name: "patient" }
277+
]
278+
}]
279+
}]
280+
}
281+
});
282+
283+
mockServer.mock({
284+
headers: { "content-type": "application/json" },
285+
status: 200,
286+
body: {
287+
resourceType: "Observation",
288+
id: "whatever"
289+
}
290+
});
291+
292+
await client.patient.request("Observation");
293+
});
294+
});
295+
296+
describe("works as expected with URL instance", () => {
297+
crossPlatformTest(async (env) => {
298+
const client = new Client(env, {
299+
serverUrl: mockUrl,
300+
tokenResponse: {
301+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
302+
}
303+
});
304+
305+
// Mock the conformance statement
306+
mockServer.mock({
307+
headers: { "content-type": "application/json" },
308+
status: 200,
309+
body: {
310+
rest: [{
311+
resource: [{
312+
type: "Observation",
313+
searchParam: [
314+
{ name: "patient" }
315+
]
316+
}]
317+
}]
318+
}
319+
});
320+
321+
mockServer.mock({
322+
headers: { "content-type": "application/json" },
323+
status: 200,
324+
body: {
325+
resourceType: "Observation",
326+
id: "whatever"
327+
}
328+
});
329+
330+
await client.patient.request(new URL("Observation", mockUrl));
331+
});
332+
});
333+
334+
describe("works as expected with request options", () => {
335+
crossPlatformTest(async (env) => {
336+
const client = new Client(env, {
337+
serverUrl: mockUrl,
338+
tokenResponse: {
339+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
340+
}
341+
});
342+
343+
// Mock the conformance statement
344+
mockServer.mock({
345+
headers: { "content-type": "application/json" },
346+
status: 200,
347+
body: {
348+
rest: [{
349+
resource: [{
350+
type: "Observation",
351+
searchParam: [
352+
{ name: "patient" }
353+
]
354+
}]
355+
}]
356+
}
357+
});
358+
359+
mockServer.mock({
360+
headers: { "content-type": "application/json" },
361+
status: 200,
362+
body: {
363+
resourceType: "Observation",
364+
id: "whatever"
365+
}
366+
});
367+
368+
await client.patient.request({ url: "Observation" });
369+
});
370+
});
371+
372+
describe("works if the resource is Patient and _id param is supported", () => {
373+
crossPlatformTest(async (env) => {
374+
const client = new Client(env, {
375+
serverUrl: mockUrl,
376+
tokenResponse: {
377+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
378+
}
379+
});
380+
381+
// Mock the conformance statement
382+
mockServer.mock({
383+
headers: { "content-type": "application/json" },
384+
status: 200,
385+
body: {
386+
rest: [{
387+
resource: [{
388+
type: "Patient",
389+
searchParam: [
390+
{ name: "_id" }
391+
]
392+
}]
393+
}]
394+
}
395+
});
396+
397+
mockServer.mock({
398+
headers: { "content-type": "application/json" },
399+
status: 200,
400+
body: {
401+
resourceType: "Patient",
402+
id: "whatever"
403+
}
404+
});
405+
406+
await client.patient.request("Patient");
407+
});
408+
});
409+
410+
describe("rejects if the resource is Patient and _id param is not supported", () => {
411+
crossPlatformTest(async (env) => {
412+
const client = new Client(env, {
413+
serverUrl: mockUrl,
414+
tokenResponse: {
415+
patient: "2e27c71e-30c8-4ceb-8c1c-5641e066c0a4"
416+
}
417+
});
418+
419+
// Mock the conformance statement
420+
mockServer.mock({
421+
headers: { "content-type": "application/json" },
422+
status: 200,
423+
body: {
424+
rest: [{
425+
resource: [{
426+
type: "Patient",
427+
searchParam: []
428+
}]
429+
}]
430+
}
431+
});
432+
433+
mockServer.mock({
434+
headers: { "content-type": "application/json" },
435+
status: 200,
436+
body: {
437+
resourceType: "Patient",
438+
id: "whatever"
439+
}
440+
});
441+
442+
await expect(client.patient.request("Patient")).to.reject();
443+
});
444+
});
445+
});
446+
137447
describe("encounter.read", () => {
138448
describe("rejects with no encounter", () => {
139449
crossPlatformTest(async (env) => {

0 commit comments

Comments
 (0)