Skip to content

Commit

Permalink
test(platforms): update test cases for platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jan 4, 2017
1 parent c0f08bb commit 2d734d1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 103 deletions.
93 changes: 0 additions & 93 deletions source/platforms/_tests/GitHub.test.js

This file was deleted.

92 changes: 92 additions & 0 deletions source/platforms/_tests/GitHub.test.ts
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);
});
});
});
10 changes: 0 additions & 10 deletions source/platforms/_tests/platform.test.js

This file was deleted.

7 changes: 7 additions & 0 deletions source/platforms/_tests/platform.test.ts
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');
});

0 comments on commit 2d734d1

Please sign in to comment.