mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Fixed members importer tests from leaving files behind
no issue - After each test run there were csv files lefover which polluted the workspace. - Ideally the write file would be some kind of a smart mock, so we'd won't have to do synchronous file remoal after each test but that's for later improvement if it becomes problematic
This commit is contained in:
parent
9794fb8883
commit
a99fec1a7b
@ -2,6 +2,7 @@
|
||||
// const testUtils = require('./utils');
|
||||
require('./utils');
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const sinon = require('sinon');
|
||||
const MembersCSVImporter = require('..');
|
||||
@ -9,6 +10,22 @@ const MembersCSVImporter = require('..');
|
||||
const csvPath = path.join(__dirname, '/fixtures/');
|
||||
|
||||
describe('Importer', function () {
|
||||
let fsWriteSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
fsWriteSpy = sinon.spy(fs, 'writeFile');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
const writtenFile = fsWriteSpy.args[0][0];
|
||||
|
||||
if (writtenFile) {
|
||||
fs.removeSync(writtenFile);
|
||||
}
|
||||
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
describe('process', function () {
|
||||
it('should import a CSV file', async function () {
|
||||
const defaultProduct = {
|
||||
@ -74,6 +91,8 @@ describe('Importer', function () {
|
||||
|
||||
should.exist(result.meta.stats.invalid);
|
||||
should.equal(result.meta.import_label, null);
|
||||
|
||||
fsWriteSpy.calledOnce.should.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
@ -97,6 +116,8 @@ describe('Importer', function () {
|
||||
|
||||
result.batches.should.equal(2);
|
||||
should.exist(result.metadata);
|
||||
|
||||
fsWriteSpy.calledOnce.should.be.true();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user