diff --git a/src/mod.ts b/src/mod.ts index cccaa1e..55ed522 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,3 +1,3 @@ // export * as Types from "./types/mod.ts"; export * from "./models/mod.ts"; -export type { JwtPayload } from "./types/mod.ts"; +export { type JwtPayload, UserTypeCode } from "./types/mod.ts"; diff --git a/src/models/Base.ts b/src/models/Base.ts index b3ab5f5..786f773 100644 --- a/src/models/Base.ts +++ b/src/models/Base.ts @@ -25,9 +25,9 @@ export class Base { readonly _version: BaseParameters["_version"]; readonly _id: BaseParameters["_id"]; readonly createdAt: BaseParameters["createdAt"]; - readonly updatedAt: BaseParameters["updatedAt"]; + updatedAt: BaseParameters["updatedAt"]; readonly createdBy: BaseParameters["createdBy"]; - readonly updatedBy: BaseParameters["updatedBy"]; + updatedBy: BaseParameters["updatedBy"]; constructor({ createdAt, diff --git a/src/models/Group.ts b/src/models/Group.ts index 91b9506..4a44605 100644 --- a/src/models/Group.ts +++ b/src/models/Group.ts @@ -18,7 +18,9 @@ export interface GroupParameters< * Parameters for adding Group members to the {@link GroupParameters}. */ export interface GroupMemberParameters { + /** Group member type from {@link GroupMemberType} */ type: GroupMemberType; + /** Either a User or Group ObjectId */ _id: ObjectId; } diff --git a/tests/organization.test.ts b/tests/organization.test.ts index 7363877..747f53b 100644 --- a/tests/organization.test.ts +++ b/tests/organization.test.ts @@ -2,7 +2,7 @@ import { assert, assertEquals } from "@std/assert"; import { Organization } from "../mod.ts"; import { ObjectId } from "bson"; -Deno.test("Create organziation", function createOrganization() { +Deno.test("Create Organziation", function createOrganization() { const createdBy: ObjectId = new ObjectId(); const org = new Organization({ domains: ["localhost:3000"], diff --git a/tests/profile.test.ts b/tests/profile.test.ts new file mode 100644 index 0000000..a848988 --- /dev/null +++ b/tests/profile.test.ts @@ -0,0 +1,21 @@ +import { assert, assertEquals } from "@std/assert"; +import { Profile } from "../mod.ts"; +import { ObjectId } from "bson"; + +Deno.test("Create Profile", function createProfile() { + const userId: ObjectId = new ObjectId(); + const createdBy: ObjectId = new ObjectId(); + const profile = new Profile({ + userId: userId, + name: { first: "Demo", last: "User" }, + username: "DemoUser", + createdBy, + }); + + assertEquals(profile.toJSON().name.first, "Demo"); + assertEquals(profile.toJSON().name.last, "User"); + assertEquals(profile.toJSON().username, "DemoUser"); + assert(profile.toJSON().userId.equals(userId)); + assert(profile.toJSON().createdBy.equals(createdBy)); + assert(profile.toJSON().updatedBy.equals(createdBy)); +}); diff --git a/tests/user.test.ts b/tests/user.test.ts new file mode 100644 index 0000000..73e5746 --- /dev/null +++ b/tests/user.test.ts @@ -0,0 +1,31 @@ +import { assert, assertEquals } from "@std/assert"; +import { User, UserTypeCode } from "../mod.ts"; +import { ObjectId } from "bson"; + +Deno.test("Create User", function createUser() { + const orgId: ObjectId = new ObjectId(); + const roleId: ObjectId = new ObjectId(); + const createdBy: ObjectId = new ObjectId(); + const user = new User({ + organizationId: orgId, + identityId: "identity_id", + type: UserTypeCode.Member, + email: "demo@codr.sh", + roles: [roleId], + flags: { + isActive: true, + isAnonymous: false, + isDeleted: false, + }, + createdBy, + }); + + assertEquals(user.toJSON().email, "demo@codr.sh"); + assertEquals(user.toJSON().flags.isActive, true); + assertEquals(user.toJSON().flags.isDeleted, false); + assertEquals(user.toJSON().flags.isAnonymous, false); + assert(user.toJSON().organizationId.equals(orgId)); + assert(user.toJSON().roles[0].equals(roleId)); + assert(user.toJSON().createdBy.equals(createdBy)); + assert(user.toJSON().updatedBy.equals(createdBy)); +});