Skip to content

Commit

Permalink
Update device overall status
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
Andrea Rosci authored and Andrea Rosci committed May 14, 2024
1 parent e62c741 commit 7f6f7d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/types/device-overall-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export enum DeviceOverallStatus {
ORDERED = 'ordered',
PREPARING = 'preparing',
SHIPPED = 'shipped',
OPERATIONAL = 'operational',
DISCONNECTED = 'disconnected',
REDUCED_FUNCTIONALITY = 'reduced-functionality',
}
6 changes: 5 additions & 1 deletion tests/integration/models/device.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from './tags';
import type * as tagsHelper from './tags';
import type * as BalenaSdk from '../../..';
import { deviceStatusAdapter } from '../utils';

const makeRequest = async (url) => {
try {
Expand Down Expand Up @@ -2129,7 +2130,7 @@ describe('Device Model', function () {
const status = await balena.models.device.getStatus(
this.device[prop],
);
expect(status).to.equal('idle');
expect(deviceStatusAdapter(status)).to.equal('idle');
});
});
});
Expand Down Expand Up @@ -2168,6 +2169,9 @@ describe('Device Model', function () {
const device = await balena.models.device.get(this.device.uuid, {
$select: ['overall_status', 'overall_progress'],
});
device.overall_status = deviceStatusAdapter(
device.overall_status,
) as BalenaSdk.DeviceOverallStatus;
return expect(device).to.deep.match({
overall_status: 'idle',
overall_progress: null,
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DeviceOverallStatus } from '../..';
import type { Dictionary } from '../../typings/utils';
import { balena } from './setup';

Expand Down Expand Up @@ -44,3 +45,16 @@ export const getParam = <T>(

return resource[field];
};

export const deviceStatusAdapter = (status: DeviceOverallStatus | string) => {
switch (status) {
case 'operational':
return 'idle';
case 'reduced-functionality':
return 'idle';
case 'disconnected':
return 'offline';
default:
return status;
}
};

0 comments on commit 7f6f7d1

Please sign in to comment.