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 {
RatingComponent,
},
methods: {
getUser() {
async getUser() {
this.currentUser = parseUserFromToken();
this.id = router.currentRoute.value.params.id;
if (this.id == this.currentUser.account_id) {
......@@ -123,10 +123,15 @@ export default {
this.user = this.currentUser;
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() {
/* if (this.user.picture == "") {
/* if (this.user.picture != "") {
return this.user.picture;
} */
return "../assets/defaultUserProfileImage.jpg";
......
......@@ -30,10 +30,10 @@ export default {
},
methods: {
getProfilePicture() {
if (this.user.picture == "") {
return "../assets/defaultUserProfileImage.jpg";
if (this.user.picture != "") {
return this.user.picture;
}
return this.user.picture;
return "../assets/defaultUserProfileImage.jpg";
},
},
};
......
......@@ -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
.get(VUE_APP_BASEURL + "users/" + userid + "/profile", {
headers: tokenHeader(),
})
.then((response) => {
console.log(response.data);
return response.data;
})
.catch((error) => {
......
......@@ -5,13 +5,16 @@ jest.mock("axios");
describe("testing mocking of apiutil.js", () => {
it("check that existing user returns correctly", async () => {
const expectedResponse = { response: "" };
const expectedResponse = {
response:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50X2lkIjoiNiIsImV4cCI6MTY1MTEzMDU2NywiZmlyc3RfbmFtZSI6IkFsaWRhIiwiZW1haWwiOiJhbGlkYUB0ZXN0Lm5vIn0.Cp3_qfLhA55j5yaa1WPG97LNtvAZssxo0ROP3VIrHVs",
};
axios.get.mockImplementation(() =>
Promise.resolve({ data: expectedResponse })
);
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 () => {
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