Skip to content

Commit

Permalink
Merge pull request #15 from dschep/lifecycle-hooks
Browse files Browse the repository at this point in the history
Update lifecycle Hooks
  • Loading branch information
marcy-terui authored Oct 7, 2017
2 parents 8142689 + 0074b2e commit dadd6e9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@ class Crypt {
};

this.hooks = {
'before:deploy:function:deploy': () => BbPromise.bind(this)
'before:deploy:function:packageFunction': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:deploy:function:deploy': () => BbPromise.bind(this)
'after:deploy:function:packageFunction': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'before:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:deploy:deploy': () => BbPromise.bind(this)
'after:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'before:invoke:local:invoke': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:invoke:local:invoke': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'encrypt:encrypt': () => BbPromise.bind(this)
Expand Down
48 changes: 40 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ describe('Crypt', () => {
// expect(cryptWithEmptyOptions.options).to.deep.equal({});
// });

it('should run promise chain in order for before:deploy:function:deploy', () => {
it('should run promise chain in order for before:deploy:function:packageFunction', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const addLibrariesStub = sinon
.stub(crypt, 'addLibraries').returns(BbPromise.resolve());

return crypt.hooks['before:deploy:function:deploy']().then(() => {
return crypt.hooks['before:deploy:function:packageFunction']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(addLibrariesStub.calledAfter(validateStub))
.to.equal(true);
Expand All @@ -73,13 +73,13 @@ describe('Crypt', () => {
});
});

it('should run promise chain in order for after:deploy:function:deploy', () => {
it('should run promise chain in order for after:deploy:function:packageFunction', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const removeLibrariesStub = sinon
.stub(crypt, 'removeLibraries').returns(BbPromise.resolve());

return crypt.hooks['after:deploy:function:deploy']().then(() => {
return crypt.hooks['after:deploy:function:packageFunction']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(removeLibrariesStub.calledAfter(validateStub))
.to.equal(true);
Expand All @@ -89,13 +89,13 @@ describe('Crypt', () => {
});
});

it('should run promise chain in order for before:deploy:createDeploymentArtifacts', () => {
it('should run promise chain in order for before:package:createDeploymentArtifacts', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const addLibrariesStub = sinon
.stub(crypt, 'addLibraries').returns(BbPromise.resolve());

return crypt.hooks['before:deploy:createDeploymentArtifacts']().then(() => {
return crypt.hooks['before:package:createDeploymentArtifacts']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(addLibrariesStub.calledAfter(validateStub))
.to.equal(true);
Expand All @@ -105,13 +105,45 @@ describe('Crypt', () => {
});
});

it('should run promise chain in order for after:deploy:deploy', () => {
it('should run promise chain in order for after:package:createDeploymentArtifacts', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const removeLibrariesStub = sinon
.stub(crypt, 'removeLibraries').returns(BbPromise.resolve());

return crypt.hooks['after:deploy:deploy']().then(() => {
return crypt.hooks['after:package:createDeploymentArtifacts']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(removeLibrariesStub.calledAfter(validateStub))
.to.equal(true);

crypt.validate.restore();
crypt.removeLibraries.restore();
});
});

it('should run promise chain in order for before:invoke:local:invoke', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const addLibrariesStub = sinon
.stub(crypt, 'addLibraries').returns(BbPromise.resolve());

return crypt.hooks['before:invoke:local:invoke']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(addLibrariesStub.calledAfter(validateStub))
.to.equal(true);

crypt.validate.restore();
crypt.addLibraries.restore();
});
});

it('should run promise chain in order for after:invoke:local:invoke', () => {
const validateStub = sinon
.stub(crypt, 'validate').returns(BbPromise.resolve());
const removeLibrariesStub = sinon
.stub(crypt, 'removeLibraries').returns(BbPromise.resolve());

return crypt.hooks['after:invoke:local:invoke']().then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(removeLibrariesStub.calledAfter(validateStub))
.to.equal(true);
Expand Down

0 comments on commit dadd6e9

Please sign in to comment.