2019-11-07 10:02:44 +00:00
|
|
|
import { expect } from 'chai';
|
2019-12-05 08:57:47 +00:00
|
|
|
import { BalenaAPIMock } from '../../balena-api-mock';
|
2019-11-14 09:53:38 +00:00
|
|
|
import { cleanOutput, runCommand } from '../../helpers';
|
2019-11-07 10:02:44 +00:00
|
|
|
|
|
|
|
describe('balena devices supported', function() {
|
2019-12-05 08:57:47 +00:00
|
|
|
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 () => {
|
2019-12-04 18:04:57 +00:00
|
|
|
api.expectWhoAmI();
|
2019-12-05 08:57:47 +00:00
|
|
|
api.expectMixpanel();
|
|
|
|
|
|
|
|
const { out, err } = await runCommand('devices supported -h');
|
|
|
|
|
2019-12-26 22:59:44 +00:00
|
|
|
expect(cleanOutput(out)).to.contain('$ balena devices supported');
|
2019-12-05 08:57:47 +00:00
|
|
|
|
|
|
|
expect(err).to.eql([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should list currently supported devices, with correct filtering', async () => {
|
2019-12-04 18:04:57 +00:00
|
|
|
api.expectWhoAmI();
|
2019-12-05 08:57:47 +00:00
|
|
|
api.expectMixpanel();
|
|
|
|
|
2019-12-11 12:18:58 +00:00
|
|
|
// TODO: Using the alias api.expect here causes route /config/vars to be called unexpectedly - why?
|
2019-12-05 08:57:47 +00:00
|
|
|
api.scope
|
|
|
|
.get('/device-types/v1')
|
2019-12-11 12:18:58 +00:00
|
|
|
.replyWithFile(200, __dirname + '/device-types.api-response.json', {
|
2019-12-05 08:57:47 +00:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
});
|
|
|
|
|
2019-11-07 10:02:44 +00:00
|
|
|
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);
|
|
|
|
|
2019-12-05 08:57:47 +00:00
|
|
|
// Discontinued devices should be filtered out from results
|
|
|
|
expect(lines.some(l => l.includes('DISCONTINUED'))).to.be.false;
|
2019-11-07 10:02:44 +00:00
|
|
|
|
2019-12-05 08:57:47 +00:00
|
|
|
// 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;
|
2019-11-07 10:02:44 +00:00
|
|
|
|
2019-12-05 08:57:47 +00:00
|
|
|
expect(err).to.eql([]);
|
2019-11-07 10:02:44 +00:00
|
|
|
});
|
|
|
|
});
|