-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
171 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,119 @@ | ||
import { NotImplementedError } from '@apextoaster/js-utils'; | ||
import { expect } from 'chai'; | ||
import { Container, NullLogger } from 'noicejs'; | ||
import { createStubInstance } from 'sinon'; | ||
|
||
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'; | ||
|
||
const TEST_REMOTE = 'test-remote'; | ||
|
||
describe('main app', () => { | ||
it('should parse command line arguments'); | ||
it('should load config from file'); | ||
it('should create a remote'); | ||
it('should fail on errors'); | ||
|
||
it('should create a remote', async () => { | ||
const args: ParsedArgs = { | ||
config: '', | ||
dryrun: true, | ||
}; | ||
const logger = NullLogger.global; | ||
const mode = Commands.GRAPH; | ||
|
||
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(); | ||
|
||
const status = await mainProject(args, container, logger, mode, { | ||
colors: [], | ||
comment: false, | ||
flags: [], | ||
name: '', | ||
remote: { | ||
data: {}, | ||
dryrun: true, | ||
logger, | ||
type: TEST_REMOTE, | ||
}, | ||
states: [], | ||
}); | ||
|
||
expect(status).to.equal(STATUS_SUCCESS); | ||
}); | ||
|
||
it('should report connection failures', async () => { | ||
const args: ParsedArgs = { | ||
config: '', | ||
dryrun: true, | ||
}; | ||
const logger = NullLogger.global; | ||
const mode = Commands.GRAPH; | ||
|
||
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(); | ||
|
||
const status = await mainProject(args, container, logger, mode, { | ||
colors: [], | ||
comment: false, | ||
flags: [], | ||
name: '', | ||
remote: { | ||
data: {}, | ||
dryrun: true, | ||
logger, | ||
type: TEST_REMOTE, | ||
}, | ||
states: [], | ||
}); | ||
|
||
expect(status).to.equal(STATUS_FAILURE); | ||
}); | ||
|
||
it('should not connect to skipped projects', async () => { | ||
const args: ParsedArgs = { | ||
config: '', | ||
dryrun: true, | ||
project: ['foo'] | ||
}; | ||
const logger = NullLogger.global; | ||
const mode = Commands.GRAPH; | ||
|
||
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(); | ||
|
||
const status = await mainProject(args, container, logger, mode, { | ||
colors: [], | ||
comment: false, | ||
flags: [], | ||
name: 'bar', | ||
remote: { | ||
data: {}, | ||
dryrun: true, | ||
logger, | ||
type: TEST_REMOTE, | ||
}, | ||
states: [], | ||
}); | ||
|
||
expect(status).to.equal(STATUS_SUCCESS); | ||
expect(remote.connect).to.have.callCount(0); | ||
}); | ||
}); |