fix(backend-test): delete nested file path (#2930)

This commit is contained in:
Bartholomew 2019-11-29 17:10:39 +01:00 committed by Erez Rokah
parent 45a6ee92cc
commit b0fba6dc9a
2 changed files with 46 additions and 4 deletions

View File

@ -157,4 +157,48 @@ describe('test backend implementation', () => {
});
});
});
describe('deleteFile', () => {
it('should delete entry by path', async () => {
window.repoFiles = {
posts: {
'some-post.md': {
content: 'post content',
},
},
};
const backend = new TestBackend();
await backend.deleteFile('posts/some-post.md');
expect(window.repoFiles).toEqual({
posts: {},
});
});
it('should delete entry by nested path', async () => {
window.repoFiles = {
posts: {
dir1: {
dir2: {
'some-post.md': {
content: 'post content',
},
},
},
},
};
const backend = new TestBackend();
await backend.deleteFile('posts/dir1/dir2/some-post.md');
expect(window.repoFiles).toEqual({
posts: {
dir1: {
dir2: {},
},
},
});
});
});
});

View File

@ -1,4 +1,4 @@
import { attempt, isError, take } from 'lodash';
import { attempt, isError, take, unset } from 'lodash';
import uuid from 'uuid/v4';
import { EditorialWorkflowError, Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util';
import AuthenticationPage from './AuthenticationPage';
@ -255,9 +255,7 @@ export default class TestBackend {
if (assetIndex > -1) {
this.assets.splice(assetIndex, 1);
} else {
const folder = path.substring(0, path.lastIndexOf('/'));
const fileName = path.substring(path.lastIndexOf('/') + 1);
delete window.repoFiles[folder][fileName];
unset(window.repoFiles, path.split('/'));
}
return Promise.resolve();