Skip to content

Commit

Permalink
fixed PR comments 1st attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
VladRomero committed Apr 25, 2017
1 parent 4f3bb2c commit f187856
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 106 deletions.
Empty file modified src/bin/barracks-integration-bigquery
100644 → 100755
Empty file.
Empty file modified src/bin/barracks-integration-bigquery-init
100644 → 100755
Empty file.
11 changes: 9 additions & 2 deletions src/commands/integration/SetGoogleClientSecretCommand
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const BarracksCommand = require('../BarracksCommand');
const Validator = require('../../utils/Validator');
const ReadFile = require('../../utils/FileReader');
const ObjectReader = require('../../utils/ObjectReader');

function getObject(program) {
if (program.file) {
return ObjectReader.readObjectFromFile(program.file);
} else {
return ObjectReader.readObjectFromStdin();
}
}
class SetGoogleClientSecretCommand extends BarracksCommand {

configureCommand(program) {
Expand All @@ -16,7 +23,7 @@ class SetGoogleClientSecretCommand extends BarracksCommand {
let token;
return this.getAuthenticationToken().then(authToken => {
token = authToken;
return ReadFile.getObject(program);
return getObject(program);
}).then(secret => {
return this.barracks.setGoogleClientSecret(token, secret);
});
Expand Down
11 changes: 9 additions & 2 deletions src/commands/package/PublishDeploymentPlanCommand.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const BarracksCommand = require('../BarracksCommand');
const Validator = require('../../utils/Validator');
const ReadFile = require('../../utils/FileReader');
const ObjectReader = require('../../utils/ObjectReader');

function getObject(program) {
if (program.file) {
return ObjectReader.readObjectFromFile(program.file);
} else {
return ObjectReader.readObjectFromStdin();
}
}
class PublishDeploymentPlanCommand extends BarracksCommand {

configureCommand(program) {
Expand All @@ -16,7 +23,7 @@ class PublishDeploymentPlanCommand extends BarracksCommand {
let token;
return this.getAuthenticationToken().then(authToken => {
token = authToken;
return ReadFile.getObject(program);
return getObject(program);
}).then(plan => {
if (plan.package) {
return this.barracks.publishDeploymentPlan(token, plan);
Expand Down
12 changes: 2 additions & 10 deletions src/utils/FileReader.js → src/utils/ObjectReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Validator = require('./Validator');
const inStream = require('in-stream');
const fs = require('fs');

class ReadFile {
class ObjectReader {

static getObjectFromString(data) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -51,14 +51,6 @@ class ReadFile {
});
});
}

static getObject(program) {
if (program.file) {
return this.readObjectFromFile(program.file);
} else {
return this.readObjectFromStdin();
}
}
}

module.exports = ReadFile;
module.exports = ObjectReader;
55 changes: 44 additions & 11 deletions tests/commands/integration/SetGoogleClientSecretCommand.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ const sinonChai = require('sinon-chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
const proxyquire = require('proxyquire').noCallThru();
const FileReader = require('../../../src/utils/FileReader');
const ObjectReader = require('../../../src/utils/ObjectReader');

chai.use(chaiAsPromised);
chai.use(sinonChai);

describe('SetBigQueryClientSecretCommand', () => {
describe('SetGoogleClientSecretCommand', () => {

let setGoogleClientSecretCommand;
let proxyFileExists;
let proxyGetObject;
let proxyReadObjectFromFile;
let proxyReadObjectFromStdin;
const token = '789ze5df1s354q984e';
const file = 'path/to/file.json';
const validProgram = { file };
Expand All @@ -25,16 +26,19 @@ describe('SetBigQueryClientSecretCommand', () => {
return proxyFileExists(path);
}
},
'../../utils/FileReader': {
getObject: (program) => {
return proxyGetObject(program);
'../../utils/ObjectReader': {
readObjectFromFile: (file) => {
return proxyReadObjectFromFile(file);
},
readObjectFromStdin: () => {
return proxyReadObjectFromStdin();
}
}
});
}

beforeEach(() => {
const Command = new getProxyCommand();
const Command = getProxyCommand();
setGoogleClientSecretCommand = new Command();
setGoogleClientSecretCommand.barracks = {};
setGoogleClientSecretCommand.userConfiguration = {};
Expand Down Expand Up @@ -99,13 +103,13 @@ describe('SetBigQueryClientSecretCommand', () => {
}
};

it ('should forward to client when token is accessed and object is provided as file or stream', done => {
it ('should forward to client when token is accessed and object is provided as file', done => {
// Given
const program = validProgram;
const response = 'Hello !';
const spyGetObject = sinon.spy();
proxyGetObject = (program) => {
spyGetObject(program);
const spyReadObjectFromFile = sinon.spy();
proxyReadObjectFromFile = (file) => {
spyReadObjectFromFile(file);
return validSecret;
};
setGoogleClientSecretCommand.getAuthenticationToken = sinon.stub().returns(Promise.resolve(token));
Expand All @@ -114,6 +118,35 @@ describe('SetBigQueryClientSecretCommand', () => {
// When / Then
setGoogleClientSecretCommand.execute(program).then(result => {
expect(result).to.be.equals(response);
expect(setGoogleClientSecretCommand.getAuthenticationToken).to.have.been.calledOnce;
expect(setGoogleClientSecretCommand.getAuthenticationToken).to.have.been.calledWithExactly();
expect(setGoogleClientSecretCommand.barracks.setGoogleClientSecret).to.have.been.calledOnce;
expect(setGoogleClientSecretCommand.barracks.setGoogleClientSecret).to.have.been.calledWithExactly(token, validSecret);
done();
}).catch(err => {
done(err);
});
});

it ('should forward to client when token is accessed and object is provided as stream', done => {
// Given
const program = {};
const response = 'Hello !';
const spyReadObjectFromStdin = sinon.spy();
proxyReadObjectFromStdin = () => {
spyReadObjectFromStdin();
return validSecret;
};
setGoogleClientSecretCommand.getAuthenticationToken = sinon.stub().returns(Promise.resolve(token));
setGoogleClientSecretCommand.barracks.setGoogleClientSecret = sinon.stub().returns(Promise.resolve(response));

// When / Then
setGoogleClientSecretCommand.execute(program).then(result => {
expect(result).to.be.equals(response);
expect(setGoogleClientSecretCommand.getAuthenticationToken).to.have.been.calledOnce;
expect(setGoogleClientSecretCommand.getAuthenticationToken).to.have.been.calledWithExactly();
expect(setGoogleClientSecretCommand.barracks.setGoogleClientSecret).to.have.been.calledOnce;
expect(setGoogleClientSecretCommand.barracks.setGoogleClientSecret).to.have.been.calledWithExactly(token, validSecret);
done();
}).catch(err => {
done(err);
Expand Down
62 changes: 48 additions & 14 deletions tests/commands/package/PublishDeploymentPlanCommand.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const mockStdin = require('mock-stdin');
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
const proxyquire = require('proxyquire').noCallThru();
const Stream = require('stream');

chai.use(chaiAsPromised);
chai.use(sinonChai);
Expand All @@ -14,7 +12,8 @@ describe('PublishDeploymentPlanCommand', () => {

let publishDeploymentPlanCommand;
let proxyFileExists;
let proxyGetObject;
let proxyReadObjectFromFile;
let proxyReadObjectFromStdin;
const token = '345678ujhbvcdsw34rg';
const file = 'path/to/file.json';
const validProgram = { file };
Expand All @@ -26,17 +25,19 @@ describe('PublishDeploymentPlanCommand', () => {
return proxyFileExists(path);
}
},
'../../utils/FileReader': {
getObject: (program) => {
return proxyGetObject(program);
'../../utils/ObjectReader': {
readObjectFromFile: (file) => {
return proxyReadObjectFromFile(file);
},
readObjectFromStdin: () => {
return proxyReadObjectFromStdin();
}
}
});
}

beforeEach(() => {

const Command = new getProxyCommand();
const Command = getProxyCommand();
publishDeploymentPlanCommand = new Command();
publishDeploymentPlanCommand.barracks = {};
publishDeploymentPlanCommand.userConfiguration = {};
Expand Down Expand Up @@ -107,13 +108,14 @@ describe('PublishDeploymentPlanCommand', () => {
}
};

it ('should forward to client when valid plan is given', done => {
it ('should forward to client when valid plan is given as file', done => {
// Given
const program = validProgram;
const spyGetObject = sinon.spy();
const spyReadObjectFromFile = sinon.spy();
const response = 'Yatta.';
proxyGetObject = (program) => {
spyGetObject(program);

proxyReadObjectFromFile = (file) => {
spyReadObjectFromFile(file);
return validPlan;
};

Expand All @@ -123,17 +125,48 @@ describe('PublishDeploymentPlanCommand', () => {
// When / Then
publishDeploymentPlanCommand.execute(program).then(result => {
expect(result).to.be.equals(response);
expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledOnce;
expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledWithExactly();
expect(publishDeploymentPlanCommand.barracks.publishDeploymentPlan).to.have.been.calledOnce;
expect(publishDeploymentPlanCommand.barracks.publishDeploymentPlan).to.have.been.calledWithExactly(token, validPlan);
done();
}).catch(err => {
done(err);
});
});

it ('should forward to client when valid plan is given as stream', done => {
// Given
const program = {};
const spyReadObjectFromStdin = sinon.spy();
const response = 'Yatta.';

proxyReadObjectFromStdin = () => {
spyReadObjectFromStdin();
return validPlan;
};

publishDeploymentPlanCommand.getAuthenticationToken = sinon.stub().returns(Promise.resolve(token));
publishDeploymentPlanCommand.barracks.publishDeploymentPlan = sinon.stub().returns(Promise.resolve(response));

// When / Then
publishDeploymentPlanCommand.execute(program).then(result => {
expect(result).to.be.equals(response);
expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledOnce;
expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledWithExactly();
expect(publishDeploymentPlanCommand.barracks.publishDeploymentPlan).to.have.been.calledOnce;
expect(publishDeploymentPlanCommand.barracks.publishDeploymentPlan).to.have.been.calledWithExactly(token, validPlan);
done();
}).catch(err => {
done(err);
});
});

it ('should return false when plan given is valid JSON but has no package field', done => {
// Given
const program = validProgram;
const spyGetObject = sinon.spy();
proxyGetObject = (program) => {
proxyReadObjectFromFile = (program) => {
spyGetObject(program);
return invalidPlan;
};
Expand All @@ -142,7 +175,8 @@ describe('PublishDeploymentPlanCommand', () => {

// When / Then
publishDeploymentPlanCommand.execute(program).then(result => {
expect(result).to.be.equals(false);
expect(result).to.be.equals(false);expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledOnce;
expect(publishDeploymentPlanCommand.getAuthenticationToken).to.have.been.calledWithExactly();
done();
}).catch(err => {
done(err);
Expand Down

0 comments on commit f187856

Please sign in to comment.