feat(Cypress-Gherkin): Implemented the whole test in cypress and updated documentation accordingly

This commit is contained in:
Simon Priet
2021-09-08 12:25:55 +02:00
parent 68acc2a949
commit ed9a550d5e
12 changed files with 269 additions and 317 deletions

View File

@@ -1,208 +0,0 @@
/// <reference types="cypress" />
describe("it test the api", () => {
let jsonWebToken = "";
const apiUrl = "https://fhir-api.public.post-prod.lifen.fr";
let documentReferenceId, communicationRequestId, patientId = "";
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}`,
"Prefer": "return=representation"
}
}).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}`,
'content-type': 'application/json',
"Prefer": "return=representation"
},
json: true,
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) => {
expect(response.status).to.eq(201);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "DocumentReference");
expect(response.body).to.have.property('id');
documentReferenceId = response.body.id
});
//cy.log(documentReferenceId);
});
it("I prepare the CommunicationRequest", () => {
cy.request({
url: `${apiUrl}/fhir/CommunicationRequest`,
method: 'POST',
headers: {
authorization: `Bearer ${jsonWebToken}`,
'content-type': 'application/json',
"Prefer": "return=representation"
},
json: true,
body: {
"meta": {
"tag": [
{
"system": "http://lifen.fr/fhir/tag/verified/sender",
"code": "SENDER_VERIFIED",
"display": "Sender is verified and should not be changed."
},
{
"system": "http://lifen.fr/fhir/tag/processing/mode",
"code": "IMMEDIATE_MODE",
"display": "request should be treated in immediate mode"
},
{
"system": "http://lifen.fr/fhir/CodeSystem/Resource/Tag/PatientAutomaticResending",
"code": "NONE",
"display": "Patient communication should not be resent"
}
]
},
"status": "draft",
"category": [
{
"coding": [
{
"system": "http://lifen.fr/fhir/CodeSystem/communication-category",
"code": "MEDICAL_REPORT"
}
]
}
],
"priority": "routine",
"payload": [
{
"contentReference": {
"reference": `DocumentReference/${documentReferenceId}`
}
}
],
"sender": {
"extension": [
{
"url": "http://lifen.fr/fhir/StructureDefinition/Resource/Extension/Source",
"valueCode": "USER"
}
],
"reference": "Organization/2"
},
"requester": {
"agent": {
"extension": [
{
"url": "http://lifen.fr/fhir/StructureDefinition/communicationrequest-requester-user-uuid",
"valueString": "ea07d7c6-ff4b-43fc-9765-e4235886d30c"
}
],
"reference": "Organization/2"
}
},
"resourceType": "CommunicationRequest"
}
}).then((response) => {
expect(response.status).to.eq(201);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "CommunicationRequest");
expect(response.body).to.have.property('id');
expect(response.body).to.have.property('status', 'draft');
communicationRequestId = response.body.id
});
});
it("I fetch the CommunicationRequest's PatientId after waiting 10 sec for the IA to process it", () => {
cy.wait(10000);
// avec cypress-recurse, on surveille jusqu'a ce que l'IA ai finit son traitement ; plutot que d'attendre un temps arbitraire.
// import { recurse } from 'cypress-recurse' // a placer en début de fichier.
// recurse(() => cy.request(...), (response) => { expect(response.body).to.have.property('status', 'suspended') } ).then((response) => {...})
cy.request({
url: `${apiUrl}/fhir/CommunicationRequest/${communicationRequestId}`,
method: 'GET',
headers: {
authorization: `Bearer ${jsonWebToken}`
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "CommunicationRequest");
expect(response.body).to.have.property('id');
expect(response.body).to.have.property('status', 'suspended');
expect(response.body).to.have.property('subject');
expect(response.body).to.have.property('recipient');
expect(response.body.subject).to.have.property('reference');
let patient = response.body.subject.reference;
patientId = patient.split("/")[1];
});
});
it("I get the Patient", () => {
cy.request({
url: `${apiUrl}/fhir/Patient/${patientId}`,
method: 'GET',
headers: {
authorization: `Bearer ${jsonWebToken}`
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "Patient");
expect(response.body).to.have.property('id', patientId);
});
});
});

View File

@@ -1,7 +1,8 @@
Feature: Send a document that is ready
As a practiciant, I can send mails that i have prepared
Scenario: Send a document
Scenario: Send a prepared document
Given I am connected to my mailbox
And I have a document ready to send
When I send the mail

View File

@@ -1,77 +0,0 @@
/// <reference types="cypress" />
context('The login page', () => {
describe.skip('Test the login page', () => {
it('Access the webpage', function() {
cy.visit('/login');
cy.get('#email').should("have.attr", "type", "email");
cy.get('#password').should("have.attr", "type", "password");
//cy.get('#password').type(mdp);
});
it('Log a malformed email', function() {
cy.visit('/login');
cy.get('#email').type("not an email");
cy.get('#password').type("somepasseword {enter}");
cy.url().should('include', 'login?');
});
it('Log an unexisting user', function() {
cy.visit('/login');
cy.get('#email').type("toto@yopmail.com");
cy.get('#password').type("somepasseword {enter}");
cy.get('#error-message').should("have.class", "alert alert-danger").should("be.visible");
});
});
/* describe("It send an SMS", function() {
it('Log the candidate user', function(){
cy.visit('/');
cy.get('#email').type("candidature-qa@example.org");
cy.get('#password').type("kHwWawhH5ADNuFb");
cy.get('#continueButton').click();
cy.mailosaurGetMessage(serverId, {
sentTo: smsNumber
}).as('sms');
cy.wait(10000).then(() => {
cy.get('#validateButton').click();
});
});
});
*/
});
context("The inbox page", function() {
describe("It check the inbox content", function() {
before(() => {
cy.visit('/');
cy.get('#email').type("candidature-qa@example.org");
cy.get('#password').type("kHwWawhH5ADNuFb");
cy.get('#continueButton').click();
cy.wait(20000).then(() => {
cy.get('#validateButton').click();
});
});
it("It load the inbox page of a valid user", ()=> {
cy.visit("/request");
cy.get("#dashboard-dropzone tr:first-child td").eq(1).click();
cy.get("#sending-button").click();
});
it("It checks for messages in the inbox", () => {
});
it("Open the message for data that has been injected previously", () => {
});
});
});

View File

@@ -1,7 +1,7 @@
/* global Given, When, Then */
import { Given, When, Then, And, Before } from "cypress-cucumber-preprocessor/steps";
describe("Send a document", () => {
describe("Send a prepared document", () => {
Given("I am connected to my mailbox", () => {
cy.visit('/');

View File

@@ -0,0 +1,14 @@
Feature: Prepare and Send the document #1615660
As a practiciant, I can prepare a document to send to my colleague and be helped by Irène to fill contextual data.
Scenario: Send a document
Given I use the API
And I have the document #1615660
And I have a DocumentReference
And I have a CommunicationRequest
And Irène prepared the CommunicationRequest
And I have a Patient
And I am connected to my mailbox
When I send the mail
Then the mail is sent

View File

@@ -0,0 +1,230 @@
/* global Given, When, Then */
import { Given, When, Then, And, Before } from "cypress-cucumber-preprocessor/steps";
describe("Send a document", () => {
const apiUrl = "https://fhir-api.public.post-prod.lifen.fr";
let jsonWebToken, documentReferenceId, communicationRequestId, patientId = "";
Given("I use the API", () => {
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;
});
})
And("I have the document #1615660", () => {
cy.request({
url: `${apiUrl}/fhir/Binary/1615660`,
method: 'GET',
headers: {
"authorization": `Bearer ${jsonWebToken}`,
"Prefer": "return=representation"
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("application/pdf");
});
});
And("I have a DocumentReference", () => {
cy.request({
url: `${apiUrl}/fhir/DocumentReference`,
method: 'POST',
headers: {
authorization: `Bearer ${jsonWebToken}`,
'content-type': 'application/json',
"Prefer": "return=representation"
},
json: true,
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) => {
expect(response.status).to.eq(201);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "DocumentReference");
expect(response.body).to.have.property('id');
documentReferenceId = response.body.id
});
});
And("I have a CommunicationRequest", () => {
cy.request({
url: `${apiUrl}/fhir/CommunicationRequest`,
method: 'POST',
headers: {
authorization: `Bearer ${jsonWebToken}`,
'content-type': 'application/json',
"Prefer": "return=representation"
},
json: true,
body: {
"meta": {
"tag": [
{
"system": "http://lifen.fr/fhir/tag/verified/sender",
"code": "SENDER_VERIFIED",
"display": "Sender is verified and should not be changed."
},
{
"system": "http://lifen.fr/fhir/tag/processing/mode",
"code": "IMMEDIATE_MODE",
"display": "request should be treated in immediate mode"
},
{
"system": "http://lifen.fr/fhir/CodeSystem/Resource/Tag/PatientAutomaticResending",
"code": "NONE",
"display": "Patient communication should not be resent"
}
]
},
"status": "draft",
"category": [
{
"coding": [
{
"system": "http://lifen.fr/fhir/CodeSystem/communication-category",
"code": "MEDICAL_REPORT"
}
]
}
],
"priority": "routine",
"payload": [
{
"contentReference": {
"reference": `DocumentReference/${documentReferenceId}`
}
}
],
"sender": {
"extension": [
{
"url": "http://lifen.fr/fhir/StructureDefinition/Resource/Extension/Source",
"valueCode": "USER"
}
],
"reference": "Organization/2"
},
"requester": {
"agent": {
"extension": [
{
"url": "http://lifen.fr/fhir/StructureDefinition/communicationrequest-requester-user-uuid",
"valueString": "ea07d7c6-ff4b-43fc-9765-e4235886d30c"
}
],
"reference": "Organization/2"
}
},
"resourceType": "CommunicationRequest"
}
}).then((response) => {
expect(response.status).to.eq(201);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "CommunicationRequest");
expect(response.body).to.have.property('id');
expect(response.body).to.have.property('status', 'draft');
communicationRequestId = response.body.id
});
});
And("Irène prepared the CommunicationRequest", () => {
cy.wait(10000);
// avec cypress-recurse, on surveille jusqu'a ce que l'IA ai finit son traitement ; plutot que d'attendre un temps arbitraire.
// import { recurse } from 'cypress-recurse' // a placer en début de fichier.
// recurse(() => cy.request(...), (response) => { expect(response.body).to.have.property('status', 'suspended') } ).then((response) => {...})
cy.request({
url: `${apiUrl}/fhir/CommunicationRequest/${communicationRequestId}`,
method: 'GET',
headers: {
authorization: `Bearer ${jsonWebToken}`
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "CommunicationRequest");
expect(response.body).to.have.property('id');
expect(response.body).to.have.property('status', 'suspended');
expect(response.body).to.have.property('subject');
expect(response.body).to.have.property('recipient');
expect(response.body.subject).to.have.property('reference');
let patient = response.body.subject.reference;
patientId = patient.split("/")[1];
});
});
And("I have a Patient", () => {
cy.request({
url: `${apiUrl}/fhir/Patient/${patientId}`,
method: 'GET',
headers: {
authorization: `Bearer ${jsonWebToken}`
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
expect(response.body).to.have.property("resourceType", "Patient");
expect(response.body).to.have.property('id', patientId);
});
});
And("I am connected to my mailbox", () => {
cy.visit('/');
cy.get('#email').type("candidature-qa@example.org");
cy.get('#password').type("kHwWawhH5ADNuFb");
cy.get('#continueButton').click();
cy.wait(20000).then(() => {
cy.get('#validateButton').click();
});
cy.visit("/request");
});
When("I send the mail", () => {
// Il n'y a pas de moyen fiable de lier la communicationRequestId que l'on a préparer avec l'une des entrée listée.
// Il y a bien un code LT-xxxxxxx, mais il faudrais un moyen d'atteindre de le modèle stoquée dans la vue
cy.get("#dashboard-dropzone tr:first-child td").eq(1).click();
cy.get("#sending-button").click();
});
Then("the mail is sent", () => {
//?
// On peux essayer d'attendre une requete de repondre un status
// On peux attendre la notification "Envoie du document réussit"
});
});