diff --git a/webapp/e2e/steps/getQuestion.steps.js b/webapp/e2e/steps/getQuestion.steps.js index 2a7a5a0..a47b2f4 100644 --- a/webapp/e2e/steps/getQuestion.steps.js +++ b/webapp/e2e/steps/getQuestion.steps.js @@ -17,34 +17,38 @@ defineFeature(feature, test => { page = await browser.newPage(); await page.setRequestInterception(true); - //intercepts the requests to the getQuestion endpoint and other request of options + //intercepts the requests to the getQuestion, savequestion endpoints and other request of options page.on('request', (req) => { - if (req.url().endsWith('/getQuestion')) { - if (req.method() === 'OPTIONS') { - // Respond to preflight request - req.respond({ - status: 200, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': '*' - } - }); - } else { - // Respond to actual request - req.respond({ - status: 200, - headers: { - 'Access-Control-Allow-Origin': '*' - }, - contentType: 'application/json', - body: JSON.stringify({ - question: 'Test question', - correctAnswerLabel: 'Test correct answer', - answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'] - }) - }); + if (req.method() === 'OPTIONS'){ + // Respond to preflight request + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*' + } + }); + } else if (req.url().endsWith('/getQuestion')) { + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*' + }, + contentType: 'application/json', + body: JSON.stringify({ + question: 'Test question', + correctAnswerLabel: 'Test correct answer', + answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'] + }) + }); + } else if(req.url().endsWith('/saveQuestion')){ + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*' } + }); } else { req.continue(); } diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index 42ab5df..1925cf7 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -16,6 +16,32 @@ defineFeature(feature, test => { ? await puppeteer.launch() : await puppeteer.launch({ headless: false, slowMo: 100 }); page = await browser.newPage(); + + await page.setRequestInterception(true); + //intercepts the requests to the getQuestion endpoint and other request of options + page.on('request', (req) => { + if (req.method() === 'OPTIONS'){ + // Respond to preflight request + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*' + } + }); + } else if (req.url().endsWith('/generateQuestions')) { + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*' + } + }); + } else { + req.continue(); + } + }); + //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }) diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index b0cd43e..e0988b4 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -19,7 +19,7 @@ async function startServer() { authservice = await require("../../users/authservice/auth-service"); gatewayservice = await require("../../gatewayservice/gateway-service"); questionservice = await require("../../questionsgenerator/questions-service"); - historialservice = await require("../../historial/historial-service"); + historialservice = await require("../../record/historial-service"); // Add the user for the tests, if the user already exists, it will not be added await mongoose.connect(mongoUri);