|
2 | 2 |
|
3 | 3 | const expect = require('chai').expect;
|
4 | 4 | const sinon = require('sinon');
|
| 5 | +const createConfig = require('../utils/config-stub'); |
| 6 | + |
| 7 | +const fs = require('fs-extra'); |
| 8 | +const ghostUser = require('../../lib/utils/use-ghost-user'); |
5 | 9 |
|
6 | 10 | const migrations = require('../../lib/migrations');
|
7 | 11 |
|
8 | 12 | describe('Unit: Migrations', function () {
|
| 13 | + const sandbox = sinon.sandbox.create(); |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + sandbox.restore(); |
| 17 | + }); |
| 18 | + |
9 | 19 | describe('ensureSettingsFolder', function () {
|
10 |
| - const setupEnv = require('../utils/env'); |
11 |
| - const path = require('path'); |
12 |
| - const fs = require('fs'); |
| 20 | + it('if ghost user owns directory, runs `sudo mkdir` as ghost user', function () { |
| 21 | + const ghostUserStub = sandbox.stub(ghostUser, 'shouldUseGhostUser').returns(true); |
| 22 | + const sudoStub = sandbox.stub().resolves(); |
| 23 | + const config = createConfig(); |
| 24 | + config.get.withArgs('paths.contentPath').returns('/var/www/ghost/content'); |
| 25 | + |
| 26 | + const context = { |
| 27 | + instance: {config: config}, |
| 28 | + ui: {sudo: sudoStub} |
| 29 | + }; |
| 30 | + |
| 31 | + return migrations[0].task(context).then(() => { |
| 32 | + expect(ghostUserStub.calledOnce).to.be.true; |
| 33 | + expect(ghostUserStub.calledWithExactly('/var/www/ghost/content')).to.be.true; |
| 34 | + expect(sudoStub.calledOnce).to.be.true; |
| 35 | + expect(sudoStub.calledWithExactly( |
| 36 | + 'mkdir /var/www/ghost/content/settings', |
| 37 | + {sudoArgs: '-E -u ghost'} |
| 38 | + )).to.be.true; |
| 39 | + }); |
| 40 | + }); |
13 | 41 |
|
14 |
| - it('creates settings folder if not existent', function () { |
15 |
| - const env = setupEnv(); |
16 |
| - const cwdStub = sinon.stub(process, 'cwd').returns(env.dir); |
17 |
| - const ensureSettingsFolder = migrations[0].task; |
| 42 | + it('if ghost user doesn\'t own directory, runs basic mkdir', function () { |
| 43 | + const ghostUserStub = sandbox.stub(ghostUser, 'shouldUseGhostUser').returns(false); |
| 44 | + const fsStub = sandbox.stub(fs, 'ensureDirSync'); |
| 45 | + const config = createConfig(); |
| 46 | + config.get.withArgs('paths.contentPath').returns('/var/www/ghost/content'); |
18 | 47 |
|
19 |
| - ensureSettingsFolder(); |
20 |
| - expect(cwdStub.calledOnce).to.be.true; |
21 |
| - expect(fs.existsSync(path.join(env.dir, 'content/settings'))).to.be.true; |
| 48 | + const context = {instance: {config: config}}; |
22 | 49 |
|
23 |
| - cwdStub.restore(); |
24 |
| - env.cleanup(); |
| 50 | + return migrations[0].task(context).then(() => { |
| 51 | + expect(ghostUserStub.calledOnce).to.be.true; |
| 52 | + expect(ghostUserStub.calledWithExactly('/var/www/ghost/content')).to.be.true; |
| 53 | + expect(fsStub.calledOnce).to.be.true; |
| 54 | + expect(fsStub.calledWithExactly('/var/www/ghost/content/settings')).to.be.true; |
| 55 | + }); |
25 | 56 | });
|
26 | 57 | });
|
27 | 58 | });
|
0 commit comments