1
0
Fork 0
cautious-journey/test/TestMain.ts

98 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-08-28 16:01:39 +00:00
import { NotImplementedError } from '@apextoaster/js-utils';
import { expect } from 'chai';
import { Container, NullLogger } from 'noicejs';
import sinon from 'sinon';
2020-08-28 16:01:39 +00:00
import { Commands, ParsedArgs } from '../src/config/args';
import { GithubRemote, mainProject, Remote, RemoteOptions, STATUS_FAILURE, STATUS_SUCCESS } from '../src/main';
import { RemoteModule } from '../src/module/RemoteModule';
2020-08-31 13:43:01 +00:00
import { ProjectConfig } from '../src/config';
2020-08-28 16:01:39 +00:00
const { createStubInstance } = sinon;
2020-08-28 16:01:39 +00:00
const TEST_REMOTE = 'test-remote';
2020-08-31 13:43:01 +00:00
const TEST_PROJECT: ProjectConfig = {
colors: [],
comment: false,
flags: [],
initial: [],
name: 'bar',
remote: {
data: {},
dryrun: true,
logger: NullLogger.global,
type: TEST_REMOTE,
},
states: [],
};
2020-08-28 16:01:39 +00:00
describe('main app', () => {
it('should parse command line arguments');
it('should load config from file');
2020-08-28 16:01:39 +00:00
it('should create a remote', async () => {
const args: ParsedArgs = {
config: '',
dryrun: true,
2021-07-30 04:52:44 +00:00
mode: Commands.GRAPH,
2020-08-28 16:01:39 +00:00
};
const logger = NullLogger.global;
const remote = createStubInstance(GithubRemote);
remote.connect.returns(Promise.resolve(true));
const module = new RemoteModule();
module.bind<Remote, Remote, RemoteOptions>(TEST_REMOTE).toInstance(remote);
const container = Container.from(module);
await container.configure();
2021-07-30 04:52:44 +00:00
const status = await mainProject(args, container, logger, args.mode, TEST_PROJECT);
2020-08-28 16:01:39 +00:00
expect(status).to.equal(STATUS_SUCCESS);
});
it('should report connection failures', async () => {
const args: ParsedArgs = {
config: '',
dryrun: true,
2021-07-30 04:52:44 +00:00
mode: Commands.GRAPH,
2020-08-28 16:01:39 +00:00
};
const logger = NullLogger.global;
const remote = createStubInstance(GithubRemote);
remote.connect.returns(Promise.resolve(false));
const module = new RemoteModule();
module.bind<Remote, Remote, RemoteOptions>(TEST_REMOTE).toInstance(remote);
const container = Container.from(module);
await container.configure();
2021-07-30 04:52:44 +00:00
const status = await mainProject(args, container, logger, args.mode, TEST_PROJECT);
2020-08-28 16:01:39 +00:00
expect(status).to.equal(STATUS_FAILURE);
});
it('should not connect to skipped projects', async () => {
const args: ParsedArgs = {
config: '',
dryrun: true,
2021-07-30 04:52:44 +00:00
mode: Commands.GRAPH,
2020-08-28 16:01:39 +00:00
project: ['foo']
};
const logger = NullLogger.global;
const remote = createStubInstance(GithubRemote);
remote.connect.throws(new NotImplementedError());
const module = new RemoteModule();
module.bind<Remote, Remote, RemoteOptions>(TEST_REMOTE).toInstance(remote);
const container = Container.from(module);
await container.configure();
2021-07-30 04:52:44 +00:00
const status = await mainProject(args, container, logger, args.mode, TEST_PROJECT);
2020-08-28 16:01:39 +00:00
expect(status).to.equal(STATUS_SUCCESS);
expect(remote.connect).to.have.callCount(0);
});
});