refactor: improve code formatting and readability in tests and components
This commit is contained in:
@@ -138,11 +138,7 @@ async def update_gateway(
|
|||||||
organization_id=ctx.organization.id,
|
organization_id=ctx.organization.id,
|
||||||
)
|
)
|
||||||
updates = payload.model_dump(exclude_unset=True)
|
updates = payload.model_dump(exclude_unset=True)
|
||||||
if (
|
if "url" in updates or "token" in updates or "disable_device_pairing" in updates:
|
||||||
"url" in updates
|
|
||||||
or "token" in updates
|
|
||||||
or "disable_device_pairing" in updates
|
|
||||||
):
|
|
||||||
raw_next_url = updates.get("url", gateway.url)
|
raw_next_url = updates.get("url", gateway.url)
|
||||||
next_url = raw_next_url.strip() if isinstance(raw_next_url, str) else ""
|
next_url = raw_next_url.strip() if isinstance(raw_next_url, str) else ""
|
||||||
next_token = updates.get("token", gateway.token)
|
next_token = updates.get("token", gateway.token)
|
||||||
|
|||||||
@@ -80,10 +80,14 @@ def _generate_identity() -> DeviceIdentity:
|
|||||||
format=serialization.PrivateFormat.PKCS8,
|
format=serialization.PrivateFormat.PKCS8,
|
||||||
encryption_algorithm=serialization.NoEncryption(),
|
encryption_algorithm=serialization.NoEncryption(),
|
||||||
).decode("utf-8")
|
).decode("utf-8")
|
||||||
public_key_pem = private_key.public_key().public_bytes(
|
public_key_pem = (
|
||||||
encoding=serialization.Encoding.PEM,
|
private_key.public_key()
|
||||||
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
.public_bytes(
|
||||||
).decode("utf-8")
|
encoding=serialization.Encoding.PEM,
|
||||||
|
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
||||||
|
)
|
||||||
|
.decode("utf-8")
|
||||||
|
)
|
||||||
device_id = _derive_device_id(public_key_pem)
|
device_id = _derive_device_id(public_key_pem)
|
||||||
return DeviceIdentity(
|
return DeviceIdentity(
|
||||||
device_id=device_id,
|
device_id=device_id,
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
import {
|
||||||
|
act,
|
||||||
|
fireEvent,
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
waitFor,
|
||||||
|
} from "@testing-library/react";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
@@ -21,9 +27,7 @@ vi.mock("@/components/ui/dialog", () => ({
|
|||||||
DialogFooter: ({ children }: { children?: ReactNode }) => (
|
DialogFooter: ({ children }: { children?: ReactNode }) => (
|
||||||
<div>{children}</div>
|
<div>{children}</div>
|
||||||
),
|
),
|
||||||
DialogTitle: ({ children }: { children?: ReactNode }) => (
|
DialogTitle: ({ children }: { children?: ReactNode }) => <h2>{children}</h2>,
|
||||||
<h2>{children}</h2>
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@/api/generated/board-onboarding/board-onboarding", () => ({
|
vi.mock("@/api/generated/board-onboarding/board-onboarding", () => ({
|
||||||
@@ -31,10 +35,12 @@ vi.mock("@/api/generated/board-onboarding/board-onboarding", () => ({
|
|||||||
startOnboardingMock(...args),
|
startOnboardingMock(...args),
|
||||||
getOnboardingApiV1BoardsBoardIdOnboardingGet: (...args: unknown[]) =>
|
getOnboardingApiV1BoardsBoardIdOnboardingGet: (...args: unknown[]) =>
|
||||||
getOnboardingMock(...args),
|
getOnboardingMock(...args),
|
||||||
answerOnboardingApiV1BoardsBoardIdOnboardingAnswerPost: (...args: unknown[]) =>
|
answerOnboardingApiV1BoardsBoardIdOnboardingAnswerPost: (
|
||||||
answerOnboardingMock(...args),
|
...args: unknown[]
|
||||||
confirmOnboardingApiV1BoardsBoardIdOnboardingConfirmPost: (...args: unknown[]) =>
|
) => answerOnboardingMock(...args),
|
||||||
confirmOnboardingMock(...args),
|
confirmOnboardingApiV1BoardsBoardIdOnboardingConfirmPost: (
|
||||||
|
...args: unknown[]
|
||||||
|
) => confirmOnboardingMock(...args),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const buildQuestionSession = (question: string): BoardOnboardingRead => ({
|
const buildQuestionSession = (question: string): BoardOnboardingRead => ({
|
||||||
@@ -116,7 +122,9 @@ describe("BoardOnboardingChat polling", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(getOnboardingMock.mock.calls.length).toBeGreaterThan(callsBeforePoll);
|
expect(getOnboardingMock.mock.calls.length).toBeGreaterThan(
|
||||||
|
callsBeforePoll,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ export function GatewayForm({
|
|||||||
role="switch"
|
role="switch"
|
||||||
aria-checked={disableDevicePairing}
|
aria-checked={disableDevicePairing}
|
||||||
aria-label="Disable device pairing"
|
aria-label="Disable device pairing"
|
||||||
onClick={() => onDisableDevicePairingChange(!disableDevicePairing)}
|
onClick={() =>
|
||||||
|
onDisableDevicePairingChange(!disableDevicePairing)
|
||||||
|
}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
className={`inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition ${
|
className={`inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition ${
|
||||||
disableDevicePairing
|
disableDevicePairing
|
||||||
|
|||||||
Reference in New Issue
Block a user