-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tests as it is possible to get team account id
- Loading branch information
1 parent
bd86a78
commit c9f7d91
Showing
1 changed file
with
65 additions
and
9 deletions.
There are no files selected for viewing
74 changes: 65 additions & 9 deletions
74
src/practices/LanguageIndependent/TimeToSolvePractice.spec.ts
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,37 +1,93 @@ | ||
import moment from 'moment'; | ||
import nock from 'nock'; | ||
import { PullRequestState } from '../../inspectors/ICollaborationInspector'; | ||
import { CollaborationInspector } from '../../inspectors'; | ||
import { createTestContainer, TestContainerContext } from '../../inversify.config'; | ||
import { PracticeEvaluationResult } from '../../model'; | ||
import { GitHubNock } from '../../test/helpers/gitHubNock'; | ||
import { BitbucketPullRequestState } from '../../services'; | ||
import { BitbucketNock } from '../../test/helpers/bitbucketNock'; | ||
import { TimeToSolvePractice } from './TimeToSolvePractice'; | ||
|
||
describe('TimeToSolvePractice', () => { | ||
let practice: TimeToSolvePractice; | ||
let containerCtx: TestContainerContext; | ||
let bitbucketNock: BitbucketNock; | ||
const MockedCollaborationInspector = <jest.Mock<CollaborationInspector>>(<unknown>CollaborationInspector); | ||
let mockCollaborationInspector: CollaborationInspector; | ||
|
||
beforeEach(async () => { | ||
nock.cleanAll(); | ||
bitbucketNock = new BitbucketNock('pypy', 'pypy'); | ||
}); | ||
|
||
beforeAll(() => { | ||
containerCtx = createTestContainer(); | ||
containerCtx.container.bind('TimeToSolvePractice').to(TimeToSolvePractice); | ||
practice = containerCtx.container.get('TimeToSolvePractice'); | ||
mockCollaborationInspector = new MockedCollaborationInspector(); | ||
}); | ||
|
||
afterEach(async () => { | ||
containerCtx.virtualFileSystemService.clearFileSystem(); | ||
containerCtx.practiceContext.fileInspector!.purgeCache(); | ||
}); | ||
|
||
it('', async () => { | ||
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://github.com/octocat/Hello-World'; | ||
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls( | ||
[{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' }], | ||
PullRequestState.open, | ||
); | ||
it('returns practicing if there are open pullrequests updated or created less than 30 days from now', async () => { | ||
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://bitbucket.org/pypy/pypy'; | ||
nock(bitbucketNock.url) | ||
.get('/users/pypy') | ||
.reply(200); | ||
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open); | ||
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(10, 'days').asMilliseconds() }; | ||
mockCollaborationInspector.getPullRequests = async () => { | ||
return bitbucketNock.mockBitbucketPullRequestsResponse(args); | ||
}; | ||
|
||
const evaluated = await practice.evaluate({ | ||
...containerCtx.practiceContext, | ||
collaborationInspector: mockCollaborationInspector, | ||
}); | ||
|
||
const evaluated = await practice.evaluate(containerCtx.practiceContext); | ||
expect(evaluated).toEqual(PracticeEvaluationResult.practicing); | ||
}); | ||
|
||
it('returns practicing if there are open pullrequests updated or created more than 30 days from now', async () => { | ||
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://bitbucket.org/pypy/pypy'; | ||
nock(bitbucketNock.url) | ||
.get('/users/pypy') | ||
.reply(200); | ||
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open); | ||
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(100, 'days').asMilliseconds() }; | ||
mockCollaborationInspector.getPullRequests = async () => { | ||
return bitbucketNock.mockBitbucketPullRequestsResponse(args); | ||
}; | ||
|
||
const evaluated = await practice.evaluate({ | ||
...containerCtx.practiceContext, | ||
collaborationInspector: mockCollaborationInspector, | ||
}); | ||
|
||
expect(evaluated).toEqual(PracticeEvaluationResult.notPracticing); | ||
}); | ||
|
||
it('returns practicing if there are no open pullrequest', async () => { | ||
mockCollaborationInspector.getPullRequests = async () => { | ||
return bitbucketNock.mockBitbucketPullRequestsResponse({}); | ||
}; | ||
|
||
const evaluated = await practice.evaluate({ | ||
...containerCtx.practiceContext, | ||
collaborationInspector: mockCollaborationInspector, | ||
}); | ||
expect(evaluated).toEqual(PracticeEvaluationResult.practicing); | ||
}); | ||
|
||
it('returns always true, as it is always applicable', async () => { | ||
const response = await practice.isApplicable(); | ||
expect(response).toBe(true); | ||
}); | ||
|
||
it('returns unknown if there is no collaborationInspector', async () => { | ||
const evaluated = await practice.evaluate({ ...containerCtx.practiceContext, collaborationInspector: undefined }); | ||
expect(evaluated).toEqual(PracticeEvaluationResult.unknown); | ||
}); | ||
}); |