Skip to content

Commit

Permalink
Use enums for node statuses.
Browse files Browse the repository at this point in the history
  • Loading branch information
huwshimi committed Nov 17, 2020
1 parent 7ce6efd commit 9cee184
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions ui/.betterer.results
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ exports[`stricter compilation`] = {
[9, 59, 12, "Type \'SliceCaseReducers<UserState>\' does not satisfy the constraint \'SliceCaseReducers<GenericState<User, any>>\'.\\n Index signatures are incompatible.\\n Type \'CaseReducer<UserState, { payload: any; type: string; }> | CaseReducerWithPrepare<UserState, PayloadAction<any, string, any, any>>\' is not assignable to type \'CaseReducer<GenericState<User, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<User, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<UserState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<User, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<User, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<UserState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<User, any>, { payload: any; type: string; }>\'.\\n Types of parameters \'state\' and \'state\' are incompatible.\\n Property \'auth\' is missing in type \'{ errors: any; items: { id: number; completed_intro: boolean; email: string; global_permissions: string[]; is_local: boolean; is_superuser: boolean; last_name: string; last_login: string; machines_count: number; sshkeys_count: number; username: string; }[]; loaded: boolean; loading: boolean; saved: boolean; saving: ...\' but required in type \'{ auth: { errors: any; loaded: boolean; loading: boolean; saved: boolean; saving: boolean; user: { id: number; completed_intro: boolean; email: string; global_permissions: string[]; is_local: boolean; ... 5 more ...; username: string; }; }; ... 5 more ...; saving: boolean; }\'.", "1934442805"]
],
"src/app/store/utils/slice.test.ts:1988551168": [
[250, 10, 6, "Type \'(state: TokenState, _action: PayloadAction<undefined>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 12 more ... | Zone, unknown>, { ...; }> | CaseReducerWithPrepare<...>\'.\\n Type \'(state: TokenState, _action: PayloadAction<undefined>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 12 more ... | Zone, unknown>, { ...; }>\'.\\n Types of parameters \'state\' and \'state\' are incompatible.\\n Type \'{ errors: unknown; items: ({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | ... 19 more ... | { ...; })[]; loaded: boolean; loading: boolean; saved: boolean; saving: boolean; }\' is not assignable to type \'TokenState\'.\\n Types of property \'items\' are incompatible.\\n Type \'({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | { id: number; ... 27 more ...; zone: number; } | ... 18 more ... | { ...; })[]\' is not assignable to type \'Token[]\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | { id: number; ... 27 more ...; zone: number; } | ... 18 more ... | { ...; }\' is not assignable to type \'Token\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; }\' is not assignable to type \'Token\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; }\' is missing the following properties from type \'{ consumer: TokenConsumer; key: string; secret: string; }\': consumer, key, secret", "1551012726"],
[250, 10, 6, "Type \'(state: TokenState, _action: PayloadAction<undefined>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 13 more ... | Zone, unknown>, { ...; }> | CaseReducerWithPrepare<...>\'.\\n Type \'(state: TokenState, _action: PayloadAction<undefined>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 13 more ... | Zone, unknown>, { ...; }>\'.\\n Types of parameters \'state\' and \'state\' are incompatible.\\n Type \'{ errors: unknown; items: ({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | ... 20 more ... | { ...; })[]; loaded: boolean; loading: boolean; saved: boolean; saving: boolean; }\' is not assignable to type \'TokenState\'.\\n Types of property \'items\' are incompatible.\\n Type \'({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | { id: number; ... 27 more ...; zone: number; } | ... 19 more ... | { ...; })[]\' is not assignable to type \'Token[]\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | { id: number; ... 27 more ...; zone: number; } | ... 19 more ... | { ...; }\' is not assignable to type \'Token\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; }\' is not assignable to type \'Token\'.\\n Type \'{ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; }\' is missing the following properties from type \'{ consumer: TokenConsumer; key: string; secret: string; }\': consumer, key, secret", "1551012726"],
[256, 53, 8, "Expected 1 arguments, but got 0.", "1130710519"],
[270, 10, 10, "Type \'(state: TokenState, action: PayloadAction<string>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 12 more ... | Zone, unknown>, { ...; }> | CaseReducerWithPrepare<...>\'.\\n Type \'(state: TokenState, action: PayloadAction<string>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 12 more ... | Zone, unknown>, { ...; }>\'.\\n Types of parameters \'state\' and \'state\' are incompatible.\\n Type \'{ errors: unknown; items: ({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | ... 19 more ... | { ...; })[]; loaded: boolean; loading: boolean; saved: boolean; saving: boolean; }\' is not assignable to type \'TokenState\'.", "3510326721"],
[270, 10, 10, "Type \'(state: TokenState, action: PayloadAction<string>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 13 more ... | Zone, unknown>, { ...; }> | CaseReducerWithPrepare<...>\'.\\n Type \'(state: TokenState, action: PayloadAction<string>) => void\' is not assignable to type \'CaseReducer<GenericState<Controller | Device | BaseMachine | Subnet | User | Notification | DHCPSnippet | Domain | ... 13 more ... | Zone, unknown>, { ...; }>\'.\\n Types of parameters \'state\' and \'state\' are incompatible.\\n Type \'{ errors: unknown; items: ({ id: number; created: string; description: string; is_default: boolean; machine_ready_count: number; machine_total_count: number; name: string; permissions: string[]; updated: string; } | ... 20 more ... | { ...; })[]; loaded: boolean; loading: boolean; saved: boolean; saving: boolean; }\' is not assignable to type \'TokenState\'.", "3510326721"],
[394, 10, 7, "Type \'CaseReducer<PodState, { payload: any; type: string; }> | CaseReducerWithPrepare<PodState, PayloadAction<any, string, any, any>>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }>\'.", "1380666520"],
[395, 10, 12, "Type \'CaseReducer<PodState, { payload: any; type: string; }> | CaseReducerWithPrepare<PodState, PayloadAction<any, string, any, any>>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }>\'.", "662888088"],
[396, 10, 14, "Type \'CaseReducer<PodState, { payload: any; type: string; }> | CaseReducerWithPrepare<PodState, PayloadAction<any, string, any, any>>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }> | CaseReducerWithPrepare<GenericState<Pod, any>, PayloadAction<any, string, any, any>>\'.\\n Type \'CaseReducer<PodState, { payload: any; type: string; }>\' is not assignable to type \'CaseReducer<GenericState<Pod, any>, { payload: any; type: string; }>\'.", "368191931"],
Expand Down Expand Up @@ -661,5 +661,5 @@ exports[`no TSFixMe types`] = {
};

exports[`migrate js files to ts`] = {
value: `431`
value: `426`
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StatusColumn } from "./StatusColumn";
import type { Machine } from "app/store/machine/types";
import type { RootState } from "app/store/root/types";
import type { TestResult } from "app/store/types/node";
import { NodeStatus } from "app/store/types/node";
import {
machine as machineFactory,
machineState as machineStateFactory,
Expand All @@ -29,7 +30,7 @@ describe("StatusColumn", () => {
actions: [],
distro_series: "bionic",
osystem: "ubuntu",
status: "New",
status: NodeStatus.NEW,
status_code: 0,
status_message: "",
system_id: "abc123",
Expand Down Expand Up @@ -78,7 +79,7 @@ describe("StatusColumn", () => {

describe("status text", () => {
it("displays the machine's status if not deploying or deployed", () => {
machine.status = "New";
machine.status = NodeStatus.NEW;
machine.status_code = nodeStatus.NEW;
const store = mockStore(state);
const wrapper = mount(
Expand All @@ -95,7 +96,7 @@ describe("StatusColumn", () => {
});

it("displays the short-form of Ubuntu release if deployed", () => {
machine.status = "Deployed";
machine.status = NodeStatus.DEPLOYED;
machine.status_code = nodeStatus.DEPLOYED;
machine.osystem = "ubuntu";
machine.distro_series = "bionic";
Expand All @@ -116,7 +117,7 @@ describe("StatusColumn", () => {
});

it("displays the full OS and release if non-Ubuntu deployed", () => {
machine.status = "Deployed";
machine.status = NodeStatus.DEPLOYED;
machine.status_code = nodeStatus.DEPLOYED;
machine.osystem = "centos";
machine.distro_series = "centos70";
Expand All @@ -135,7 +136,7 @@ describe("StatusColumn", () => {
});

it("displays 'Deploying OS release' if machine is deploying", () => {
machine.status = "Deploying";
machine.status = NodeStatus.DEPLOYING;
machine.status_code = nodeStatus.DEPLOYING;
machine.osystem = "ubuntu";
machine.distro_series = "bionic";
Expand All @@ -157,7 +158,7 @@ describe("StatusColumn", () => {

it("displays an error message for broken machines", () => {
machine.error_description = "machine is on fire";
machine.status = "Broken";
machine.status = NodeStatus.BROKEN;
machine.status_code = nodeStatus.BROKEN;
const store = mockStore(state);

Expand All @@ -179,7 +180,7 @@ describe("StatusColumn", () => {

describe("progress text", () => {
it("displays the machine's status_message if in a transient state", () => {
machine.status = "Testing";
machine.status = NodeStatus.TESTING;
machine.status_code = nodeStatus.TESTING;
machine.status_message = "2 of 6 tests complete";
const store = mockStore(state);
Expand All @@ -200,7 +201,7 @@ describe("StatusColumn", () => {

it(`does not display the machine's status_message if
not in a transient state`, () => {
machine.status = "Allocated";
machine.status = NodeStatus.ALLOCATED;
machine.status_code = nodeStatus.ALLOCATED;
machine.status_message = "This machine is allocated";
const store = mockStore(state);
Expand All @@ -220,7 +221,7 @@ describe("StatusColumn", () => {

describe("status icon", () => {
it("shows a spinner if machine is in a transient state", () => {
machine.status = "Commissioning";
machine.status = NodeStatus.COMMISSIONING;
machine.status_code = nodeStatus.COMMISSIONING;
const store = mockStore(state);
const wrapper = mount(
Expand All @@ -238,7 +239,7 @@ describe("StatusColumn", () => {

it(`shows a warning and tooltip if machine has failed tests and is not in a
state where the warning should be hidden`, () => {
machine.status = "Allocated";
machine.status = NodeStatus.ALLOCATED;
machine.status_code = nodeStatus.ALLOCATED;
machine.testing_status.status = scriptStatus.FAILED as TestResult;
const store = mockStore(state);
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/utils/getStatusText.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { nodeStatus } from "app/base/enum";
import { machine as machineFactory } from "testing/factories";
import { getStatusText } from "./getStatusText";
import { NodeStatus } from "app/store/types/node";

describe("getStatusText", () => {
it("displays the machine's status if not deploying or deployed", () => {
const machine = machineFactory({
status: "New",
status: NodeStatus.NEW,
status_code: nodeStatus.NEW,
});
expect(getStatusText(machine, "Ubuntu 18.04 LTS")).toEqual("New");
Expand Down

0 comments on commit 9cee184

Please sign in to comment.