Skip to content

Add test for Migration Helper (#518) #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions __tests__/tests/utilities/migration-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { getRepoIdFromUrl, toOldIssueFormat, toOldUserFormat } from 'utils';

describe('Migration Helper', () => {
it('should return a repo id in {username}/{reponame} format', () => {
const result = getRepoIdFromUrl('https://api.github.com/repos/octocat/Hello-World');

expect(result).toBe('octocat/Hello-World');
});

it('should convert a user object to old format', () => {
const user = {};
const result = toOldUserFormat(user);
const resultKeys = Object.keys(result);

expect(result.avatar_url).toBe(user.avatarUrl);
expect(Object.keys(user).reduce((accum, key) => accum && resultKeys.includes(key), true)).toBe(true);
});

it('should convert an issue object to old format', () => {
const issue = {
author: {},
comments: {
totalCount: 7,
},
closedAt: '',
createdAt: '',
number: 42,
state: 'StAte',
};
const repoId = 'git-point';
const result = toOldIssueFormat(issue, repoId);
const resultKeys = Object.keys(result);

expect(Object.keys(issue).reduce((accum, key) => accum && resultKeys.includes(key), true)).toBe(true);
expect(result.comments).toBe(issue.comments.totalCount);
expect(result.closed_at).toBe(issue.closedAt);
expect(result.created_at).toBe(issue.createdAt);
expect(result.state).toBe('state');
expect(result.pull_request).toBeNull();
expect(result.url).toBe('https://api.github.com/repos/git-point/issues/42');

expect(toOldIssueFormat(issue, repoId, false).pull_request).toBeNull();
expect(toOldIssueFormat(issue, repoId, true).pull_request).toMatchObject({});
});
});