-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(platforms): update test cases for platforms
- Loading branch information
Showing
4 changed files
with
99 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,92 @@ | ||
import { GitHub } from '../GitHub'; | ||
import { FakeCI } from '../../ci_source/providers/Fake'; | ||
import { readFileSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
import * as os from 'os'; | ||
const fixtures = resolve(__dirname, 'fixtures'); | ||
const EOL = os.EOL; | ||
|
||
// Gets a mocked out GitHub class for checking a get path | ||
const mockGitHubWithGetForPath = (expectedPath): GitHub => { | ||
const mockSource = new FakeCI({}); | ||
const github = new GitHub('Token', mockSource); | ||
|
||
github.get = (path: string, headers: any = {}, body: any = {}, method: string = 'GET'): Promise<any> => { | ||
return new Promise((resolve: any, reject: any) => { | ||
expect(path).toBe(expectedPath); | ||
resolve({}); | ||
}); | ||
}; | ||
|
||
return github; | ||
}; | ||
|
||
/** Returns JSON from the fixtured dir */ | ||
const requestWithFixturedJSON = async (path: string): Promise<any> => { | ||
const json = JSON.parse(readFileSync(`${fixtures}/${path}`, {}).toString()); | ||
return () => { | ||
return { | ||
json: () => Promise.resolve(json) | ||
}; | ||
}; | ||
}; | ||
|
||
/** Returns arbitrary text value from a request */ | ||
const requestWithFixturedContent = async (path: string): Promise<any> => { | ||
const content = readFileSync(`${fixtures}/${path}`, {}).toString(); | ||
return () => { | ||
return { | ||
text: () => Promise.resolve(content) | ||
}; | ||
}; | ||
}; | ||
|
||
describe('API results', () => { | ||
it('sets the correct paths for pull request comments', () => { | ||
const expectedPath = 'repos/artsy/emission/issues/327/comments'; | ||
const github = mockGitHubWithGetForPath(expectedPath); | ||
expect(github.getPullRequestComments()); | ||
}); | ||
|
||
it('sets the correct paths for getPullRequestDiff', () => { | ||
const expectedPath = 'repos/artsy/emission/pulls/327'; | ||
const github = mockGitHubWithGetForPath(expectedPath); | ||
expect(github.getPullRequestDiff()); | ||
}); | ||
}); | ||
|
||
describe('with fixtured data', () => { | ||
it('returns the correct github data', async () => { | ||
const mockSource = new FakeCI({}); | ||
const github = new GitHub('Token', mockSource); | ||
github.getPullRequestInfo = await requestWithFixturedJSON('github_pr.json'); | ||
|
||
const info = await github.getReviewInfo(); | ||
expect(info.title).toEqual('Adds support for showing the metadata and trending Artists to a Gene VC'); | ||
}); | ||
|
||
describe('the dangerfile gitDSL', async () => { | ||
let github = {}; | ||
beforeEach(async () => { | ||
github = new GitHub('Token', new FakeCI({})); | ||
(github as any).getPullRequestDiff = await requestWithFixturedContent('github_diff.diff'); | ||
}); | ||
|
||
it('sets the modified/created/deleted', async () => { | ||
const gitDSL = await (github as any).getReviewDiff(); | ||
|
||
expect(gitDSL.modified_files).toEqual(['CHANGELOG.md', 'data/schema.graphql', 'data/schema.json', 'externals/metaphysics', 'lib/__mocks__/react-relay.js', 'lib/components/artist/about.js', 'lib/components/gene/header.js', 'lib/containers/__tests__/__snapshots__/gene-tests.js.snap', 'lib/containers/__tests__/gene-tests.js', 'lib/containers/gene.js', 'tsconfig.json']); //tslint:disable-line:max-line-length | ||
|
||
expect(gitDSL.created_files).toEqual(['lib/components/gene/about.js', 'lib/components/gene/biography.js', 'lib/components/related_artists/index.js', 'lib/components/related_artists/related_artist.js']); //tslint:disable-line:max-line-length | ||
|
||
expect(gitDSL.deleted_files).toEqual(['lib/components/artist/related_artists/index.js', 'lib/components/artist/related_artists/related_artist.js', 'lib/components/gene/about_gene.js']); //tslint:disable-line:max-line-length | ||
}); | ||
|
||
it('shows the diff for a specific file', async () => { | ||
const expected = ` - [dev] Updates Flow to 0.32 - orta${EOL} - [dev] Updates React to 0.34 - orta${EOL} - [dev] Turns on "keychain sharing" to fix a keychain bug in sim - orta${EOL}+- GeneVC now shows about information, and trending artists - orta${EOL} ${EOL} ### 1.1.0-beta.2${EOL} `; //tslint:disable-line:max-line-length | ||
const gitDSL = await (github as any).getReviewDiff(); | ||
|
||
expect(gitDSL.diffForFile('CHANGELOG.md')).toEqual(expected); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
import { getPlatformForEnv } from '../platform'; | ||
|
||
it('should bail if there is no DANGER_GITHUB_API_TOKEN found', () => { | ||
(expect as any)(() => { | ||
getPlatformForEnv({} as any, {} as any); | ||
}).toThrow('Cannot use authenticated API requests'); | ||
}); |