Commit 7ecc4b66 authored by Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt Committed by Paul Gascou-Vaillancourt

Leverage logError helper

parent 5b09c084
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { needsArkoseLabsChallenge } from 'ee/rest_api'; import { needsArkoseLabsChallenge } from 'ee/rest_api';
import { logError } from '~/lib/logger';
import { loadingIconForLegacyJS } from '~/loading_icon_for_legacy_js'; import { loadingIconForLegacyJS } from '~/loading_icon_for_legacy_js';
import { __ } from '~/locale'; import { __ } from '~/locale';
import DomElementListener from '~/vue_shared/components/dom_element_listener.vue'; import DomElementListener from '~/vue_shared/components/dom_element_listener.vue';
...@@ -144,8 +145,7 @@ export default { ...@@ -144,8 +145,7 @@ export default {
this.hideErrors(); this.hideErrors();
}, },
handleArkoseLabsFailure(e) { handleArkoseLabsFailure(e) {
// eslint-disable-next-line no-console logError('ArkoseLabs initialization error', e);
console.error('ArkoseLabs initialization error', e);
this.showArkoseFailure = true; this.showArkoseFailure = true;
}, },
updateSubmitButtonLoading(val) { updateSubmitButtonLoading(val) {
......
...@@ -3,9 +3,11 @@ import AxiosMockAdapter from 'axios-mock-adapter'; ...@@ -3,9 +3,11 @@ import AxiosMockAdapter from 'axios-mock-adapter';
import { mountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended } from 'helpers/vue_test_utils_helper';
import SignInArkoseApp from 'ee/arkose_labs/components/sign_in_arkose_app.vue'; import SignInArkoseApp from 'ee/arkose_labs/components/sign_in_arkose_app.vue';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { logError } from '~/lib/logger';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { initArkoseLabsScript } from 'ee/arkose_labs/init_arkose_labs_script'; import { initArkoseLabsScript } from 'ee/arkose_labs/init_arkose_labs_script';
jest.mock('~/lib/logger');
// ArkoseLabs enforcement mocks // ArkoseLabs enforcement mocks
jest.mock('ee/arkose_labs/init_arkose_labs_script'); jest.mock('ee/arkose_labs/init_arkose_labs_script');
let onShown; let onShown;
...@@ -20,6 +22,7 @@ initArkoseLabsScript.mockImplementation(() => ({ ...@@ -20,6 +22,7 @@ initArkoseLabsScript.mockImplementation(() => ({
})); }));
const MOCK_USERNAME = 'cassiopeia'; const MOCK_USERNAME = 'cassiopeia';
const MOCK_PUBLIC_KEY = 'arkose-labs-public-api-key';
describe('SignInArkoseApp', () => { describe('SignInArkoseApp', () => {
let wrapper; let wrapper;
...@@ -44,7 +47,7 @@ describe('SignInArkoseApp', () => { ...@@ -44,7 +47,7 @@ describe('SignInArkoseApp', () => {
createForm(username); createForm(username);
wrapper = mountExtended(SignInArkoseApp, { wrapper = mountExtended(SignInArkoseApp, {
propsData: { propsData: {
publicKey: 'arkose-labs-public-api-key', publicKey: MOCK_PUBLIC_KEY,
formSelector: makeTestIdSelector('sign-in-form'), formSelector: makeTestIdSelector('sign-in-form'),
usernameSelector: makeTestIdSelector('username-field'), usernameSelector: makeTestIdSelector('username-field'),
submitSelector: makeTestIdSelector('sign-in-button'), submitSelector: makeTestIdSelector('sign-in-button'),
...@@ -64,7 +67,7 @@ describe('SignInArkoseApp', () => { ...@@ -64,7 +67,7 @@ describe('SignInArkoseApp', () => {
// Assertions // Assertions
const itInitializesArkoseLabs = () => { const itInitializesArkoseLabs = () => {
it("includes ArkoseLabs' script", () => { it("includes ArkoseLabs' script", () => {
expect(initArkoseLabsScript).toHaveBeenCalled(); expect(initArkoseLabsScript).toHaveBeenCalledWith({ publicKey: MOCK_PUBLIC_KEY });
}); });
it('creates a hidden input for the verification token', () => { it('creates a hidden input for the verification token', () => {
...@@ -86,6 +89,7 @@ describe('SignInArkoseApp', () => { ...@@ -86,6 +89,7 @@ describe('SignInArkoseApp', () => {
}); });
afterEach(() => { afterEach(() => {
axiosMock.restore();
wrapper?.destroy(); wrapper?.destroy();
}); });
...@@ -173,15 +177,12 @@ describe('SignInArkoseApp', () => { ...@@ -173,15 +177,12 @@ describe('SignInArkoseApp', () => {
}); });
it('shows an error alert if the challenge fails to load', async () => { it('shows an error alert if the challenge fails to load', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
expect(wrapper.text()).not.toContain(wrapper.vm.$options.MSG_ARKOSE_FAILURE_BODY); expect(wrapper.text()).not.toContain(wrapper.vm.$options.MSG_ARKOSE_FAILURE_BODY);
const error = new Error(); const error = new Error();
onError(error); onError(error);
// eslint-disable-next-line no-console expect(logError).toHaveBeenCalledWith('ArkoseLabs initialization error', error);
expect(console.error).toHaveBeenCalledWith('ArkoseLabs initialization error', error);
await nextTick(); await nextTick();
...@@ -215,10 +216,6 @@ describe('SignInArkoseApp', () => { ...@@ -215,10 +216,6 @@ describe('SignInArkoseApp', () => {
}); });
describe('when the username check fails', () => { describe('when the username check fails', () => {
beforeEach(async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});
it('with a 404, nothing happens', async () => { it('with a 404, nothing happens', async () => {
axiosMock.onGet().reply(404); axiosMock.onGet().reply(404);
initArkoseLabs(MOCK_USERNAME); initArkoseLabs(MOCK_USERNAME);
...@@ -247,8 +244,7 @@ describe('SignInArkoseApp', () => { ...@@ -247,8 +244,7 @@ describe('SignInArkoseApp', () => {
await waitForPromises(); await waitForPromises();
expectArkoseLabsInitError(); expectArkoseLabsInitError();
// eslint-disable-next-line no-console expect(logError).toHaveBeenCalledWith('ArkoseLabs initialization error', error);
expect(console.error).toHaveBeenCalledWith('ArkoseLabs initialization error', error);
}); });
}); });
}); });
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