Merge pull request #1365 from balena-io/normalize-test-files

Convert all test files to TS and add .spec to all filenames
This commit is contained in:
bulldozer-balena[bot] 2020-06-05 23:16:43 +00:00 committed by GitHub
commit 400d2f5fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 48 additions and 47 deletions

View File

@ -13,6 +13,7 @@ import balenaAPI = require('./lib/mocked-balena-api');
import { schema } from '../src/config/schema';
import ConfigJsonConfigBackend from '../src/config/configJson';
import * as TargetState from '../src/device-state/target-state';
import { DeviceStatus } from '../src/types/state';
const { expect } = chai;
@ -24,8 +25,7 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
// @ts-ignore
config.configJsonBackend = new ConfigJsonConfigBackend(schema, filename);
config.generateRequiredFields();
// @ts-expect-error using private properties
config.configJsonBackend.cache = await config.configJsonBackend.read();
(config.configJsonBackend as any).cache = await (config.configJsonBackend as any).read();
await config.generateRequiredFields();
obj.eventTracker = {
@ -307,6 +307,51 @@ describe('ApiBinder', () => {
});
});
describe('local mode', () => {
const components: Dictionary<any> = {};
before(() => {
return initModels(components, '/config-apibinder.json');
});
after(async () => {
// @ts-ignore
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
const sampleState = {
local: {
ip_address: '192.168.1.42 192.168.1.99',
api_port: 48484,
api_secret:
'20ffbd6e15aba827dca6381912d6aeb6c3a7a7c7206d4dfadf0d2f0a9e1136',
os_version: 'balenaOS 2.32.0+rev4',
os_variant: 'dev',
supervisor_version: '9.16.3',
provisioning_progress: null,
provisioning_state: '',
status: 'Idle',
logs_channel: null,
apps: {},
is_on__commit: 'whatever',
},
dependent: { apps: {} },
} as DeviceStatus;
it('should strip applications data', () => {
const result = components.apiBinder.stripDeviceStateInLocalMode(
sampleState,
) as Dictionary<any>;
expect(result).to.not.have.property('dependent');
const local = result['local'];
expect(local).to.not.have.property('apps');
expect(local).to.not.have.property('is_on__commit');
expect(local).to.not.have.property('logs_channel');
});
});
describe('healthchecks', () => {
const components: Dictionary<any> = {};
let configStub: SinonStub;

View File

@ -14,7 +14,7 @@ describe('Logger', function () {
this._req.end = sinon.spy();
this._req.body = '';
this._req.pipe(zlib.createGunzip()).on('data', (chunk) => {
this._req.pipe(zlib.createGunzip()).on('data', (chunk: any) => {
this._req.body += chunk;
});

View File

@ -1,44 +0,0 @@
import { expect } from 'chai';
import { APIBinder, APIBinderConstructOpts } from '../src/api-binder';
import { DeviceStatus } from '../src/types/state';
describe('APIBinder', () => {
let apiBinder: APIBinder;
before(() => {
apiBinder = new APIBinder({} as APIBinderConstructOpts);
});
describe('stripDeviceStateInLocalMode', () => {
const sampleState = {
local: {
ip_address: '192.168.1.42 192.168.1.99',
api_port: 48484,
api_secret:
'20ffbd6e15aba827dca6381912d6aeb6c3a7a7c7206d4dfadf0d2f0a9e1136',
os_version: 'balenaOS 2.32.0+rev4',
os_variant: 'dev',
supervisor_version: '9.16.3',
provisioning_progress: null,
provisioning_state: '',
status: 'Idle',
logs_channel: null,
apps: {},
is_on__commit: 'whatever',
},
dependent: { apps: {} },
} as DeviceStatus;
it('should strip applications data', () => {
const result = apiBinder.stripDeviceStateInLocalMode(
sampleState,
) as Dictionary<any>;
expect(result).to.not.have.property('dependent');
const local = result['local'];
expect(local).to.not.have.property('apps');
expect(local).to.not.have.property('is_on__commit');
expect(local).to.not.have.property('logs_channel');
});
});
});