Skip to content

Commit

Permalink
PR feedback:
Browse files Browse the repository at this point in the history
+ tune test naming in base command class tests
+ tune fn naming in subscribe command e2e tests
+ filter received events by name before assertions in subscribe command e2e tests
  • Loading branch information
busticated committed Apr 18, 2020
1 parent 3d6fa21 commit 5a9d43f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/cmd/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CLI Command Base Class', () => {
expect(cmd.isDeviceId('0123456789ABCDEF01234567')).to.equal(true);
});

it('Show a usage error', async () => {
it('Shows a usage error', async () => {
const promise = cmd.showUsageError('test');

expect(promise).to.be.an.instanceof(Promise);
Expand All @@ -48,7 +48,7 @@ describe('CLI Command Base Class', () => {
expect(error).to.have.property('message', 'test');
});

it('Show a product device name usage error', async () => {
it('Shows a product device name usage error', async () => {
const promise = cmd.showProductDeviceNameUsageError('my-device-name');

expect(promise).to.be.an.instanceof(Promise);
Expand Down
25 changes: 14 additions & 11 deletions test/e2e/subscribe.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Subscribe Commands [@device]', () => {
await cli.callStrobyStart(DEVICE_NAME);

const args = ['subscribe'];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal('Subscribing to all events from my devices');
expect(events).to.have.lengthOf.above(2);
Expand All @@ -86,7 +86,7 @@ describe('Subscribe Commands [@device]', () => {

const eventName = 'led';
const args = ['subscribe', eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to "${eventName}" from my devices`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -104,7 +104,8 @@ describe('Subscribe Commands [@device]', () => {
const eventName = DEVICE_ID.substring(0, 6);
const eventData = 'active';
const args = ['subscribe', '--all', eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { received: [msg, ...data], isCanceled } = await runAndCollectEventOutput(args);
const events = getPublishedEventsByName(data, eventName);

expect(msg).to.equal(`Subscribing to "${eventName}" from the firehose (all devices) and my personal stream (my devices)`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -120,7 +121,7 @@ describe('Subscribe Commands [@device]', () => {
await cli.callStrobyStart(DEVICE_NAME);
const eventName = 't';
const args = ['subscribe', '--all', eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to "${eventName}" from the firehose (all devices) and my personal stream (my devices)`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -144,7 +145,7 @@ describe('Subscribe Commands [@device]', () => {
await cli.callStrobyStart(DEVICE_NAME);

const args = ['subscribe', '--device', DEVICE_ID];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to all events from device ${DEVICE_ID}'s stream`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -162,7 +163,7 @@ describe('Subscribe Commands [@device]', () => {

const eventName = 'led';
const args = ['subscribe', '--device', DEVICE_ID, eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to "${eventName}" from device ${DEVICE_ID}'s stream`);
expect(events).to.have.lengthOf.above(2);
Expand Down Expand Up @@ -226,7 +227,7 @@ describe('Subscribe Commands [@device]', () => {

const eventName = 'led';
const args = ['subscribe', '--product', PRODUCT_01_ID];
const { received: [msg, ...data], isCanceled } = await collectEventOutput(args);
const { received: [msg, ...data], isCanceled } = await runAndCollectEventOutput(args);
const events = getPublishedEventsByName(data, eventName);

expect(msg).to.equal(`Subscribing to all events from product ${PRODUCT_01_ID}'s stream`);
Expand All @@ -248,7 +249,7 @@ describe('Subscribe Commands [@device]', () => {

const eventName = 'led';
const args = ['subscribe', '--product', PRODUCT_01_ID, eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to "${eventName}" from product ${PRODUCT_01_ID}'s stream`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -267,8 +268,10 @@ describe('Subscribe Commands [@device]', () => {
it('Subscribes to a product device\'s events', async () => {
await cli.callStrobyStart(PRODUCT_01_DEVICE_02_ID, PRODUCT_01_ID);

const eventName = 'led';
const args = ['subscribe', '--product', PRODUCT_01_ID, '--device', PRODUCT_01_DEVICE_02_ID];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { received: [msg, ...data], isCanceled } = await runAndCollectEventOutput(args);
const events = getPublishedEventsByName(data, eventName);

expect(msg).to.equal(`Subscribing to all events from product ${PRODUCT_01_ID} device ${PRODUCT_01_DEVICE_02_ID}'s stream`);
expect(events).to.have.lengthOf.above(2);
Expand All @@ -289,7 +292,7 @@ describe('Subscribe Commands [@device]', () => {

const eventName = 'led';
const args = ['subscribe', '--product', PRODUCT_01_ID, '--device', PRODUCT_01_DEVICE_02_ID, eventName];
const { events, received: [msg], isCanceled } = await collectEventOutput(args);
const { events, received: [msg], isCanceled } = await runAndCollectEventOutput(args);

expect(msg).to.equal(`Subscribing to "${eventName}" from product ${PRODUCT_01_ID} device ${PRODUCT_01_DEVICE_02_ID}'s stream`);
expect(events).to.have.lengthOf.above(2);
Expand Down Expand Up @@ -333,7 +336,7 @@ describe('Subscribe Commands [@device]', () => {
}

// TODO (mirande): capture stdout and stderr independently
async function collectEventOutput(...args){
async function runAndCollectEventOutput(...args){
const subprocess = cli.run(...args);
const received = [];

Expand Down

0 comments on commit 5a9d43f

Please sign in to comment.