Update app/create and device/supported tests to use new api-mock.

Change-type: patch
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe 2019-12-05 09:57:47 +01:00
parent 33210b896b
commit bb19903826
3 changed files with 6901 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as _ from 'lodash';
import { BalenaAPIMock } from '../../balena-api-mock';
import { cleanOutput, runCommand } from '../../helpers';
const HELP_MESSAGE = `
@ -25,11 +25,25 @@ Options:
`;
describe('balena app create', function() {
let api: BalenaAPIMock;
beforeEach(() => {
api = new BalenaAPIMock();
});
afterEach(() => {
// Check all expected api calls have been made and clean up.
api.done();
});
it('should print help text with the -h flag', async () => {
api.expectOptionalWhoAmI();
api.expectMixpanel();
const { out, err } = await runCommand('app create -h');
expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP_MESSAGE]));
expect(err).to.have.lengthOf(0);
expect(err).to.eql([]);
});
});

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
import { expect } from 'chai';
import * as _ from 'lodash';
import { BalenaAPIMock } from '../../balena-api-mock';
import { cleanOutput, runCommand } from '../../helpers';
const HELP = `
const HELP_RESPONSE = `
Usage: devices supported
Use this command to get the list of all supported devices.
@ -13,23 +13,52 @@ Examples:
`;
describe('balena devices supported', function() {
it('should list currently supported devices', async () => {
let api: BalenaAPIMock;
beforeEach(() => {
api = new BalenaAPIMock();
});
afterEach(() => {
// Check all expected api calls have been made and clean up.
api.done();
});
it('should print help text with the -h flag', async () => {
api.expectOptionalWhoAmI();
api.expectMixpanel();
const { out, err } = await runCommand('devices supported -h');
expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP_RESPONSE]));
expect(err).to.eql([]);
});
it('should list currently supported devices, with correct filtering', async () => {
api.expectOptionalWhoAmI();
api.expectMixpanel();
api.scope
.get('/device-types/v1')
.replyWithFile(200, __dirname + '/supported.api-response.json', {
'Content-Type': 'application/json',
});
const { out, err } = await runCommand('devices supported');
const lines = cleanOutput(out);
expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG NAME');
expect(lines).to.have.lengthOf.at.least(2);
// Discontinued devices should be filtered out from results
expect(lines.some(l => l.includes('DISCONTINUED'))).to.be.false;
expect(err).to.have.lengthOf(0);
});
// Experimental devices should be listed as beta
expect(lines.some(l => l.includes('EXPERIMENTAL'))).to.be.false;
expect(lines.some(l => l.includes('BETA'))).to.be.true;
it('should print help text with the -h flag', async () => {
const { out, err } = await runCommand('devices supported -h');
expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP]));
expect(err).to.have.lengthOf(0);
expect(err).to.eql([]);
});
});