Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Fix/login process #327

Merged
merged 7 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/composables/__tests__/useCms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe("Shopware composables", () => {

it("should have failed on bad url settings", async () => {
const { search, page, error } = useCms();
mockedGetPage.getPage.mockRejectedValueOnce("Something went wrong...");
mockedGetPage.getPage.mockRejectedValueOnce({
response: { statusText: "Something went wrong..." }
});
expect(page.value).toEqual(null);
await search();
expect(page.value).toEqual(null);
Expand Down
15 changes: 15 additions & 0 deletions packages/composables/__tests__/useUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ describe("Composables - useUser", () => {
expect(error.value).toEqual("Bad user credentials");
});

it("error message should be appriopriate to the 401 HTTP status code", async () => {
mockedApiClient.login.mockRejectedValueOnce({
response: {
status: 401
}
});
const { error, login } = useUser();
const result = await login({
username: "qwe@qwe.com",
password: "fakePassword"
});
expect(result).toEqual(false);
expect(error.value).toEqual(undefined);
});

it("should login user succesfully", async () => {
mockedApiClient.login.mockResolvedValueOnce({
"sw-context-token": "qweqwe"
Expand Down
2 changes: 1 addition & 1 deletion packages/composables/src/hooks/useCms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const useCms = (): any => {
const result = await getPage(path, searchCriteria);
vuexStore.commit("SET_PAGE", result);
} catch (e) {
error.value = e;
console.error("Problem with fetching CMS data", e.message);
error.value = (e.response && e.response.statusText) || e;
} finally {
loading.value = false;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/default-theme/components/SwLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
v-if="error"
class="sw-login__alert"
type="danger"
message="Cannot login with provided credentials"
message="Invalid credentials"
/>
<SfInput
v-model="email"
Expand Down Expand Up @@ -80,7 +80,7 @@ export default {
return
}
const loggedIn = await this.clientLogin({
username: this.login,
username: this.email,
password: this.password
})
if (loggedIn) this.$emit('success')
Expand Down
5 changes: 4 additions & 1 deletion packages/default-theme/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="login">
<SwLogin class="login__component" />
<SwLogin class="login__component" @success="redirectToMyAccount"/>
</div>
</template>
<script>
Expand All @@ -19,6 +19,9 @@ export default {
computed: {
},
methods: {
redirectToMyAccount() {
this.$router.push("/account")
}
}
}
</script>
Expand Down