Skip to content
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

PR for Issue6: projectOwner & projectName is not set in .all-contributorsrc file. #80

Merged
merged 13 commits into from
May 29, 2018
4 changes: 3 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@
"profile": "https://in.linkedin.com/in/mzubairahmed",
"contributions": [
"doc",
"bug"
"bug",
"code",
"test"
]
},
{
Expand Down
34 changes: 31 additions & 3 deletions src/util/__tests__/config-file.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import configFile from '../config-file'

const absentFile = './abc'
const expected = `Configuration file not found: ${absentFile}`
const absentConfileFileExpected = `Configuration file not found: ${absentFile}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed this as, we have more test with expected in this file now.

const incompleteConfigFilePath = './.all-contributorsrc'
const NoOwnerConfigFile = {
projectOwner: '',
projectName: 'all-contributors-cli',
imageSize: 100,
commit: false,
contributorsPerLine: 6,
contributors: [],
}
const NoNameConfigFile = {
projectOwner: 'jfmengels',
projectName: '',
imageSize: 100,
commit: false,
contributorsPerLine: 6,
contributors: [],
}

test('Reading an absent configuration file throws a helpful error', () => {
expect(() => configFile.readConfig(absentFile)).toThrowError(expected)
expect(() => configFile.readConfig(absentFile)).toThrowError(
absentConfileFileExpected,
)
})

test('Writing contributors in an absent configuration file throws a helpful error', async () => {
const resolvedError = await configFile
.writeContributors(absentFile, [])
.catch(e => e)
expect(resolvedError.message).toBe(expected)
expect(resolvedError.message).toBe(absentConfileFileExpected)
})

test('Should throw error and not allow editing config file if project name or owner is not set', () => {
expect(() =>
configFile.writeConfig(incompleteConfigFilePath, NoOwnerConfigFile),
).toThrow(`Error! Project owner is not set in ${incompleteConfigFilePath}`)
expect(() =>
configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile),
).toThrow(`Error! Project name is not set in ${incompleteConfigFilePath}`)
})
6 changes: 6 additions & 0 deletions src/util/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function readConfig(configPath) {
}

function writeConfig(configPath, content) {
if (!content.projectOwner) {
throw new Error(`Error! Project owner is not set in ${configPath}`)
}
if (!content.projectName) {
throw new Error(`Error! Project name is not set in ${configPath}`)
}
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
}

Expand Down