Skip to content

Commit

Permalink
Merge pull request #1368 from balena-io/test-file-ts-adjustments
Browse files Browse the repository at this point in the history
Refactored @ts-ignore to @ts-expect-error in test file
  • Loading branch information
bulldozer-balena[bot] authored Jun 8, 2020
2 parents 12a4a11 + ffe814e commit 89055a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 14 additions & 20 deletions test/11-api-binder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
await prepare();
config.removeAllListeners();

// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = new ConfigJsonConfigBackend(schema, filename);
config.generateRequiredFields();
(config.configJsonBackend as any).cache = await (config.configJsonBackend as any).read();
// @ts-expect-error using private properties
config.configJsonBackend.cache = await config.configJsonBackend.read();
await config.generateRequiredFields();

obj.logger = {
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('ApiBinder', () => {
});

after(() => {
// @ts-ignore
// @ts-expect-error setting read-only property
balenaAPI.balenaBackend!.registerHandler.restore();
try {
server.close();
Expand All @@ -88,19 +89,18 @@ describe('ApiBinder', () => {
});

after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});

it('provisions a device', () => {
// @ts-ignore
const promise = components.apiBinder.provisionDevice();

return expect(promise).to.be.fulfilled.then(() => {
expect(balenaAPI.balenaBackend!.registerHandler).to.be.calledOnce;

// @ts-ignore
// @ts-expect-error function does not exist on type
balenaAPI.balenaBackend!.registerHandler.resetHistory();
expect(eventTracker.track).to.be.calledWith('Device bootstrap success');
});
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder.json');
});
after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder.json');
});
after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
Expand All @@ -211,7 +211,6 @@ describe('ApiBinder', () => {
const fetchDeviceStub = stub(components.apiBinder, 'fetchDevice');
fetchDeviceStub.onCall(0).resolves({ id: 1 });

// @ts-ignore
const device = await components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts,
);
Expand All @@ -220,17 +219,15 @@ describe('ApiBinder', () => {
expect(device).to.deep.equal({ id: 1 });
expect(components.apiBinder.fetchDevice).to.be.calledOnce;

// @ts-ignore
components.apiBinder.fetchDevice.restore();
// @ts-ignore
// @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore();
});

it('throws if it cannot get the device with any of the keys', () => {
spy(balenaAPI.balenaBackend!, 'deviceKeyHandler');
stub(components.apiBinder, 'fetchDevice').returns(Promise.resolve(null));

// @ts-ignore
const promise = components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts,
);
Expand All @@ -241,9 +238,8 @@ describe('ApiBinder', () => {
return expect(promise).to.be.rejected.then(() => {
expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.not.be.called;
expect(components.apiBinder.fetchDevice).to.be.calledTwice;
// @ts-ignore
components.apiBinder.fetchDevice.restore();
// @ts-ignore
// @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore();
});
});
Expand All @@ -254,16 +250,14 @@ describe('ApiBinder', () => {
fetchDeviceStub.onCall(0).returns(Promise.resolve(null));
fetchDeviceStub.onCall(1).returns(Promise.resolve({ id: 1 }));

// @ts-ignore
const device = await components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts as any,
);
expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.be.calledOnce;
expect(device).to.deep.equal({ id: 1 });
expect(components.apiBinder.fetchDevice).to.be.calledTwice;
// @ts-ignore
components.apiBinder.fetchDevice.restore();
// @ts-ignore
// @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore();
});
});
Expand All @@ -274,7 +268,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder-offline.json');
});
after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
Expand Down Expand Up @@ -313,7 +307,7 @@ describe('ApiBinder', () => {
});

after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
Expand Down Expand Up @@ -362,7 +356,7 @@ describe('ApiBinder', () => {
});

after(async () => {
// @ts-ignore
// @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields();
});
Expand Down
2 changes: 1 addition & 1 deletion test/12-logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Logger', function () {
this._req.end = sinon.spy();

this._req.body = '';
this._req.pipe(zlib.createGunzip()).on('data', (chunk: any) => {
this._req.pipe(zlib.createGunzip()).on('data', (chunk: Buffer) => {
this._req.body += chunk;
});

Expand Down

0 comments on commit 89055a8

Please sign in to comment.