Commit fa8c83ea authored by Phil Hughes's avatar Phil Hughes

Fixes emoji endpoint being called when user not signed in

This stops a unauthorised request error for when the user
is not signed in and tries to request the award emoji endpoint.

Changelog: fixed

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/331265
parent 3c024aa0
......@@ -13,6 +13,8 @@ import {
export const setInitialData = ({ commit }, data) => commit(SET_INITIAL_DATA, data);
export const fetchAwards = async ({ commit, dispatch, state }, page = '1') => {
if (!window.gon?.current_user_id) return;
try {
const { data, headers } = await axios.get(state.path, { params: { per_page: 100, page } });
const normalizedHeaders = normalizeHeaders(headers);
......
......@@ -7,6 +7,10 @@ import axios from '~/lib/utils/axios_utils';
jest.mock('@sentry/browser');
describe('Awards app actions', () => {
afterEach(() => {
window.gon = {};
});
describe('setInitialData', () => {
it('commits SET_INITIAL_DATA', async () => {
await testAction(
......@@ -39,6 +43,8 @@ describe('Awards app actions', () => {
});
it('commits FETCH_AWARDS_SUCCESS', async () => {
window.gon = { current_user_id: 1 };
await testAction(
actions.fetchAwards,
'1',
......@@ -47,6 +53,10 @@ describe('Awards app actions', () => {
[{ type: 'fetchAwards', payload: '2' }],
);
});
it('does not commit FETCH_AWARDS_SUCCESS when user signed out', async () => {
await testAction(actions.fetchAwards, '1', { path: '/awards' }, [], []);
});
});
describe('error', () => {
......@@ -55,6 +65,8 @@ describe('Awards app actions', () => {
});
it('calls Sentry.captureException', async () => {
window.gon = { current_user_id: 1 };
await testAction(actions.fetchAwards, null, { path: '/awards' }, [], [], () => {
expect(Sentry.captureException).toHaveBeenCalled();
});
......
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