diff --git a/clients/Barracks.js b/clients/Barracks.js index eafb2ca..bf9d1fb 100644 --- a/clients/Barracks.js +++ b/clients/Barracks.js @@ -134,7 +134,7 @@ class Barracks { getSegmentByName(token, segmentName) { return new Promise((resolve, reject) => { this.getSegments(token).then(segments => { - const segment = segments.active.find(segment => { + const segment = segments.active.concat(segments.other).find(segment => { return segment.name === segmentName; }); if (segment) { diff --git a/clients/Barracks.spec.js b/clients/Barracks.spec.js index 7739966..c82eb69 100644 --- a/clients/Barracks.spec.js +++ b/clients/Barracks.spec.js @@ -340,7 +340,25 @@ describe('Barracks', () => { // Given const segmentName = 'segment prod'; const segment = { id: 'lkjhgfdsa', name: segmentName }; - const response = { active: [ segment, { id: 'zxcvbnm', name: 'other segment' } ] }; + const response = { active: [ segment, { id: 'zxcvbnm', name: 'other segment' } ], other: { id: 'other', name: 'Other' } }; + barracks.getSegments = sinon.stub().returns(Promise.resolve(response)); + + // When / Then + barracks.getSegmentByName(token, segmentName).then(result => { + expect(result).to.be.equals(segment); + expect(barracks.getSegments).to.have.been.calledOnce; + expect(barracks.getSegments).to.have.been.calledWithExactly(token); + done(); + }).catch(err => { + done(err); + }); + }); + + it('should return other segment when name is other when request succeed', done => { + // Given + const segmentName = 'Other'; + const segment = { id: 'other', name: segmentName }; + const response = { active: [ { id: 'zxcvbnm', name: 'other segment' } ], other: segment }; barracks.getSegments = sinon.stub().returns(Promise.resolve(response)); // When / Then diff --git a/commands/DeviceCommand.js b/commands/DeviceCommand.js index 8e2745a..f600552 100644 --- a/commands/DeviceCommand.js +++ b/commands/DeviceCommand.js @@ -5,7 +5,7 @@ class DeviceCommand extends BarracksCommand { configureCommand(program) { return program .arguments('') - .option('--fromDate [\'YYYY-MM-DD\' | \'YYYY-MM-DDTHH:mm:ss.sssZ\']', '(Optionnal) The date (ISO-8601) from when to begin the history.'); + .option('--fromDate [\'YYYY-MM-DD\' | \'YYYY-MM-DD HH:mm\' | \'YYYY-MM-DDTHH:mm:ss.sssZ\']', '(Optionnal) The date from when to begin the history'); } validateCommand(program) {