Commit fb5c5f84 authored by Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt Committed by Paul Gascou-Vaillancourt

Improve and extend spec

parent 2c67bd80
...@@ -19,6 +19,8 @@ initArkoseLabsScript.mockImplementation(() => ({ ...@@ -19,6 +19,8 @@ initArkoseLabsScript.mockImplementation(() => ({
}, },
})); }));
const MOCK_USERNAME = 'cassiopeia';
describe('SignInArkoseApp', () => { describe('SignInArkoseApp', () => {
let wrapper; let wrapper;
let axiosMock; let axiosMock;
...@@ -75,6 +77,9 @@ describe('SignInArkoseApp', () => { ...@@ -75,6 +77,9 @@ describe('SignInArkoseApp', () => {
const expectHiddenArkoseLabsError = () => { const expectHiddenArkoseLabsError = () => {
expect(findArkoseLabsErrorMessage().exists()).toBe(false); expect(findArkoseLabsErrorMessage().exists()).toBe(false);
}; };
const expectArkoseLabsInitError = () => {
expect(wrapper.text()).toContain(wrapper.vm.$options.MSG_ARKOSE_FAILURE_BODY);
};
beforeEach(() => { beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios); axiosMock = new AxiosMockAdapter(axios);
...@@ -85,14 +90,12 @@ describe('SignInArkoseApp', () => { ...@@ -85,14 +90,12 @@ describe('SignInArkoseApp', () => {
}); });
describe('when the username field is pre-filled', () => { describe('when the username field is pre-filled', () => {
const username = 'invite-email-username';
it("does not include ArkoseLabs' script initially", () => { it("does not include ArkoseLabs' script initially", () => {
expect(initArkoseLabsScript).not.toHaveBeenCalled(); expect(initArkoseLabsScript).not.toHaveBeenCalled();
}); });
it('puts the sign-in button in the loading state', async () => { it('puts the sign-in button in the loading state', async () => {
initArkoseLabs(username); initArkoseLabs(MOCK_USERNAME);
await nextTick(); await nextTick();
const signInButton = findSignInButton(); const signInButton = findSignInButton();
...@@ -101,20 +104,20 @@ describe('SignInArkoseApp', () => { ...@@ -101,20 +104,20 @@ describe('SignInArkoseApp', () => {
}); });
it('triggers a request to the captcha_check API', async () => { it('triggers a request to the captcha_check API', async () => {
initArkoseLabs(username); initArkoseLabs(MOCK_USERNAME);
expect(axiosMock.history.get).toHaveLength(0); expect(axiosMock.history.get).toHaveLength(0);
await waitForPromises(); await waitForPromises();
expect(axiosMock.history.get).toHaveLength(1); expect(axiosMock.history.get).toHaveLength(1);
expect(axiosMock.history.get[0].url).toMatch(`/users/${username}/captcha_check`); expect(axiosMock.history.get[0].url).toMatch(`/users/${MOCK_USERNAME}/captcha_check`);
}); });
describe('if the challenge is not needed', () => { describe('if the challenge is not needed', () => {
beforeEach(async () => { beforeEach(async () => {
axiosMock.onGet().reply(200, { result: false }); axiosMock.onGet().reply(200, { result: false });
initArkoseLabs(username); initArkoseLabs(MOCK_USERNAME);
await waitForPromises(); await waitForPromises();
}); });
...@@ -122,10 +125,12 @@ describe('SignInArkoseApp', () => { ...@@ -122,10 +125,12 @@ describe('SignInArkoseApp', () => {
const signInButton = findSignInButton(); const signInButton = findSignInButton();
expect(signInButton.innerText).toMatchInterpolatedText('Sign in'); expect(signInButton.innerText).toMatchInterpolatedText('Sign in');
expect(signInButton.disabled).toBe(false);
}); });
it('does not show ArkoseLabs error when submitting the form', () => { it('does not show ArkoseLabs error when submitting the form', async () => {
submitForm(); submitForm();
await nextTick();
expect(findArkoseLabsErrorMessage().exists()).toBe(false); expect(findArkoseLabsErrorMessage().exists()).toBe(false);
}); });
...@@ -133,7 +138,7 @@ describe('SignInArkoseApp', () => { ...@@ -133,7 +138,7 @@ describe('SignInArkoseApp', () => {
describe('if the challenge becomes needed', () => { describe('if the challenge becomes needed', () => {
beforeEach(async () => { beforeEach(async () => {
axiosMock.onGet().reply(200, { result: true }); axiosMock.onGet().reply(200, { result: true });
setUsername('bob'); setUsername(`malicious-${MOCK_USERNAME}`);
await waitForPromises(); await waitForPromises();
}); });
...@@ -144,7 +149,7 @@ describe('SignInArkoseApp', () => { ...@@ -144,7 +149,7 @@ describe('SignInArkoseApp', () => {
describe('if the challenge is needed', () => { describe('if the challenge is needed', () => {
beforeEach(async () => { beforeEach(async () => {
axiosMock.onGet().reply(200, { result: true }); axiosMock.onGet().reply(200, { result: true });
initArkoseLabs(username); initArkoseLabs(MOCK_USERNAME);
await waitForPromises(); await waitForPromises();
}); });
...@@ -155,6 +160,7 @@ describe('SignInArkoseApp', () => { ...@@ -155,6 +160,7 @@ describe('SignInArkoseApp', () => {
await nextTick(); await nextTick();
expect(findArkoseLabsErrorMessage().exists()).toBe(true); expect(findArkoseLabsErrorMessage().exists()).toBe(true);
expect(wrapper.text()).toContain(wrapper.vm.$options.MSG_ARKOSE_NEEDED);
}); });
it('un-hides the challenge container once the iframe has been shown', async () => { it('un-hides the challenge container once the iframe has been shown', async () => {
...@@ -179,7 +185,7 @@ describe('SignInArkoseApp', () => { ...@@ -179,7 +185,7 @@ describe('SignInArkoseApp', () => {
await nextTick(); await nextTick();
expect(wrapper.text()).toContain(wrapper.vm.$options.MSG_ARKOSE_FAILURE_BODY); expectArkoseLabsInitError();
}); });
describe('when ArkoseLabs calls `onCompleted` handler that has been configured', () => { describe('when ArkoseLabs calls `onCompleted` handler that has been configured', () => {
...@@ -207,4 +213,17 @@ describe('SignInArkoseApp', () => { ...@@ -207,4 +213,17 @@ describe('SignInArkoseApp', () => {
}); });
}); });
}); });
describe('when the REST endpoint fails', () => {
beforeEach(async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
axiosMock.onGet().reply(500);
initArkoseLabs(MOCK_USERNAME);
await waitForPromises();
});
it('shows initialization error', () => {
expectArkoseLabsInitError();
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment