generated from nhcarrigan/template
feat: add start and end dates
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import type { AuthResponse, JwtPayload, User } from "../src/lib/auth.types";
|
||||
|
||||
describe("auth Types", () => {
|
||||
describe("user interface", () => {
|
||||
it("should accept valid user objects", () => {
|
||||
const userWithAvatar: User = {
|
||||
avatar: "https://example.com/avatar.png",
|
||||
discordId: "discord123",
|
||||
email: "test@example.com",
|
||||
id: "user123",
|
||||
inDiscord: true,
|
||||
isAdmin: true,
|
||||
isBanned: false,
|
||||
isMod: true,
|
||||
isStaff: true,
|
||||
isVip: false,
|
||||
username: "testuser",
|
||||
};
|
||||
|
||||
const userWithoutAvatar: User = {
|
||||
discordId: "discord456",
|
||||
email: "another@example.com",
|
||||
id: "user456",
|
||||
inDiscord: false,
|
||||
isAdmin: false,
|
||||
isBanned: false,
|
||||
isMod: false,
|
||||
isStaff: false,
|
||||
isVip: true,
|
||||
username: "anotheruser",
|
||||
};
|
||||
|
||||
expect(userWithAvatar.avatar).toBe("https://example.com/avatar.png");
|
||||
expect(userWithoutAvatar.avatar).toBeUndefined();
|
||||
expect(userWithAvatar.isAdmin).toBeTruthy();
|
||||
expect(userWithoutAvatar.isVip).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should handle all boolean flags correctly", () => {
|
||||
const bannedUser: User = {
|
||||
discordId: "discord789",
|
||||
email: "banned@example.com",
|
||||
id: "banned123",
|
||||
inDiscord: false,
|
||||
isAdmin: false,
|
||||
isBanned: true,
|
||||
isMod: false,
|
||||
isStaff: false,
|
||||
isVip: false,
|
||||
username: "banneduser",
|
||||
};
|
||||
|
||||
expect(bannedUser.isBanned).toBeTruthy();
|
||||
expect(bannedUser.isAdmin).toBeFalsy();
|
||||
expect(bannedUser.inDiscord).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("jwtPayload interface", () => {
|
||||
it("should accept JWT payload with required fields", () => {
|
||||
const payload: JwtPayload = {
|
||||
email: "test@example.com",
|
||||
isAdmin: false,
|
||||
sub: "user123",
|
||||
username: "testuser",
|
||||
};
|
||||
|
||||
expect(payload.sub).toBe("user123");
|
||||
expect(payload.iat).toBeUndefined();
|
||||
expect(payload.exp).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should accept JWT payload with timestamps", () => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const payloadWithTimestamps: JwtPayload = {
|
||||
email: "another@example.com",
|
||||
exp: now + 3600,
|
||||
iat: now,
|
||||
isAdmin: true,
|
||||
sub: "user456",
|
||||
username: "anotheruser", // 1 hour
|
||||
};
|
||||
|
||||
expect(payloadWithTimestamps.iat).toBe(now);
|
||||
expect(payloadWithTimestamps.exp).toBe(now + 3600);
|
||||
});
|
||||
});
|
||||
|
||||
describe("authResponse interface", () => {
|
||||
it("should accept valid auth response", () => {
|
||||
const authResponse: AuthResponse = {
|
||||
accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
user: {
|
||||
avatar: "https://example.com/avatar.png",
|
||||
discordId: "discord123",
|
||||
email: "test@example.com",
|
||||
id: "user123",
|
||||
inDiscord: true,
|
||||
isAdmin: false,
|
||||
isBanned: false,
|
||||
isMod: false,
|
||||
isStaff: false,
|
||||
isVip: false,
|
||||
username: "testuser",
|
||||
},
|
||||
};
|
||||
|
||||
expect(authResponse.accessToken).toContain("eyJ");
|
||||
expect(authResponse.user.username).toBe("testuser");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user