Commit 02f0298c authored by Phil Hughes's avatar Phil Hughes

Fixes award emoji not working with relative root URL

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/332010
parent 7535be32
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { normalizeHeaders } from '~/lib/utils/common_utils'; import { normalizeHeaders } from '~/lib/utils/common_utils';
import { joinPaths } from '~/lib/utils/url_utility';
import { __ } from '~/locale'; import { __ } from '~/locale';
import showToast from '~/vue_shared/plugins/global_toast'; import showToast from '~/vue_shared/plugins/global_toast';
import { import {
...@@ -16,7 +17,9 @@ export const fetchAwards = async ({ commit, dispatch, state }, page = '1') => { ...@@ -16,7 +17,9 @@ export const fetchAwards = async ({ commit, dispatch, state }, page = '1') => {
if (!window.gon?.current_user_id) return; 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(joinPaths(gon.relative_url_root || '', state.path), {
params: { per_page: 100, page },
});
const normalizedHeaders = normalizeHeaders(headers); const normalizedHeaders = normalizeHeaders(headers);
const nextPage = normalizedHeaders['X-NEXT-PAGE']; const nextPage = normalizedHeaders['X-NEXT-PAGE'];
...@@ -35,13 +38,15 @@ export const toggleAward = async ({ commit, state }, name) => { ...@@ -35,13 +38,15 @@ export const toggleAward = async ({ commit, state }, name) => {
try { try {
if (award) { if (award) {
await axios.delete(`${state.path}/${award.id}`); await axios.delete(joinPaths(gon.relative_url_root || '', `${state.path}/${award.id}`));
commit(REMOVE_AWARD, award.id); commit(REMOVE_AWARD, award.id);
showToast(__('Award removed')); showToast(__('Award removed'));
} else { } else {
const { data } = await axios.post(state.path, { name }); const { data } = await axios.post(joinPaths(gon.relative_url_root || '', state.path), {
name,
});
commit(ADD_NEW_AWARD, data); commit(ADD_NEW_AWARD, data);
......
...@@ -35,15 +35,23 @@ describe('Awards app actions', () => { ...@@ -35,15 +35,23 @@ describe('Awards app actions', () => {
}); });
describe('success', () => { describe('success', () => {
describe.each`
relativeRootUrl
${null}
${'/gitlab'}
`('with relative_root_url as $relativeRootUrl', ({ relativeRootUrl }) => {
beforeEach(() => { beforeEach(() => {
window.gon = { relative_url_root: relativeRootUrl };
mock mock
.onGet('/awards', { params: { per_page: 100, page: '1' } }) .onGet(`${relativeRootUrl || ''}/awards`, { params: { per_page: 100, page: '1' } })
.reply(200, ['thumbsup'], { 'x-next-page': '2' }); .reply(200, ['thumbsup'], { 'x-next-page': '2' });
mock.onGet('/awards', { params: { per_page: 100, page: '2' } }).reply(200, ['thumbsdown']); mock
.onGet(`${relativeRootUrl || ''}/awards`, { params: { per_page: 100, page: '2' } })
.reply(200, ['thumbsdown']);
}); });
it('commits FETCH_AWARDS_SUCCESS', async () => { it('commits FETCH_AWARDS_SUCCESS', async () => {
window.gon = { current_user_id: 1 }; window.gon.current_user_id = 1;
await testAction( await testAction(
actions.fetchAwards, actions.fetchAwards,
...@@ -58,6 +66,7 @@ describe('Awards app actions', () => { ...@@ -58,6 +66,7 @@ describe('Awards app actions', () => {
await testAction(actions.fetchAwards, '1', { path: '/awards' }, [], []); await testAction(actions.fetchAwards, '1', { path: '/awards' }, [], []);
}); });
}); });
});
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
...@@ -85,10 +94,19 @@ describe('Awards app actions', () => { ...@@ -85,10 +94,19 @@ describe('Awards app actions', () => {
mock.restore(); mock.restore();
}); });
describe.each`
relativeRootUrl
${null}
${'/gitlab'}
`('with relative_root_url as $relativeRootUrl', ({ relativeRootUrl }) => {
beforeEach(() => {
window.gon = { relative_url_root: relativeRootUrl };
});
describe('adding new award', () => { describe('adding new award', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock.onPost('/awards').reply(200, { id: 1 }); mock.onPost(`${relativeRootUrl || ''}/awards`).reply(200, { id: 1 });
}); });
it('commits ADD_NEW_AWARD', async () => { it('commits ADD_NEW_AWARD', async () => {
...@@ -100,7 +118,7 @@ describe('Awards app actions', () => { ...@@ -100,7 +118,7 @@ describe('Awards app actions', () => {
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onPost('/awards').reply(500); mock.onPost(`${relativeRootUrl || ''}/awards`).reply(500);
}); });
it('calls Sentry.captureException', async () => { it('calls Sentry.captureException', async () => {
...@@ -123,7 +141,7 @@ describe('Awards app actions', () => { ...@@ -123,7 +141,7 @@ describe('Awards app actions', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock.onDelete('/awards/1').reply(200); mock.onDelete(`${relativeRootUrl || ''}/awards/1`).reply(200);
}); });
it('commits REMOVE_AWARD', async () => { it('commits REMOVE_AWARD', async () => {
...@@ -142,7 +160,7 @@ describe('Awards app actions', () => { ...@@ -142,7 +160,7 @@ describe('Awards app actions', () => {
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onDelete('/awards/1').reply(500); mock.onDelete(`${relativeRootUrl || ''}/awards/1`).reply(500);
}); });
it('calls Sentry.captureException', async () => { it('calls Sentry.captureException', async () => {
...@@ -164,4 +182,5 @@ describe('Awards app actions', () => { ...@@ -164,4 +182,5 @@ describe('Awards app actions', () => {
}); });
}); });
}); });
});
}); });
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