Skip to content

Commit

Permalink
fix tests for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine authored Apr 11, 2018
1 parent 5173649 commit 1ccbded
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions test/unit/migrations-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,57 @@

const expect = require('chai').expect;
const sinon = require('sinon');
const createConfig = require('../utils/config-stub');

const fs = require('fs-extra');
const ghostUser = require('../../lib/utils/use-ghost-user');

const migrations = require('../../lib/migrations');

describe('Unit: Migrations', function () {
const sandbox = sinon.sandbox.create();

afterEach(() => {
sandbox.restore();
});

describe('ensureSettingsFolder', function () {
const setupEnv = require('../utils/env');
const path = require('path');
const fs = require('fs');
it('if ghost user owns directory, runs `sudo mkdir` as ghost user', function () {
const ghostUserStub = sandbox.stub(ghostUser, 'shouldUseGhostUser').returns(true);
const sudoStub = sandbox.stub().resolves();
const config = createConfig();
config.get.withArgs('paths.contentPath').returns('/var/www/ghost/content');

const context = {
instance: {config: config},
ui: {sudo: sudoStub}
};

return migrations[0].task(context).then(() => {
expect(ghostUserStub.calledOnce).to.be.true;
expect(ghostUserStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
expect(sudoStub.calledOnce).to.be.true;
expect(sudoStub.calledWithExactly(
'mkdir /var/www/ghost/content/settings',
{sudoArgs: '-E -u ghost'}
)).to.be.true;
});
});

it('creates settings folder if not existent', function () {
const env = setupEnv();
const cwdStub = sinon.stub(process, 'cwd').returns(env.dir);
const ensureSettingsFolder = migrations[0].task;
it('if ghost user doesn\'t own directory, runs basic mkdir', function () {
const ghostUserStub = sandbox.stub(ghostUser, 'shouldUseGhostUser').returns(false);
const fsStub = sandbox.stub(fs, 'ensureDirSync');
const config = createConfig();
config.get.withArgs('paths.contentPath').returns('/var/www/ghost/content');

ensureSettingsFolder();
expect(cwdStub.calledOnce).to.be.true;
expect(fs.existsSync(path.join(env.dir, 'content/settings'))).to.be.true;
const context = {instance: {config: config}};

cwdStub.restore();
env.cleanup();
return migrations[0].task(context).then(() => {
expect(ghostUserStub.calledOnce).to.be.true;
expect(ghostUserStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
expect(fsStub.calledOnce).to.be.true;
expect(fsStub.calledWithExactly('/var/www/ghost/content/settings')).to.be.true;
});
});
});
});

0 comments on commit 1ccbded

Please sign in to comment.