-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable no-template-curly-in-string */ | ||
const { writeFile, existsSync } = require('fs'); | ||
const { dump } = require('js-yaml'); | ||
|
||
const defaultConfig = { | ||
service: 'my-service', | ||
provider: { | ||
name: 'ssm' | ||
}, | ||
config: { | ||
path: '/${stage}/config', | ||
defaults: { | ||
DB_NAME: 'my-database', | ||
DB_HOST: 3200 | ||
}, | ||
required: { | ||
DB_TABLE: 'some database table name for ${stage}' | ||
} | ||
}, | ||
secret: { | ||
path: '/${stage}/secret', | ||
required: { | ||
DB_PASSWORD: 'secret database password' | ||
} | ||
} | ||
}; | ||
|
||
const makeGenerate = () => async () => { | ||
if (existsSync('oprah.yml')) { | ||
throw new Error( | ||
`oprah.yml file already exists in the following directory -- ${process.cwd()}` | ||
); | ||
} | ||
|
||
writeFile('oprah.yml', dump(defaultConfig), () => {}); | ||
}; | ||
|
||
module.exports = { | ||
defaultConfig, | ||
makeGenerate | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { dump } = require('js-yaml'); | ||
|
||
const mockWriteFile = jest.fn(); | ||
const mockExists = jest.fn(); | ||
|
||
jest.mock('fs', () => ({ | ||
writeFile: mockWriteFile, | ||
existsSync: mockExists | ||
})); | ||
|
||
const { makeGenerate, defaultConfig } = require('./make-generate'); | ||
|
||
describe('make generate', () => { | ||
describe('when file exists', () => { | ||
it('throws an error', async () => { | ||
mockExists.mockReturnValueOnce(true); | ||
const generate = makeGenerate(); | ||
await expect(generate).rejects.toThrow( | ||
`oprah.yml file already exists in the following directory -- ${process.cwd()}` | ||
); | ||
}); | ||
}); | ||
|
||
describe('when file doesnt exist', () => { | ||
it('generates file', async () => { | ||
mockExists.mockReturnValueOnce(false); | ||
const generate = makeGenerate(); | ||
await generate(); | ||
expect(mockWriteFile).toHaveBeenCalledWith( | ||
'oprah.yml', | ||
dump(defaultConfig), | ||
expect.any(Function) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters