Skip to content

Commit

Permalink
Fixed e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289029 committed Apr 6, 2024
1 parent f111b22 commit 1205ca7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
56 changes: 30 additions & 26 deletions webapp/e2e/steps/getQuestion.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
26 changes: 26 additions & 0 deletions webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1205ca7

Please sign in to comment.