Skip to content

Commit

Permalink
**BREAKING**: Remove the device-type.json state & name normalization
Browse files Browse the repository at this point in the history
We should not have any code any more
relying on these.

Change-type: major
  • Loading branch information
thgreasi authored and otaviojacobi committed Aug 17, 2023
1 parent b82bfb5 commit 447aa40
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 56 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
5 changes: 4 additions & 1 deletion tests/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ export function givenLoggedInUserWithApiKey(beforeFn: Mocha.HookFunction) {
afterFn(() => resetUser());
}

export function givenLoggedInUser(beforeFn: Mocha.HookFunction, forceRelogin = false) {
export function givenLoggedInUser(
beforeFn: Mocha.HookFunction,
forceRelogin = false,
) {
beforeFn(async () => {
await balena.auth.login({
email: credentials.email,
Expand Down

0 comments on commit 447aa40

Please sign in to comment.