Commit 109a57af authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/331265/stopRequestsToEmojiEndpoint' into 'master'

Fixes emoji endpoint being called when user not signed in

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