1
0
Fork 0
cautious-journey/test/remote/TestGithubRemote.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-08-28 16:02:19 +00:00
import { InvalidArgumentError } from '@apextoaster/js-utils';
import { Octokit } from '@octokit/rest';
2020-08-15 04:40:56 +00:00
import { expect } from 'chai';
2020-08-28 16:02:19 +00:00
import { BaseOptions, Container, NullLogger } from 'noicejs';
import { stub } from 'sinon';
import { RemoteModule } from '../../src/module/RemoteModule';
import { GithubRemote } from '../../src/remote/github';
2020-08-15 04:40:56 +00:00
describe('github remote', () => {
2020-08-28 16:02:19 +00:00
it('should create an octokit client with token auth', async () => {
const logger = NullLogger.global;
const module = new RemoteModule();
const container = Container.from(module);
await container.configure();
const client = stub();
module.bind<Octokit, Octokit, BaseOptions>(Octokit).toFactory(client);
const remote = await container.create(GithubRemote, {
data: {
token: 'foo',
type: 'token',
},
logger,
type: '',
});
const status = await remote.connect();
expect(status).to.equal(true);
expect(client).to.have.been.calledWithMatch({
auth: 'foo',
});
});
it('should throw on invalid auth methods', async () => {
const logger = NullLogger.global;
const module = new RemoteModule();
const container = Container.from(module);
await container.configure();
const client = stub();
module.bind<Octokit, Octokit, BaseOptions>(Octokit).toFactory(client);
const remote = await container.create(GithubRemote, {
data: {
type: 'test',
},
logger,
type: '',
});
return expect(remote.connect()).to.eventually.be.rejectedWith(InvalidArgumentError);
});
2020-08-15 04:40:56 +00:00
});