generated from pagopa/io-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#IOCOM-1036] Added UserRCConfig model to bind users to rc configurat…
…ions (#363)
- Loading branch information
1 parent
444b8c3
commit 10b8369
Showing
3 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |