From 50d7760641bb48444499b65e143f058aef996b73 Mon Sep 17 00:00:00 2001 From: psrok1 Date: Mon, 15 Jul 2024 17:04:30 +0200 Subject: [PATCH] I guess that one is no longer needed --- tests/frontend/cypress/e2e/sample.cy.js | 21 +++++++++++++-------- tests/frontend/cypress/support/commands.js | 14 -------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/tests/frontend/cypress/e2e/sample.cy.js b/tests/frontend/cypress/e2e/sample.cy.js index cee85f855..49d66b62b 100644 --- a/tests/frontend/cypress/e2e/sample.cy.js +++ b/tests/frontend/cypress/e2e/sample.cy.js @@ -4,22 +4,27 @@ describe("Sample view test - mwdb-core", function () { it("Sample view test - existent and non-existent md5 and sha256 hashes", function () { requestLogin(Cypress.env("user"), Cypress.env("password")); - const fileName = "TEST"; - const method = "POST"; - const apiUrl = "/api/file"; - - const fileType = "text/plain"; const addedFile = new Cypress.Promise((resolve) => { + const fileName = "TEST"; + const method = "POST"; + const apiUrl = "/api/file"; + + const fileType = "text/plain"; + cy.get("@token").then((token) => { cy.fixture(fileName).then((bin) => { const blob = Cypress.Blob.binaryStringToBlob(bin, fileType); const formData = new FormData(); formData.set("file", blob, fileName); - - cy.formRequest(method, apiUrl, formData, token).then((response) => { + cy.request({ + url: apiUrl, + method, + headers: {"Authorization": "Bearer " + token}, + body: formData, + }).then((response) => { expect(response.status).to.eq(200); - resolve(response.response.body); + resolve(response.body); }); }); }); diff --git a/tests/frontend/cypress/support/commands.js b/tests/frontend/cypress/support/commands.js index 8159ea66e..ca4d256f3 100644 --- a/tests/frontend/cypress/support/commands.js +++ b/tests/frontend/cypress/support/commands.js @@ -23,17 +23,3 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) - -Cypress.Commands.add("formRequest", (method, url, formData, token) => { - return cy - .intercept(method, url) - .as("formRequest") - .window() - .then((win) => { - let xhr = new win.XMLHttpRequest(); - xhr.open(method, url); - xhr.setRequestHeader("Authorization", "Bearer " + token); - xhr.send(formData); - }) - .wait("@formRequest"); -});