diff --git a/src/models/__tests__/rc_configuration.test.ts b/src/models/__tests__/rc_configuration.test.ts index 9ef8dd48..99cd8d4a 100644 --- a/src/models/__tests__/rc_configuration.test.ts +++ b/src/models/__tests__/rc_configuration.test.ts @@ -85,46 +85,46 @@ const aRetrievedRemoteContentConfigurationWithBothEnv: RetrievedRCConfiguration _ts: 1 }; -describe("RC", () => { - it("GIVEN a valid RC object with test environment WHEN the object is decoded THEN the decode succeed", async () => { +describe("RCConfiguration", () => { + it("GIVEN a valid RCConfiguration object with test environment WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRemoteContentConfigurationWithTestEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); - it("GIVEN a retrieved RC object with test environment WHEN the object is decoded THEN the decode succeed", async () => { + it("GIVEN a retrieved RCConfiguration object with test environment WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRetrievedRemoteContentConfigurationWithTestEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); - it("GIVEN a valid RC object with prod environment WHEN the object is decoded THEN the decode succeed", async () => { + it("GIVEN a valid RCConfiguration object with prod environment WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRemoteContentConfigurationWithProdEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); - it("GIVEN a retrieved RC object with prod environment WHEN the object is decoded THEN the decode succeed", async () => { + it("GIVEN a retrieved RCConfiguration object with prod environment WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRetrievedRemoteContentConfigurationWithProdEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); - it("GIVEN a valid RC object with both environments WHEN the object is decoded THEN the decode succeed", async () => { + it("GIVEN a valid RCConfiguration object with both environments WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRemoteContentConfigurationWithBothEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); - it("GIVEN a retrieved RC object with both environment WHEN the object is decoded THEN the decode succeed", async () => { + it("GIVEN a retrieved RCConfiguration object with both environment WHEN the object is decoded THEN the decode succeed", async () => { const result = RCConfiguration.decode( aRetrievedRemoteContentConfigurationWithBothEnv ); - expect(E.isRight(result)).toBeTruthy(); + expect(E.isRight(result)).toBe(true); }); }); diff --git a/src/models/__tests__/user_rc_configuration.test.ts b/src/models/__tests__/user_rc_configuration.test.ts new file mode 100644 index 00000000..43380f9b --- /dev/null +++ b/src/models/__tests__/user_rc_configuration.test.ts @@ -0,0 +1,35 @@ +import * as E from "fp-ts/lib/Either"; +import { NonEmptyString } from "@pagopa/ts-commons/lib/strings"; +import { + UserRCConfiguration, + RetrievedUserRCConfiguration +} from "../user_rc_configuration"; + +const aUserRCConfiguration: UserRCConfiguration = { + userId: "aUserId" as NonEmptyString, + id: "01HMRBX079WA5SGYBQP1A7FSKH" as NonEmptyString +}; + +const aRetrievedUserRCConfiguration: RetrievedUserRCConfiguration = { + ...aUserRCConfiguration, + _etag: "_etag", + _rid: "_rid", + _self: "_self", + _ts: 1 +}; + +describe("UserRCConfiguration", () => { + it("GIVEN a valid UserRCConfiguration object WHEN the object is decoded THEN the decode succeed", async () => { + const result = UserRCConfiguration.decode( + aUserRCConfiguration + ); + expect(E.isRight(result)).toBeTruthy(); + }); + + it("GIVEN a retrieved RC object with test environment WHEN the object is decoded THEN the decode succeed", async () => { + const result = UserRCConfiguration.decode( + aRetrievedUserRCConfiguration + ); + expect(E.isRight(result)).toBeTruthy(); + }); +}); diff --git a/src/models/user_rc_configuration.ts b/src/models/user_rc_configuration.ts new file mode 100644 index 00000000..6217ef78 --- /dev/null +++ b/src/models/user_rc_configuration.ts @@ -0,0 +1,37 @@ +import * as t from "io-ts"; +import { NonEmptyString } from "@pagopa/ts-commons/lib/strings"; +import { Container } from "@azure/cosmos"; +import { AzureCosmosResource, CosmosdbModel } from "../utils/cosmosdb_model"; + +export const USER_RC_CONFIGURATIONS_COLLECTION_NAME = "user-configurations"; +const USER_RC_CONFIGURATIONS_MODEL_PK_FIELD = "userId"; + +export const UserRCConfiguration = t.interface({ + id: NonEmptyString, + userId: NonEmptyString +}); +export type UserRCConfiguration = t.TypeOf; + +export const RetrievedUserRCConfiguration = t.intersection([ + UserRCConfiguration, + AzureCosmosResource +]); +export type RetrievedUserRCConfiguration = t.TypeOf< + typeof RetrievedUserRCConfiguration +>; + +export class UserRCConfigurationModel extends CosmosdbModel< + UserRCConfiguration, + UserRCConfiguration, + RetrievedUserRCConfiguration, + typeof USER_RC_CONFIGURATIONS_MODEL_PK_FIELD +> { + /** + * Creates a new RemoteContentConfiguration model + * + * @param container the Cosmos container client + */ + constructor(container: Container) { + super(container, UserRCConfiguration, RetrievedUserRCConfiguration); + } +}