From 311c69f7706cc843fb4b78ce8e219c6f1e7478d5 Mon Sep 17 00:00:00 2001 From: Simon Priet Date: Wed, 8 Sep 2021 10:02:38 +0200 Subject: [PATCH] feat(Cypress): :white_check_mark: implemented JWT retrieval, binaryTest --- cypress/integration/api.spec.js | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 cypress/integration/api.spec.js diff --git a/cypress/integration/api.spec.js b/cypress/integration/api.spec.js new file mode 100644 index 00000000..50dced03 --- /dev/null +++ b/cypress/integration/api.spec.js @@ -0,0 +1,81 @@ +/// + +describe("it test the api", () => { + let jsonWebToken = ""; + const apiUrl = "https://fhir-api.public.post-prod.lifen.fr" + + it("I have a JWT", () => { + + cy.request({ + url: "https://lifen-post-prod.eu.auth0.com/oauth/token", + method: "POST", + body: { + client_id: 'szVsMPaDPUdwqngGiLoHfXFT5XCYPFcy', + client_secret: 'sMp2PB-QWBZupCB4IXJrWDJ-7tlpUl09vQ2tMKdy049He7-g93ofbXz7ESlAc82B', + audience: 'post-prod-apis', + grant_type: 'client_credentials', + } + }).its('body').then((body) => { + jsonWebToken = body.access_token; + //cy.log(json_web_token); + expect(jsonWebToken).to.not.be.empty; + }); + + }); + + it("I have a the document #1615660", () => { + cy.request({ + url:`${apiUrl}/fhir/Binary/1615660`, + method:'GET', + headers: { + "Authorization" : `Bearer ${jsonWebToken}`, + "contet-type": "application/json", + "Prefer": "return=presentation" + } + }).then((response) => { + expect(response.status).to.eq(200); + expect(response.headers["content-type"]).to.eq("application/pdf"); + }) + }); + + it("I prepare the DocumentReference", () => { + cy.request({ + url:`${apiUrl}/fhir/DocumentReference`, + method:'POST', + headers: { + "Authorization" : `Bearer ${jsonWebToken}`, + "contet-type": "application/json", + "Prefer": "return=presentation" + }, + body: { + "status": "current", + "docStatus": "final", + "type": { + "coding": [ + { + "system": "http://loinc.org", + "code": "34109-9", + "display": "Document médical" + } + ] + }, + "indexed": "2021-02-11T09:25:39Z", + "description": "aelgain-copiepatient.pdf", + "content": [ + { + "attachment": { + "contentType": "application/pdf", + "url": "Binary/1615660", + "title": "aelgain-copiepatient.pdf" + } + } + ], + "resourceType": "DocumentReference" + } + }).then(response => { + + }); + + + }); +});