Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#IOCOM-1036] Added UserRCConfig model to bind users to rc configurations #363

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/models/__tests__/rc_configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as E from "fp-ts/lib/Either";
import { NonEmptyString, Ulid } from "@pagopa/ts-commons/lib/strings";
import {
RCConfiguration,
RetrievedRCConfiguration
} from "../rc_configuration";
import { RCConfiguration, RetrievedRCConfiguration } from "../rc_configuration";
import { RCConfigurationBase } from "../../../generated/definitions/RCConfigurationBase";
import { HasPreconditionEnum } from "../../../generated/definitions/HasPrecondition";
import { NonNegativeInteger } from "@pagopa/ts-commons/lib/numbers";
Expand Down Expand Up @@ -85,51 +82,51 @@ 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);
});

it("GIVEN a not valid RC object with no environments WHEN the object is decoded THEN the decode fail", async () => {
it("GIVEN a not valid RCConfiguration object with no environments WHEN the object is decoded THEN the decode fail", async () => {
const result = RCConfiguration.decode(aRemoteContentConfigurationWithNoEnv);
expect(E.isLeft(result)).toBeTruthy();
expect(E.isLeft(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();
});
});
44 changes: 44 additions & 0 deletions src/models/user_rc_configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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({
userId: NonEmptyString,
id: NonEmptyString
Garma00 marked this conversation as resolved.
Show resolved Hide resolved
});
export type UserRCConfiguration = t.TypeOf<typeof UserRCConfiguration>;

export const RetrievedUserRCConfiguration = t.intersection([
UserRCConfiguration,
AzureCosmosResource
]);
export type RetrievedUserRCConfiguration = t.TypeOf<
typeof RetrievedUserRCConfiguration
>;

/**
* @deprecated This model is deprecated, use the one inside ./remote_content.ts instead
*/
michaeldisaro marked this conversation as resolved.
Show resolved Hide resolved
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
);
}
}
michaeldisaro marked this conversation as resolved.
Show resolved Hide resolved