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
1 parent
ab007b9
commit 5f41130
Showing
3 changed files
with
54 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,20 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const templatePath = path.join(__dirname, '/../../templates/'); | ||
const copy = require('../utils/copy'); | ||
|
||
const create = name => { | ||
const file = path.join(templatePath, 'migration-default.yml'); | ||
const snakeCase = name | ||
.split(/(?=[A-Z])/) | ||
.join('_') | ||
.toLowerCase(); | ||
const fileName = `${Date.now()}_${snakeCase}`; | ||
|
||
copy.file(file, fileName, 'migrations'); | ||
}; | ||
|
||
module.exports = { | ||
create | ||
}; |
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,24 @@ | ||
const sinon = require('sinon'); | ||
const expect = require('chai').expect; | ||
const path = require('path'); | ||
const migrations = require('../src/migrations'); | ||
const copy = require('../src/utils/copy'); | ||
|
||
describe('Migrations', function() { | ||
afterEach(function() { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should invoke copy.file with migration-default file', function() { | ||
const fakePath = 'directory/migration-default.yml'; | ||
const pathStub = sinon.stub(path, 'join').returns(fakePath); | ||
const copyStub = sinon.stub(copy, 'file'); | ||
const now = Date.now(); | ||
sinon.useFakeTimers(now); | ||
|
||
migrations.create('CustomName'); | ||
|
||
expect(pathStub.calledOnceWithExactly(sinon.match.string, 'migration-default.yml')).to.be.true; | ||
expect(copyStub.calledOnceWithExactly(fakePath, `${now}_custom_name`, 'migrations')).to.be.true; | ||
}); | ||
}); |