Skip to content
Snippets Groups Projects
Commit 4869cfc0 authored by Gilgard's avatar Gilgard
Browse files

Completed getting of other users

parent eb682645
No related branches found
No related tags found
1 merge request!13User profile view
Pipeline #175980 passed
...@@ -115,7 +115,7 @@ export default { ...@@ -115,7 +115,7 @@ export default {
RatingComponent, RatingComponent,
}, },
methods: { methods: {
getUser() { async getUser() {
this.currentUser = parseUserFromToken(); this.currentUser = parseUserFromToken();
this.id = router.currentRoute.value.params.id; this.id = router.currentRoute.value.params.id;
if (this.id == this.currentUser.account_id) { if (this.id == this.currentUser.account_id) {
...@@ -123,10 +123,15 @@ export default { ...@@ -123,10 +123,15 @@ export default {
this.user = this.currentUser; this.user = this.currentUser;
return; return;
} }
this.user = getUser(this.id); let getuser = await getUser(this.id);
this.user = {
account_id: getuser.userID,
first_name: getuser.firstName,
last_name: getuser.lastName,
};
}, },
getProfilePicture() { getProfilePicture() {
/* if (this.user.picture == "") { /* if (this.user.picture != "") {
return this.user.picture; return this.user.picture;
} */ } */
return "../assets/defaultUserProfileImage.jpg"; return "../assets/defaultUserProfileImage.jpg";
......
...@@ -30,10 +30,10 @@ export default { ...@@ -30,10 +30,10 @@ export default {
}, },
methods: { methods: {
getProfilePicture() { getProfilePicture() {
if (this.user.picture == "") { if (this.user.picture != "") {
return "../assets/defaultUserProfileImage.jpg"; return this.user.picture;
} }
return this.user.picture; return "../assets/defaultUserProfileImage.jpg";
}, },
}, },
}; };
......
...@@ -15,13 +15,27 @@ export function doLogin(loginRequest) { ...@@ -15,13 +15,27 @@ export function doLogin(loginRequest) {
}); });
} }
export function getUser(userid) { export function registerUser(registerInfo) {
return axios
.post(VUE_APP_BASEURL + "register", {
email: registerInfo.email,
firstName: registerInfo.firstName,
lastname: registerInfo.lastname,
password: registerInfo.password,
address: registerInfo.address,
})
.then((response) => {
return response;
})
.catch((err) => console.log(err));
}
export async function getUser(userid) {
return axios return axios
.get(VUE_APP_BASEURL + "users/" + userid + "/profile", { .get(VUE_APP_BASEURL + "users/" + userid + "/profile", {
headers: tokenHeader(), headers: tokenHeader(),
}) })
.then((response) => { .then((response) => {
console.log(response.data);
return response.data; return response.data;
}) })
.catch((error) => { .catch((error) => {
......
...@@ -5,13 +5,16 @@ jest.mock("axios"); ...@@ -5,13 +5,16 @@ jest.mock("axios");
describe("testing mocking of apiutil.js", () => { describe("testing mocking of apiutil.js", () => {
it("check that existing user returns correctly", async () => { it("check that existing user returns correctly", async () => {
const expectedResponse = { response: "" }; const expectedResponse = {
response:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50X2lkIjoiNiIsImV4cCI6MTY1MTEzMDU2NywiZmlyc3RfbmFtZSI6IkFsaWRhIiwiZW1haWwiOiJhbGlkYUB0ZXN0Lm5vIn0.Cp3_qfLhA55j5yaa1WPG97LNtvAZssxo0ROP3VIrHVs",
};
axios.get.mockImplementation(() => axios.get.mockImplementation(() =>
Promise.resolve({ data: expectedResponse }) Promise.resolve({ data: expectedResponse })
); );
const userResponse = await getUser(1); const userResponse = await getUser(1);
expect(userResponse).not.toEqual(expectedResponse); expect(userResponse).not.toEqual({ response: "User not found in DB" });
}); });
it("check that non-existing user returns 404", async () => { it("check that non-existing user returns 404", async () => {
const expectedResponse = { response: "User not found in DB" }; const expectedResponse = { response: "User not found in DB" };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment