Skip to content

Commit

Permalink
Fixed e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
algarfer committed Apr 30, 2024
1 parent 561ab36 commit 6268918
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 19 deletions.
10 changes: 2 additions & 8 deletions gatewayservice/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ module.exports = (app, axios) => {
app.post("/login", async (req, res, next) => {
axios.post(`${authServiceUrl}/login`, req.body)
.then(response => res.json(response.data))
.catch(e => {
if(e.code) return next(e.code)
next({status: e.response.status, error: e.response.data})
});
.catch(e => next({status: e.response.status, ...e.response.data}));
});

app.get("/validate/:token", (req, res, next) => {
axios
.get(`${authServiceUrl}/validate/${req.params.token}`)
.then(({ data }) => res.json({valid: data.valid}))
.catch(e => {
if(e.code) return next(e.code)
next({status: e.response.status, error: e.response.data})
});
.catch(e => next({status: e.response.status, ...e.response.data}));
});
};
13 changes: 4 additions & 9 deletions gatewayservice/routes/usersRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ module.exports = (app, axios, authTokenMiddleware) => {
res.json({ message: response.data.message, error: e })
})
})
.catch(() => next({ error: i18next.t("error_adding_user") }));
.catch(e => errorHandler(e, next));
});

app.get("/user/:userId", authTokenMiddleware, (req, res, next) => {
const { userId } = req.params
axios
.get(`${userServiceUrl}/user/${userId}`)
.then(({ data }) => res.json(data))
.catch(e => {
if(e.code && e.code === "ECONNREFUSED") return next(e.code)
next({status: e.response.status, ...e.response.data})
})
.catch(e => errorHandler(e, next));
});

app.get("/users/search/:filter", async (req, res, next) => {
Expand All @@ -49,10 +46,8 @@ module.exports = (app, axios, authTokenMiddleware) => {
axios
.get(`${userServiceUrl}/users/search/${filter}`)
.then(({ data }) => res.json(data))
.catch(e => {
if(e.code && e.code === "ECONNREFUSED") return next(e.code)
next({status: e.response.status, ...e.response.data})
});
.catch(e => errorHandler(e, next));

});

app.post("/users/social/sendrequest", authTokenMiddleware, async (req, res, next) => {
Expand Down
1 change: 1 addition & 0 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function startServer() {
userhistory = await require("../../userhistory/history-service");

await testUtils.insertSampleUser(axios);
await testUtils.insertGroups(axios);

}
startServer().then(e=>{});
134 changes: 133 additions & 1 deletion webapp/e2e/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,137 @@ module.exports = {
}catch(error){
console.error("Error inserting sample user for e2e tests: " + error)
}
},
insertGroups: async (axios) => {
try{
console.log("Inserting groups for e2e tests...")
await axios.post(`http://localhost:8003/addGroups`, groups)
await axios.get(`http://localhost:8003/gen`)
}catch(error){
console.error("Error inserting groups for e2e tests: " + error)
}
}
}

const groups = [
{
"groupId": "capitals",
"questionItem": "Q6256",
"answer": "P36",
"statements": [
"The capital of <QuestionItem> is...",
"What is the capital of <QuestionItem>?",
"Select the capital of <QuestionItem>"
],
"categories": [
"capitals",
"geography"
]
},
{
"groupId": "continent",
"questionItem": "Q6256",
"answer": "P30",
"statements": [
"The continent of <QuestionItem> is...",
"What is the continent of <QuestionItem>?",
"Select the continent of <QuestionItem>"
],
"categories": [
"continent",
"geography"
]
},
{
"groupId": "languages",
"questionItem": "Q6256",
"answer": "P37",
"statements": [
"The language spoken in <QuestionItem> is...",
"What is the language spoken in <QuestionItem>?",
"Select the language spoken in <QuestionItem>"
],
"categories": [
"languages",
"geography"
]
},
{
"groupId": "population",
"questionItem": "Q6256",
"answer": "P1082",
"statements": [
"The population of <QuestionItem> is...",
"What is the population of <QuestionItem>",
"Select the population of <QuestionItem>"
],
"categories": [
"population",
"geography"
],
"plainText": true,
"filter": "FILTER(LANG(?question) = 'en')"
},
{
"groupId": "area",
"questionItem": "Q6256",
"answer": "P2046",
"statements": [
"The area of <QuestionItem> is...",
"What is the area of <QuestionItem>",
"Select the area of <QuestionItem>"
],
"categories": [
"area",
"geography"
],
"plainText": true,
"filter": "FILTER(LANG(?question) = 'en')"
},
{
"groupId": "gdp",
"questionItem": "Q6256",
"answer": "P2131",
"statements": [
"The GDP of <QuestionItem> is...",
"What is the GDP of <QuestionItem>",
"Select the GDP of <QuestionItem>"
],
"categories": [
"gdp",
"geography"
],
"plainText": true,
"filter": "FILTER(LANG(?question) = 'en')"
},
{
"groupId": "currency",
"questionItem": "Q6256",
"answer": "P38",
"statements": [
"The currency of <QuestionItem> is...",
"What is the currency of <QuestionItem>",
"Select the currency of <QuestionItem>"
],
"categories": [
"currency",
"geography",
"economy"
]
},
{
"groupId": "president",
"questionItem": "Q6256",
"answer": "P35",
"statements": [
"The president of <QuestionItem> is...",
"Who is the president of <QuestionItem>",
"Select the president of <QuestionItem>"
],
"categories": [
"president",
"geography",
"politics"
]
}
}
]
2 changes: 1 addition & 1 deletion webapp/src/locals/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"home_menu_logout": "Logout",
"home_menu_social": "Social",

"signup_title": "Signup",
"signup_title": "Sign up",
"signup_suggestion_text": "Already have an account?",
"signup_suggestion_link": "Login",
"signup_submit_button": "Create account",
Expand Down

0 comments on commit 6268918

Please sign in to comment.