-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): cover token entity, github client
- Loading branch information
Showing
7 changed files
with
184 additions
and
58 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { Token, TokenOptions } from '../../../src/entity/auth/Token'; | ||
import { describeLeaks, itLeaks } from '../../helpers/async'; | ||
|
||
describeLeaks('token entity', async () => { | ||
itLeaks('should copy options', async () => { | ||
const testProps = { | ||
audience: ['test'], | ||
expiresAt: new Date(), | ||
issuer: 'test', | ||
subject: 'test', | ||
}; | ||
const data: TokenOptions = { | ||
...testProps, | ||
data: {}, | ||
grants: [], | ||
labels: {}, | ||
}; | ||
const token = new Token(data); | ||
expect(token).to.deep.include(testProps); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { App } from '@octokit/app'; | ||
import Octokit from '@octokit/rest'; | ||
import { expect } from 'chai'; | ||
import { ineeda } from 'ineeda'; | ||
import { match, stub } from 'sinon'; | ||
|
||
import { GithubClient } from '../../../src/utils/github'; | ||
import { describeLeaks, itLeaks } from '../../helpers/async'; | ||
import { createServiceContainer } from '../../helpers/container'; | ||
|
||
// tslint:disable:no-any | ||
describeLeaks('github client', async () => { | ||
itLeaks('should poll for new tokens', async () => { | ||
const getInstallationAccessToken = stub().returns('test'); | ||
const app = stub().returns(ineeda<App>({ | ||
getInstallationAccessToken, | ||
})) as any; | ||
const { container } = await createServiceContainer(); | ||
const client = await container.create(GithubClient, { | ||
app, | ||
data: { | ||
agent: '', | ||
app: { | ||
id: 0, | ||
key: '', | ||
}, | ||
installation: { | ||
id: 0, | ||
}, | ||
}, | ||
}); | ||
const token = await client.renewToken(); | ||
|
||
expect(getInstallationAccessToken).to.have.callCount(1); | ||
expect(token).to.equal('token test'); | ||
}); | ||
|
||
itLeaks('should poll for new tokens', async () => { | ||
const kit = stub().returns(ineeda<Octokit>()) as any; | ||
const { container } = await createServiceContainer(); | ||
await container.create(GithubClient, { | ||
data: { | ||
agent: '', | ||
app: { | ||
id: 0, | ||
key: '', | ||
}, | ||
installation: { | ||
id: 0, | ||
}, | ||
}, | ||
kit, | ||
}); | ||
expect(kit).to.have.been.calledWithMatch(match.has('auth', match.func)); | ||
}); | ||
}); |