Fix locking stubs that were returning Bluebird rather than Promise

Change-type: patch
This commit is contained in:
Pagan Gazzard 2022-11-11 16:11:47 +00:00 committed by Page-
parent ae756cfabe
commit d587a323f2
2 changed files with 18 additions and 16 deletions

View File

@ -1,5 +1,4 @@
import * as _ from 'lodash';
import * as Bluebird from 'bluebird';
import { expect } from 'chai';
import {
stub,
@ -419,9 +418,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('should return 423 and reject the reboot if no locks are set', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});
@ -457,9 +456,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('should return 202 and reboot if force is set to true', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});
@ -584,9 +583,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('should return 423 and reject the reboot if locks are set', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});
@ -622,9 +621,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('should return 202 and shutdown if force is set to true', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});
@ -969,9 +968,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('prevents patch if update locks are present', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});
@ -998,9 +997,9 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
});
it('allows patch while update locks are present if force is in req.body', async () => {
stub(updateLock, 'lock').callsFake((__, opts, fn) => {
stub(updateLock, 'lock').callsFake(async (__, opts, fn) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');
});

View File

@ -1,7 +1,6 @@
import { expect } from 'chai';
import { stub, SinonStub, spy, SinonSpy } from 'sinon';
import * as supertest from 'supertest';
import * as Bluebird from 'bluebird';
import sampleResponses = require('~/test-data/device-api-responses.json');
import mockedAPI = require('~/test-lib/mocked-device-api');
@ -407,9 +406,13 @@ describe('SupervisorAPI [V2 Endpoints]', () => {
const mockContainers = [mockedAPI.mockService(service)];
const mockImages = [mockedAPI.mockImage(service)];
const lockFake = (_: any, opts: { force: boolean }, fn: () => any) => {
const lockFake = async (
_: any,
opts: { force: boolean },
fn: () => any,
) => {
if (opts.force) {
return Bluebird.resolve(fn());
return fn();
}
throw new UpdatesLockedError('Updates locked');