Commit 1a5cb572 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '327200-update-getrawfile-params' into 'master'

Update Api.getRawFile to make ref param optional[RUN-AS-IF-FOSS]

See merge request gitlab-org/gitlab!59238
parents 24e67427 563a7580
...@@ -796,7 +796,7 @@ const Api = { ...@@ -796,7 +796,7 @@ const Api = {
return axios.delete(url, { data }); return axios.delete(url, { data });
}, },
getRawFile(id, path, params = { ref: 'master' }) { getRawFile(id, path, params = {}) {
const url = Api.buildUrl(this.rawFilePath) const url = Api.buildUrl(this.rawFilePath)
.replace(':id', encodeURIComponent(id)) .replace(':id', encodeURIComponent(id))
.replace(':path', encodeURIComponent(path)); .replace(':path', encodeURIComponent(path));
......
...@@ -45,7 +45,7 @@ export const fetchPipelineConfigurationFileExists = async (path) => { ...@@ -45,7 +45,7 @@ export const fetchPipelineConfigurationFileExists = async (path) => {
} }
try { try {
const { status } = await Api.getRawFile(`${group}/${project}`, file, { ref: undefined }); const { status } = await Api.getRawFile(`${group}/${project}`, file);
return status === httpStatus.OK; return status === httpStatus.OK;
} catch (e) { } catch (e) {
......
...@@ -1222,13 +1222,26 @@ describe('Api', () => { ...@@ -1222,13 +1222,26 @@ describe('Api', () => {
)}/repository/files/${encodeURIComponent(dummyFilePath)}/raw`; )}/repository/files/${encodeURIComponent(dummyFilePath)}/raw`;
describe('when the raw file is successfully fetched', () => { describe('when the raw file is successfully fetched', () => {
it('resolves the Promise', () => { beforeEach(() => {
mock.onGet(expectedUrl).replyOnce(httpStatus.OK); mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
});
it('resolves the Promise', () => {
return Api.getRawFile(dummyProjectPath, dummyFilePath).then(() => { return Api.getRawFile(dummyProjectPath, dummyFilePath).then(() => {
expect(mock.history.get).toHaveLength(1); expect(mock.history.get).toHaveLength(1);
}); });
}); });
describe('when the method is called with params', () => {
it('sets the params on the request', () => {
const params = { ref: 'main' };
jest.spyOn(axios, 'get');
Api.getRawFile(dummyProjectPath, dummyFilePath, params);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { params });
});
});
}); });
describe('when an error occurs while getting a raw file', () => { describe('when an error occurs while getting a raw file', () => {
......
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