Skip to content

Commit

Permalink
[#IOCOM-1036] Added UserRCConfig model to bind users to rc configurat…
Browse files Browse the repository at this point in the history
…ions (#363)
  • Loading branch information
michaeldisaro authored Feb 27, 2024
1 parent 444b8c3 commit 10b8369
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/models/__tests__/rc_configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
35 changes: 35 additions & 0 deletions src/models/__tests__/user_rc_configuration.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
37 changes: 37 additions & 0 deletions src/models/user_rc_configuration.ts
Original file line number Diff line number Diff line change
@@ -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<typeof UserRCConfiguration>;

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);
}
}

0 comments on commit 10b8369

Please sign in to comment.