-
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.
test(lib): adds test to github and npm
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const authenticatedUserToken = 'some-token'; | ||
export const createAuthorization = jest | ||
.fn() | ||
.mockResolvedValue({ data: { token: authenticatedUserToken } }); | ||
export const createRepoForAuthenticatedUser = jest.fn(); | ||
|
||
const mock = jest.fn().mockImplementation(() => ({ | ||
repos: { createForAuthenticatedUser: createRepoForAuthenticatedUser }, | ||
oauthAuthorizations: { createAuthorization }, | ||
})); | ||
|
||
export default mock; |
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,5 @@ | ||
export const loginCouch = jest.fn(); | ||
|
||
const mock = { loginCouch }; | ||
|
||
export default mock; |
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 Octokit, { | ||
createRepoForAuthenticatedUser, | ||
createAuthorization, | ||
authenticatedUserToken, | ||
} from '@octokit/rest'; | ||
import Github from './github'; | ||
|
||
describe('Github', () => { | ||
let github; | ||
const username = 'some-username'; | ||
const password = 'some-password'; | ||
const on2fa = jest.fn(); | ||
|
||
beforeEach(() => { | ||
Octokit.mockClear(); | ||
createRepoForAuthenticatedUser.mockClear(); | ||
createAuthorization.mockClear(); | ||
|
||
github = new Github(username, password, on2fa); | ||
}); | ||
|
||
it('should create a new Github instance', () => { | ||
expect(Octokit).toBeCalledWith({ | ||
auth: { | ||
username, | ||
password, | ||
on2fa, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create-repository', () => { | ||
const name = 'some-name'; | ||
const description = 'some-description'; | ||
|
||
github.createRepository({ name, description }); | ||
|
||
expect(createRepoForAuthenticatedUser).toBeCalledWith({ | ||
name, | ||
description, | ||
}); | ||
}); | ||
|
||
it('should create-createToken', async () => { | ||
const note = 'some-note'; | ||
const scopes = 'some-scopes'; | ||
|
||
const token = await github.createToken(note, scopes); | ||
|
||
expect(token).toBe(authenticatedUserToken); | ||
expect(createAuthorization).toBeCalledWith({ | ||
note, | ||
scopes, | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import npmProfile from 'npm-profile'; | ||
import { login } from './npm'; | ||
|
||
describe('npm', () => { | ||
it('should login', () => { | ||
const username = 'some-username'; | ||
const password = 'some-password'; | ||
|
||
login({ username, password }); | ||
|
||
expect(npmProfile.loginCouch).toBeCalledWith(username, password, { | ||
registry: 'https://registry.npmjs.org', | ||
}); | ||
}); | ||
}); |