Skip to content

Commit

Permalink
Increased coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonGebben committed Aug 14, 2019
1 parent b93d062 commit f5bc8f1
Show file tree
Hide file tree
Showing 12 changed files with 2,419 additions and 1,928 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"max-len": [
"warn",
80
120
],
"no-console": [
"error"
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/configure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { logger } = require('../../utils/logger');
const chalk = require('chalk');

const configure = async() => {
if(await checkConfigExists()){
if (await checkConfigExists()) {
logger.log(chalk.red.bold('⚠️ Mergify is already configured. Configuring again will override the existing file.'));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/getAllAssigned/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { printMergeRequest } = require('../../utils/printMergeRequest');
const { simplifyMergeRequest } = require('../../utils/simplifyMergeRequest');

const getAllAssigned = async({ userId }) => {
spinner.text = "Retrieving all Merge Requests assigned to you"
spinner.text = 'Retrieving all Merge Requests assigned to you';
spinner.start();
const params = {
assignee_id: userId
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/getAllSubmitted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { printMergeRequest } = require('../../utils/printMergeRequest');
const { simplifyMergeRequest } = require('../../utils/simplifyMergeRequest');

const getAllSubmitted = async({ userId }) => {
spinner.text = "Retrieving all Merge Requests that you submitted"
spinner.text = 'Retrieving all Merge Requests that you submitted';
spinner.start();
const params = {
author_id: userId
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/verify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const UNAUTHORIZED_MESSAGE = '401 Unauthorized';

const verify = async({ userId }) => {
try {
spinner.text = "Verifying your config"
spinner.text = 'Verifying your config';
spinner.start();
const userResp = await doFetch(`users/${userId}`);

Expand Down
15 changes: 7 additions & 8 deletions lib/utils/checkConfigExists/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ const accessAsync = promisify(access);
const { getConfigPath } = require('../getConfigPath');

async function checkConfigExists() {
try {
await accessAsync(getConfigPath(), constants.F_OK);
return true;
}
catch(_){
return false;
}
try {
await accessAsync(getConfigPath(), constants.F_OK);
return true;
} catch (_) {
return false;
}
}

module.exports = {
checkConfigExists
checkConfigExists
};
39 changes: 19 additions & 20 deletions lib/utils/checkConfigExists/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ const { checkConfigExists } = require('./index.js');
const mock = require('mock-fs');

describe('utils/checkConfigExists', () => {
it('should return true when checking an existing config', async() => {
const configPath = `${__dirname}/../../../.config`;
mock({
[configPath]: ''
});

const fileExists = await checkConfigExists();

return expect(fileExists).toEqual(true);
it('should return true when checking an existing config', async() => {
const configPath = `${__dirname}/../../../.config`;
mock({
[configPath]: ''
});

it('should return false when not configured', async() => {
mock({
});

const fileExists = await checkConfigExists();

return expect(fileExists).toEqual(false);
});

afterEach(mock.restore);
const fileExists = await checkConfigExists();

return expect(fileExists).toEqual(true);
});


it('should return false when not configured', async() => {
mock({
});

const fileExists = await checkConfigExists();

return expect(fileExists).toEqual(false);
});

afterEach(mock.restore);
});
4 changes: 2 additions & 2 deletions lib/utils/getConfigPath/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function getConfigPath() {
return `${__dirname}/../../../.config`;;
return `${__dirname}/../../../.config`; ;
}

module.exports = {
getConfigPath
getConfigPath
};
20 changes: 19 additions & 1 deletion lib/utils/readConfig/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,23 @@ describe('utils/readConfig', () => {
return expect(config).toEqual(stub);
});

afterEach(mock.restore);
test('returns error when it cannot parse the config', async () => {
const configPath = `${__dirname}/../../../.config`;

// Calling console.log because of this;
// https://github.com/tschaub/mock-fs/issues/234
console.log();

mock({
[configPath]: '<html>,</html>',
});

const config = await readConfig();

return expect(config).toEqual({});
});

afterEach(() => {
mock.restore()
});
});
108 changes: 54 additions & 54 deletions lib/utils/simplifyMergeRequest/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
module.exports = {
mrs: [
{
"id": 1,
"iid": 1,
"target_branch": "master",
"source_branch": "test1",
"project_id": 3,
"title": "test1",
"state": "opened",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"name": "Administrator",
"state": "active",
"created_at": "2012-04-29T08:46:00Z"
id: 1,
iid: 1,
target_branch: 'master',
source_branch: 'test1',
project_id: 3,
title: 'test1',
state: 'opened',
created_at: '2017-04-29T08:46:00Z',
updated_at: '2017-04-29T08:46:00Z',
upvotes: 0,
downvotes: 0,
author: {
id: 1,
username: 'admin',
email: 'admin@example.com',
name: 'Administrator',
state: 'active',
created_at: '2012-04-29T08:46:00Z'
},
"assignee": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"name": "Administrator",
"state": "active",
"created_at": "2012-04-29T08:46:00Z"
assignee: {
id: 1,
username: 'admin',
email: 'admin@example.com',
name: 'Administrator',
state: 'active',
created_at: '2012-04-29T08:46:00Z'
},
"source_project_id": 2,
"target_project_id": 3,
"labels": [],
"description": "fixed login page css paddings",
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": null
source_project_id: 2,
target_project_id: 3,
labels: [],
description: 'fixed login page css paddings',
work_in_progress: false,
milestone: {
id: 5,
iid: 1,
project_id: 3,
title: 'v2.0',
description: 'Assumenda aut placeat expedita exercitationem labore sunt enim earum.',
state: 'closed',
created_at: '2015-02-02T19:49:26.013Z',
updated_at: '2015-02-02T19:49:26.013Z',
due_date: null
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"user_notes_count": 1,
"changes_count": "1",
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
merge_when_pipeline_succeeds: true,
merge_status: 'can_be_merged',
sha: '8888888888888888888888888888888888888888',
merge_commit_sha: null,
user_notes_count: 1,
changes_count: '1',
should_remove_source_branch: true,
force_remove_source_branch: false,
web_url: 'http://example.com/example/example/merge_requests/1',
time_stats: {
time_estimate: 0,
total_time_spent: 0,
human_time_estimate: null,
human_total_time_spent: null
}
}
]
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dependencies": {
"chalk": "^2.3.2",
"commander": "^2.15.1",
"inquirer": "^5.2.0",
"commander": "^3.0.0",
"inquirer": "^6.5.1",
"node-fetch": "^2.1.2",
"ora": "^2.0.0",
"ora": "^3.4.0",
"query-string": "^6.0.0",
"ramda": "^0.25.0"
"ramda": "^0.26.1"
},
"name": "@pindakaasman/mergify",
"repository": "https://github.com/RamonGebben/mergify.git",
Expand All @@ -20,14 +20,14 @@
"lib": "lib"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint": "^6.1.0",
"eslint-config-standard": "^13.0.1",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
"jest": "^22.4.3",
"jest-fetch-mock": "^1.5.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.8.0",
"jest-fetch-mock": "^2.1.2",
"mock-fs": "^4.4.2"
},
"scripts": {
Expand Down
Loading

0 comments on commit f5bc8f1

Please sign in to comment.