Skip to content

Commit

Permalink
document Group, update Base, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanBulmer committed Jul 26, 2024
1 parent 861bb98 commit 07ab24f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 2 additions & 2 deletions src/models/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class Base<K extends string> {
readonly _version: BaseParameters<K>["_version"];
readonly _id: BaseParameters<K>["_id"];
readonly createdAt: BaseParameters<K>["createdAt"];
readonly updatedAt: BaseParameters<K>["updatedAt"];
updatedAt: BaseParameters<K>["updatedAt"];
readonly createdBy: BaseParameters<K>["createdBy"];
readonly updatedBy: BaseParameters<K>["updatedBy"];
updatedBy: BaseParameters<K>["updatedBy"];

constructor({
createdAt,
Expand Down
2 changes: 2 additions & 0 deletions src/models/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/organization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
21 changes: 21 additions & 0 deletions tests/profile.test.ts
Original file line number Diff line number Diff line change
@@ -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));
});
31 changes: 31 additions & 0 deletions tests/user.test.ts
Original file line number Diff line number Diff line change
@@ -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: "[email protected]",
roles: [roleId],
flags: {
isActive: true,
isAnonymous: false,
isDeleted: false,
},
createdBy,
});

assertEquals(user.toJSON().email, "[email protected]");
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));
});

0 comments on commit 07ab24f

Please sign in to comment.