-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathadd.spec.ts
68 lines (52 loc) · 1.8 KB
/
add.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as chai from 'chai';
import * as mockery from 'mockery';
import * as sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { OPTIONS } from '../constants';
import { ManagementMode } from '../lib/license-manager';
import { addExports } from './utils';
const expect = chai.expect;
chai.use(sinonChai);
describe ('#AddCommand', () => {
let sandbox: sinon.SinonSandbox;
let manageLicenseStub: sinon.SinonStub;
let MockeryAddCommand;
before (() => {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
});
});
beforeEach (() => {
sandbox = sinon.createSandbox();
manageLicenseStub = sandbox.stub();
mockery.registerMock('./utils', { manageLicense: manageLicenseStub, addExports });
delete require.cache[require.resolve('./add.ts')];
MockeryAddCommand = require('./add.ts');
});
afterEach(() => {
sandbox.restore();
mockery.deregisterAll();
});
after(() => {
mockery.disable();
});
describe ('builder', () => {
it ('should configure yargs', () => {
const yargs = {
options: sinon.stub(),
usage: sinon.stub(),
};
const returned = MockeryAddCommand.builder(yargs);
expect(returned).to.deep.equal(yargs);
expect(yargs.options).to.have.been.calledOnceWithExactly(OPTIONS);
expect(yargs.usage).to.have.been.calledOnceWithExactly('license-check-and-add add');
});
});
describe ('handler', () => {
it ('should manage license', () => {
MockeryAddCommand.handler('some args');
expect(manageLicenseStub).to.have.been.calledOnceWithExactly('some args', ManagementMode.INSERT);
});
});
});