From a9297af2d350c30d6fb01c8a6ddfbc3df9089ae6 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Tue, 13 Feb 2024 06:27:52 -0600 Subject: [PATCH] Add a key definition for providers (#7915) --- .../services/provider.service.spec.ts | 23 +++++++++++++++++++ .../services/provider.service.ts | 5 ++++ 2 files changed, 28 insertions(+) create mode 100644 libs/common/src/admin-console/services/provider.service.spec.ts diff --git a/libs/common/src/admin-console/services/provider.service.spec.ts b/libs/common/src/admin-console/services/provider.service.spec.ts new file mode 100644 index 0000000000..b76cf3476e --- /dev/null +++ b/libs/common/src/admin-console/services/provider.service.spec.ts @@ -0,0 +1,23 @@ +import { ProviderUserStatusType, ProviderUserType } from "../enums"; +import { ProviderData } from "../models/data/provider.data"; + +import { PROVIDERS } from "./provider.service"; + +describe("PROVIDERS key definition", () => { + const sut = PROVIDERS; + it("should deserialize to a proper ProviderData object", async () => { + const expectedResult: Record = { + "1": { + id: "string", + name: "string", + status: ProviderUserStatusType.Accepted, + type: ProviderUserType.ServiceUser, + enabled: true, + userId: "string", + useEvents: true, + }, + }; + const result = sut.deserializer(JSON.parse(JSON.stringify(expectedResult))); + expect(result).toEqual(expectedResult); + }); +}); diff --git a/libs/common/src/admin-console/services/provider.service.ts b/libs/common/src/admin-console/services/provider.service.ts index dce35c5789..520424373b 100644 --- a/libs/common/src/admin-console/services/provider.service.ts +++ b/libs/common/src/admin-console/services/provider.service.ts @@ -1,8 +1,13 @@ import { StateService } from "../../platform/abstractions/state.service"; +import { KeyDefinition, PROVIDERS_DISK } from "../../platform/state"; import { ProviderService as ProviderServiceAbstraction } from "../abstractions/provider.service"; import { ProviderData } from "../models/data/provider.data"; import { Provider } from "../models/domain/provider"; +export const PROVIDERS = KeyDefinition.record(PROVIDERS_DISK, "providers", { + deserializer: (obj: ProviderData) => obj, +}); + export class ProviderService implements ProviderServiceAbstraction { constructor(private stateService: StateService) {}