Skip to content

Commit 07ab24f

Browse files
author
DylanBulmer
committed
document Group, update Base, add tests
1 parent 861bb98 commit 07ab24f

6 files changed

Lines changed: 58 additions & 4 deletions

File tree

src/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// export * as Types from "./types/mod.ts";
22
export * from "./models/mod.ts";
3-
export type { JwtPayload } from "./types/mod.ts";
3+
export { type JwtPayload, UserTypeCode } from "./types/mod.ts";

src/models/Base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class Base<K extends string> {
2525
readonly _version: BaseParameters<K>["_version"];
2626
readonly _id: BaseParameters<K>["_id"];
2727
readonly createdAt: BaseParameters<K>["createdAt"];
28-
readonly updatedAt: BaseParameters<K>["updatedAt"];
28+
updatedAt: BaseParameters<K>["updatedAt"];
2929
readonly createdBy: BaseParameters<K>["createdBy"];
30-
readonly updatedBy: BaseParameters<K>["updatedBy"];
30+
updatedBy: BaseParameters<K>["updatedBy"];
3131

3232
constructor({
3333
createdAt,

src/models/Group.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export interface GroupParameters<
1818
* Parameters for adding Group members to the {@link GroupParameters}.
1919
*/
2020
export interface GroupMemberParameters {
21+
/** Group member type from {@link GroupMemberType} */
2122
type: GroupMemberType;
23+
/** Either a User or Group ObjectId */
2224
_id: ObjectId;
2325
}
2426

tests/organization.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, assertEquals } from "@std/assert";
22
import { Organization } from "../mod.ts";
33
import { ObjectId } from "bson";
44

5-
Deno.test("Create organziation", function createOrganization() {
5+
Deno.test("Create Organziation", function createOrganization() {
66
const createdBy: ObjectId = new ObjectId();
77
const org = new Organization({
88
domains: ["localhost:3000"],

tests/profile.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { assert, assertEquals } from "@std/assert";
2+
import { Profile } from "../mod.ts";
3+
import { ObjectId } from "bson";
4+
5+
Deno.test("Create Profile", function createProfile() {
6+
const userId: ObjectId = new ObjectId();
7+
const createdBy: ObjectId = new ObjectId();
8+
const profile = new Profile({
9+
userId: userId,
10+
name: { first: "Demo", last: "User" },
11+
username: "DemoUser",
12+
createdBy,
13+
});
14+
15+
assertEquals(profile.toJSON().name.first, "Demo");
16+
assertEquals(profile.toJSON().name.last, "User");
17+
assertEquals(profile.toJSON().username, "DemoUser");
18+
assert(profile.toJSON().userId.equals(userId));
19+
assert(profile.toJSON().createdBy.equals(createdBy));
20+
assert(profile.toJSON().updatedBy.equals(createdBy));
21+
});

tests/user.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { assert, assertEquals } from "@std/assert";
2+
import { User, UserTypeCode } from "../mod.ts";
3+
import { ObjectId } from "bson";
4+
5+
Deno.test("Create User", function createUser() {
6+
const orgId: ObjectId = new ObjectId();
7+
const roleId: ObjectId = new ObjectId();
8+
const createdBy: ObjectId = new ObjectId();
9+
const user = new User({
10+
organizationId: orgId,
11+
identityId: "identity_id",
12+
type: UserTypeCode.Member,
13+
email: "demo@codr.sh",
14+
roles: [roleId],
15+
flags: {
16+
isActive: true,
17+
isAnonymous: false,
18+
isDeleted: false,
19+
},
20+
createdBy,
21+
});
22+
23+
assertEquals(user.toJSON().email, "demo@codr.sh");
24+
assertEquals(user.toJSON().flags.isActive, true);
25+
assertEquals(user.toJSON().flags.isDeleted, false);
26+
assertEquals(user.toJSON().flags.isAnonymous, false);
27+
assert(user.toJSON().organizationId.equals(orgId));
28+
assert(user.toJSON().roles[0].equals(roleId));
29+
assert(user.toJSON().createdBy.equals(createdBy));
30+
assert(user.toJSON().updatedBy.equals(createdBy));
31+
});

0 commit comments

Comments
 (0)