Commit 4c66a5eb authored by Himanshu Kapoor's avatar Himanshu Kapoor Committed by Himanshu Kapoor

Fix incorrect content returned on empty dotfile

When an empty dotfile is committed in the Web IDE, the html source of
Web IDE itself is returned as its contents. This change fixes it.
parent 93968328
......@@ -25,7 +25,7 @@ export default {
return Promise.resolve(file.content);
}
if (file.raw) {
if (file.raw || !file.rawPath) {
return Promise.resolve(file.raw);
}
......
---
title: Fix incorrect content returned on empty dotfile
merge_request: 28144
author:
type: fixed
......@@ -42,6 +42,87 @@ describe('IDE services', () => {
});
});
describe('getRawFileData', () => {
it("resolves with a file's content if its a tempfile and it isn't renamed", () => {
const file = {
path: 'file',
tempFile: true,
content: 'content',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('content');
});
});
it('resolves with file.raw if the file is renamed', () => {
const file = {
path: 'file',
tempFile: true,
content: 'content',
prevPath: 'old_path',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('raw content');
});
});
it('returns file.raw if it exists', () => {
const file = {
path: 'file',
content: 'content',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('raw content');
});
});
it("returns file.raw if file.raw is empty but file.rawPath doesn't exist", () => {
const file = {
path: 'file',
content: 'content',
raw: '',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('');
});
});
describe("if file.rawPath exists but file.raw doesn't exist", () => {
let file;
let mock;
beforeEach(() => {
file = {
path: 'file',
content: 'content',
raw: '',
rawPath: 'some_raw_path',
};
mock = new MockAdapter(axios);
mock.onGet(file.rawPath).reply(200, 'raw content');
jest.spyOn(axios, 'get');
});
afterEach(() => {
mock.restore();
});
it('sends a request to file.rawPath', () => {
return services.getRawFileData(file).then(raw => {
expect(raw).toEqual('raw content');
});
});
});
});
describe('getBaseRawFileData', () => {
let file;
let mock;
......
......@@ -408,7 +408,7 @@ describe('IDE store file actions', () => {
beforeEach(() => {
jest.spyOn(service, 'getRawFileData');
tmpFile = file('tmpFile');
tmpFile = { ...file('tmpFile'), rawPath: 'raw_path' };
store.state.entries[tmpFile.path] = tmpFile;
});
......
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