Skip to content

Commit

Permalink
fix: use method to change the message of the repo commits
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Dec 6, 2019
1 parent bf18140 commit bbf2136
Showing 1 changed file with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { createTestContainer, TestContainerContext } from '../../inversify.confi
import { PracticeEvaluationResult } from '../../model';
import { getRepoCommitsServiceResponse } from '../../services/git/__MOCKS__/gitHubServiceMockFolder/getRepoCommitsServiceResponse.mock';
import { CorrectCommitMessagesPractice } from './CorrectCommitMessagesPractice';
import { Paginated } from '../../inspectors/common/Paginated';
import { Commit } from '../../services/git/model';
import _ from 'lodash';

describe('CorrectCommitMessagesPractice', () => {
let practice: CorrectCommitMessagesPractice;
Expand All @@ -29,10 +32,7 @@ describe('CorrectCommitMessagesPractice', () => {

it('returns practicing if the commit messages are correct', async () => {
mockCollaborationInspector.getRepoCommits = async () => {
getRepoCommitsServiceResponse.items.forEach((item) => {
item.message = 'fix: correct commit message';
});
return getRepoCommitsServiceResponse;
return changeRepoCommitsMessages('fix: correct commit message');
};

const evaluated = await practice.evaluate({
Expand All @@ -44,10 +44,7 @@ describe('CorrectCommitMessagesPractice', () => {

it('returns not practicing if the commit messages are incorrect', async () => {
mockCollaborationInspector.getRepoCommits = async () => {
getRepoCommitsServiceResponse.items.forEach((item) => {
item.message = 'Incorrect commit message';
});
return getRepoCommitsServiceResponse;
return changeRepoCommitsMessages('Incorrect commit message');
};

const evaluated = await practice.evaluate({
Expand All @@ -66,4 +63,27 @@ describe('CorrectCommitMessagesPractice', () => {
const response = await practice.isApplicable();
expect(response).toBe(true);
});

const changeRepoCommitsMessages = (message: string) => {
const paginatedRepoCommits: Paginated<Commit> = {
items: getRepoCommitsServiceResponse.items,
hasNextPage: true,
hasPreviousPage: false,
page: 1,
perPage: getRepoCommitsServiceResponse.items.length,
totalCount: getRepoCommitsServiceResponse.items.length,
};
if (getRepoCommitsServiceResponse.items.length > 1) {
const repoCommits: Commit[] = _.cloneDeep(getRepoCommitsServiceResponse.items);
repoCommits.forEach((repoCommit) => {
repoCommit.message = message;
repoCommits.push(repoCommit);
});

paginatedRepoCommits.items = repoCommits;
} else {
getRepoCommitsServiceResponse.items[0].message = message;
}
return paginatedRepoCommits;
};
});

0 comments on commit bbf2136

Please sign in to comment.