Skip to content

Commit

Permalink
Merge pull request #1372 from balena-io/v18-drop-device-type-json-sta…
Browse files Browse the repository at this point in the history
…te-name-normalizations

**BREAKING**: Remove the device-type.json state & name normalization
  • Loading branch information
thgreasi authored Aug 11, 2023
2 parents 8851a59 + 7d87bf4 commit 1af9820
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 55 deletions.
23 changes: 3 additions & 20 deletions src/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,11 @@ const getConfigModel = function (
const { apiUrl } = opts;

const normalizeDeviceTypes = (
deviceTypes: DeviceTypeJson.DeviceType[], // Patch device types to be marked as ALPHA and BETA instead
deviceTypes: DeviceTypeJson.DeviceType[],
): DeviceTypeJson.DeviceType[] =>
// of PREVIEW and EXPERIMENTAL, respectively.
// This logic is literally copy and pasted from balena UI, but
// there are plans to move this to `resin-device-types` so it
// should be a matter of time for this to be removed.
deviceTypes.map(function (deviceType) {
// TODO: Drop in the next major the `deviceType.name.replace`s
if (deviceType.state === 'DISCONTINUED') {
deviceType.name = deviceType.name.replace(
/(\(PREVIEW|EXPERIMENTAL\))/,
'(DISCONTINUED)',
);
}
if (deviceType.state === 'PREVIEW') {
deviceType.state = 'ALPHA';
deviceType.name = deviceType.name.replace('(PREVIEW)', '(ALPHA)');
}
if (deviceType.state === 'EXPERIMENTAL') {
deviceType.state = 'NEW';
deviceType.name = deviceType.name.replace('(EXPERIMENTAL)', '(NEW)');
}
// Remove the device-type.json instructions to enforce
// users to use the contract based ones.
delete deviceType.instructions;
return deviceType;
});
Expand Down
37 changes: 2 additions & 35 deletions tests/integration/models/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,14 @@ const expectDeviceTypeArray = function (
}
};

const REPLACED_STATES = ['PREVIEW', 'EXPERIMENTAL'];

const REPLACED_NAME_SUFFIXES = ['(PREVIEW)', '(EXPERIMENTAL)', '(BETA)'];

type ConfigContext = Mocha.Context & {
deviceTypes: BalenaSdk.DeviceTypeJson.DeviceType[];
};

const itNormalizesDeviceTypes = function () {
it('changes old device type states', function (this: Mocha.Context) {
for (const deviceType of (this as ConfigContext).deviceTypes) {
expect(deviceType.state).to.satisfy((dtState: string) =>
_.every(REPLACED_STATES, (replacedState) => dtState !== replacedState),
);
}
});

it('changes old device type name suffixes', function (this: Mocha.Context) {
for (const deviceType of (this as ConfigContext).deviceTypes) {
expect(deviceType.name).to.satisfy((dtName: string) =>
_.every(
REPLACED_NAME_SUFFIXES,
(replacedSuffix) => !_.endsWith(dtName, replacedSuffix),
),
);
}
});

it('properly replaces the names of device types with old states', function (this: Mocha.Context) {
it('should not have an `instructions` field', function (this: Mocha.Context) {
for (const deviceType of (this as ConfigContext).deviceTypes) {
if (deviceType.state === 'PREVIEW') {
expect(deviceType.name).to.satisfy((dtName: string) =>
_.endsWith(dtName, '(ALPHA)'),
);
}

if (deviceType.state === 'BETA') {
expect(deviceType.name).to.satisfy((dtName: string) =>
_.endsWith(dtName, '(NEW)'),
);
}
expect(deviceType).to.not.have.property('instructions');
}
});
};
Expand Down

0 comments on commit 1af9820

Please sign in to comment.