feat: add start and end dates

This commit is contained in:
2026-02-19 15:20:25 -08:00
parent 9f0132db34
commit d4d5cfa532
41 changed files with 2854 additions and 140 deletions
+110
View File
@@ -0,0 +1,110 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Art, CreateArtDto, UpdateArtDto } from "../src/lib/art.types";
describe("art Types", () => {
describe("art interface", () => {
it("should accept valid art object with minimal fields", () => {
const art: Art = {
artist: "Jane Doe",
createdAt: new Date(),
dateAdded: new Date(),
id: "art123",
imageUrl: "https://example.com/sunset.jpg",
links: [],
tags: [],
title: "Beautiful Sunset",
updatedAt: new Date(),
};
expect(art.description).toBeUndefined();
expect(art.tags).toEqual([]);
});
it("should accept valid art object with all fields", () => {
const fullArt: Art = {
artist: "John Smith",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
description: "A breathtaking view of the mountains",
id: "art456",
imageUrl: "https://example.com/mountains.jpg",
links: [
{ title: "Artist Portfolio", url: "https://artist.com" },
{ title: "Instagram", url: "https://instagram.com/artist" },
],
tags: [ "landscape", "nature", "mountains" ],
title: "Mountain Landscape",
updatedAt: new Date("2024-01-02"),
};
expect(fullArt.description).toBe("A breathtaking view of the mountains");
expect(fullArt.tags).toHaveLength(3);
expect(fullArt.links).toHaveLength(2);
});
});
describe("createArtDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateArtDto = {
artist: "New Artist",
imageUrl: "https://example.com/art.jpg",
title: "New Artwork",
};
expect(createDto.description).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateArtDto = {
artist: "Famous Artist",
description: "Detailed description",
imageUrl: "https://example.com/complete.jpg",
links: [ { title: "Website", url: "https://website.com" } ],
tags: [ "tag1", "tag2" ],
title: "Complete Artwork",
};
expect(fullCreateDto.tags).toEqual([ "tag1", "tag2" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateArtDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateArtDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates", () => {
const partialUpdate: UpdateArtDto = {
tags: [ "new-tag" ],
title: "Updated Title",
};
expect(partialUpdate.title).toBe("Updated Title");
expect(partialUpdate.artist).toBeUndefined();
expect(partialUpdate.tags).toEqual([ "new-tag" ]);
});
it("should accept full update", () => {
const fullUpdate: UpdateArtDto = {
artist: "Different Artist",
description: "New description",
imageUrl: "https://example.com/new-image.jpg",
links: [ { title: "New Link", url: "https://newlink.com" } ],
tags: [ "updated", "tags" ],
title: "Completely New Title",
};
expect(fullUpdate.title).toBe("Completely New Title");
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+129
View File
@@ -0,0 +1,129 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import {
AuditAction,
AuditCategory,
type AuditLog,
type AuditLogFilters,
type AuditLogUser,
} from "../src/lib/audit.types";
describe("audit Types", () => {
describe("auditAction enum", () => {
it("should have all expected action values", () => {
expect(AuditAction.login).toBe("LOGIN");
expect(AuditAction.logout).toBe("LOGOUT");
expect(AuditAction.loginFailed).toBe("LOGIN_FAILED");
expect(AuditAction.commentCreate).toBe("COMMENT_CREATE");
expect(AuditAction.commentUpdate).toBe("COMMENT_UPDATE");
expect(AuditAction.commentDelete).toBe("COMMENT_DELETE");
expect(AuditAction.entryCreate).toBe("ENTRY_CREATE");
expect(AuditAction.entryUpdate).toBe("ENTRY_UPDATE");
expect(AuditAction.entryDelete).toBe("ENTRY_DELETE");
expect(AuditAction.like).toBe("LIKE");
expect(AuditAction.unlike).toBe("UNLIKE");
expect(AuditAction.userBan).toBe("USER_BAN");
expect(AuditAction.userUnban).toBe("USER_UNBAN");
expect(AuditAction.rateLimitExceeded).toBe("RATE_LIMIT_EXCEEDED");
expect(AuditAction.csrfValidationFailed).toBe("CSRF_VALIDATION_FAILED");
expect(AuditAction.unauthorizedAccess).toBe("UNAUTHORIZED_ACCESS");
});
});
describe("auditCategory enum", () => {
it("should have all expected category values", () => {
expect(AuditCategory.auth).toBe("AUTH");
expect(AuditCategory.content).toBe("CONTENT");
expect(AuditCategory.admin).toBe("ADMIN");
expect(AuditCategory.security).toBe("SECURITY");
});
});
describe("auditLogUser interface", () => {
it("should accept valid user objects", () => {
const userWithAvatar: AuditLogUser = {
avatar: "https://example.com/avatar.png",
id: "user123",
username: "testuser",
};
const userWithoutAvatar: AuditLogUser = {
id: "user456",
username: "anotheruser",
};
expect(userWithAvatar.avatar).toBe("https://example.com/avatar.png");
expect(userWithoutAvatar.avatar).toBeUndefined();
});
});
describe("auditLog interface", () => {
it("should accept valid audit log with minimal fields", () => {
const minimalLog: AuditLog = {
action: AuditAction.login,
category: AuditCategory.auth,
createdAt: new Date(),
id: "log123",
success: true,
};
expect(minimalLog.userId).toBeUndefined();
expect(minimalLog.details).toBeUndefined();
});
it("should accept valid audit log with all fields", () => {
const fullLog: AuditLog = {
action: AuditAction.commentDelete,
category: AuditCategory.admin,
createdAt: new Date(),
details: "Admin deleted inappropriate comment",
id: "log456",
resourceId: "comment123",
resourceType: "comment",
success: true,
targetUser: {
id: "user789",
username: "targetuser",
},
targetUserId: "user789",
user: {
avatar: "https://example.com/avatar.png",
id: "user123",
username: "admin",
},
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
userId: "user123",
};
expect(fullLog.user?.username).toBe("admin");
expect(fullLog.targetUser?.username).toBe("targetuser");
});
});
describe("auditLogFilters interface", () => {
it("should accept empty filters", () => {
const emptyFilters: AuditLogFilters = {};
expect(emptyFilters).toEqual({});
});
it("should accept filters with all fields", () => {
const fullFilters: AuditLogFilters = {
action: AuditAction.login,
category: AuditCategory.auth,
endDate: new Date("2024-12-31"),
limit: 50,
page: 1,
startDate: new Date("2024-01-01"),
success: true,
userId: "user123",
};
expect(fullFilters.page).toBe(1);
expect(fullFilters.limit).toBe(50);
});
});
});
+118
View File
@@ -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");
});
});
});
+150
View File
@@ -0,0 +1,150 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { BookStatus } from "../src/lib/book.types";
import type { Book, CreateBookDto, UpdateBookDto } from "../src/lib/book.types";
describe("book Types", () => {
describe("bookStatus enum", () => {
it("should have the correct values", () => {
expect(BookStatus.reading).toBe("READING");
expect(BookStatus.finished).toBe("FINISHED");
expect(BookStatus.toRead).toBe("TO_READ");
});
it("should have all expected enum values", () => {
const values = Object.values(BookStatus);
expect(values).toHaveLength(3);
expect(values).toContain("READING");
expect(values).toContain("FINISHED");
expect(values).toContain("TO_READ");
});
});
describe("book interface", () => {
it("should accept valid book object with minimal fields", () => {
const book: Book = {
author: "F. Scott Fitzgerald",
createdAt: new Date("2024-01-15"),
dateAdded: new Date("2024-01-15"),
id: "book123",
links: [],
status: BookStatus.reading,
tags: [],
title: "The Great Gatsby",
updatedAt: new Date("2024-01-16"),
};
expect(book.isbn).toBeUndefined();
expect(book.dateFinished).toBeUndefined();
expect(book.rating).toBeUndefined();
expect(book.notes).toBeUndefined();
expect(book.coverImage).toBeUndefined();
});
it("should accept valid book object with all fields", () => {
const fullBook: Book = {
author: "George Orwell",
coverImage: "https://example.com/1984-cover.jpg",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
dateFinished: new Date("2024-01-20"),
id: "book456",
isbn: "978-0-452-28423-4",
links: [
{ title: "Goodreads", url: "https://goodreads.com/book/1984" },
{ title: "Wikipedia", url: "https://wikipedia.org/wiki/1984" },
],
notes: "A dystopian masterpiece that remains relevant",
rating: 5,
status: BookStatus.finished,
tags: [ "dystopian", "classic", "political" ],
title: "1984",
updatedAt: new Date("2024-01-20"),
};
expect(fullBook.isbn).toBe("978-0-452-28423-4");
expect(fullBook.rating).toBe(5);
expect(fullBook.tags).toHaveLength(3);
expect(fullBook.links).toHaveLength(2);
});
});
describe("createBookDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateBookDto = {
author: "Harper Lee",
status: BookStatus.toRead,
title: "To Kill a Mockingbird",
};
expect(createDto.isbn).toBeUndefined();
expect(createDto.rating).toBeUndefined();
expect(createDto.notes).toBeUndefined();
expect(createDto.coverImage).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateBookDto = {
author: "J.R.R. Tolkien",
coverImage: "https://example.com/hobbit-cover.jpg",
isbn: "978-0-547-92822-7",
links: [ { title: "Author Website", url: "https://tolkien.com" } ],
notes: "Starting the journey to Middle-earth",
rating: 4,
status: BookStatus.reading,
tags: [ "fantasy", "adventure", "classic" ],
title: "The Hobbit",
};
expect(fullCreateDto.isbn).toBe("978-0-547-92822-7");
expect(fullCreateDto.rating).toBe(4);
expect(fullCreateDto.tags).toEqual([ "fantasy", "adventure", "classic" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateBookDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateBookDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates including dateFinished", () => {
const partialUpdate: UpdateBookDto = {
dateFinished: new Date("2024-02-01"),
rating: 5,
status: BookStatus.finished,
};
expect(partialUpdate.status).toBe(BookStatus.finished);
expect(partialUpdate.dateFinished).toEqual(new Date("2024-02-01"));
expect(partialUpdate.rating).toBe(5);
expect(partialUpdate.title).toBeUndefined();
});
it("should accept full update", () => {
const fullUpdate: UpdateBookDto = {
author: "Different Author",
coverImage: "https://example.com/new-cover.jpg",
dateFinished: new Date("2024-02-15"),
isbn: "978-1-234-56789-0",
links: [ { title: "New Link", url: "https://newlink.com" } ],
notes: "Updated notes after finishing",
rating: 3,
status: BookStatus.finished,
tags: [ "updated", "tags" ],
title: "Updated Title",
};
expect(fullUpdate.title).toBe("Updated Title");
expect(fullUpdate.dateFinished).toEqual(new Date("2024-02-15"));
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+195
View File
@@ -0,0 +1,195 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { CommentUser, Comment, CreateCommentDto } from "../src/lib/comment.types";
describe("comment Types", () => {
describe("commentUser interface", () => {
it("should accept valid user object with minimal fields", () => {
const user: CommentUser = {
id: "user123",
username: "testuser",
};
expect(user.avatar).toBeUndefined();
expect(user.inDiscord).toBeUndefined();
expect(user.isVip).toBeUndefined();
expect(user.isMod).toBeUndefined();
expect(user.isStaff).toBeUndefined();
});
it("should accept valid user object with all fields", () => {
const fullUser: CommentUser = {
avatar: "https://example.com/avatar.png",
id: "user456",
inDiscord: true,
isMod: true,
isStaff: false,
isVip: true,
username: "vipmoduser",
};
expect(fullUser.avatar).toBe("https://example.com/avatar.png");
expect(fullUser.inDiscord).toBeTruthy();
expect(fullUser.isVip).toBeTruthy();
expect(fullUser.isMod).toBeTruthy();
expect(fullUser.isStaff).toBeFalsy();
});
});
describe("comment interface", () => {
it("should accept valid comment object with minimal fields", () => {
const comment: Comment = {
content: "This is a great book!",
createdAt: new Date("2024-01-15"),
id: "comment123",
updatedAt: new Date("2024-01-15"),
user: {
id: "user123",
username: "bookworm",
},
userId: "user123",
};
expect(comment.rawContent).toBeUndefined();
expect(comment.gameId).toBeUndefined();
expect(comment.bookId).toBeUndefined();
expect(comment.musicId).toBeUndefined();
expect(comment.artId).toBeUndefined();
expect(comment.showId).toBeUndefined();
expect(comment.mangaId).toBeUndefined();
});
it("should accept comment for a book", () => {
const bookComment: Comment = {
bookId: "book123",
content: "<p>Amazing read!</p>",
createdAt: new Date("2024-01-20"),
id: "comment456",
rawContent: "Amazing read!",
updatedAt: new Date("2024-01-21"),
user: {
avatar: "https://example.com/reader.png",
id: "user789",
inDiscord: true,
isMod: false,
isStaff: false,
isVip: false,
username: "reader",
},
userId: "user789",
};
expect(bookComment.bookId).toBe("book123");
expect(bookComment.rawContent).toBe("Amazing read!");
expect(bookComment.gameId).toBeUndefined();
});
it("should accept comment for a game", () => {
const gameComment: Comment = {
content: "Best game ever!",
createdAt: new Date("2024-02-01"),
gameId: "game789",
id: "comment789",
updatedAt: new Date("2024-02-01"),
user: {
id: "user456",
username: "gamer",
},
userId: "user456",
};
expect(gameComment.gameId).toBe("game789");
expect(gameComment.bookId).toBeUndefined();
});
it("should accept comment for music", () => {
const musicComment: Comment = {
content: "Beautiful album",
createdAt: new Date("2024-02-10"),
id: "comment999",
musicId: "music123",
updatedAt: new Date("2024-02-10"),
user: {
id: "user111",
username: "musiclover",
},
userId: "user111",
};
expect(musicComment.musicId).toBe("music123");
});
it("should accept comment for art", () => {
const artComment: Comment = {
artId: "art456",
content: "Stunning artwork!",
createdAt: new Date("2024-02-15"),
id: "comment111",
updatedAt: new Date("2024-02-15"),
user: {
id: "user222",
username: "artcritic",
},
userId: "user222",
};
expect(artComment.artId).toBe("art456");
});
it("should accept comment for a show", () => {
const showComment: Comment = {
content: "Great series!",
createdAt: new Date("2024-02-20"),
id: "comment222",
showId: "show789",
updatedAt: new Date("2024-02-20"),
user: {
id: "user333",
username: "tvfan",
},
userId: "user333",
};
expect(showComment.showId).toBe("show789");
});
it("should accept comment for manga", () => {
const mangaComment: Comment = {
content: "Awesome manga!",
createdAt: new Date("2024-02-25"),
id: "comment333",
mangaId: "manga123",
updatedAt: new Date("2024-02-25"),
user: {
id: "user444",
username: "mangareader",
},
userId: "user444",
};
expect(mangaComment.mangaId).toBe("manga123");
});
});
describe("createCommentDto interface", () => {
it("should accept DTO with content", () => {
const createDto: CreateCommentDto = {
content: "This is my comment",
};
expect(createDto.content).toBe("This is my comment");
});
it("should accept DTO with formatted content", () => {
const createDto: CreateCommentDto = {
content: "<p>This is <strong>formatted</strong> content!</p>",
};
expect(createDto.content).toBe("<p>This is <strong>formatted</strong> content!</p>");
});
});
});
+37
View File
@@ -0,0 +1,37 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Link } from "../src/lib/common.types";
describe("common Types", () => {
describe("link interface", () => {
it("should accept valid Link objects", () => {
const validLink: Link = {
title: "Example Website",
url: "https://example.com",
};
expect(validLink.title).toBe("Example Website");
expect(validLink.url).toBe("https://example.com");
});
it("should work with different URL formats", () => {
const links: Array<Link> = [
{ title: "HTTP URL", url: "http://example.com" },
{ title: "HTTPS URL", url: "https://example.com" },
{ title: "Relative URL", url: "/path/to/page" },
{ title: "URL with query", url: "https://example.com?query=value" },
{ title: "URL with anchor", url: "https://example.com#section" },
];
expect(links).toHaveLength(5);
for (const link of links) {
expect(link).toHaveProperty("title");
expect(link).toHaveProperty("url");
}
});
});
});
+175
View File
@@ -0,0 +1,175 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { GameStatus } from "../src/lib/game.types";
import type { Game, CreateGameDto, UpdateGameDto } from "../src/lib/game.types";
describe("game Types", () => {
describe("gameStatus enum", () => {
it("should have the correct values", () => {
expect(GameStatus.playing).toBe("PLAYING");
expect(GameStatus.completed).toBe("COMPLETED");
expect(GameStatus.backlog).toBe("BACKLOG");
});
it("should have all expected enum values", () => {
const values = Object.values(GameStatus);
expect(values).toHaveLength(3);
expect(values).toContain("PLAYING");
expect(values).toContain("COMPLETED");
expect(values).toContain("BACKLOG");
});
});
describe("game interface", () => {
it("should accept valid game object with minimal fields", () => {
const game: Game = {
createdAt: new Date("2024-01-15"),
dateAdded: new Date("2024-01-15"),
id: "game123",
links: [],
status: GameStatus.playing,
tags: [],
title: "The Legend of Zelda: Breath of the Wild",
updatedAt: new Date("2024-01-16"),
};
expect(game.platform).toBeUndefined();
expect(game.dateCompleted).toBeUndefined();
expect(game.rating).toBeUndefined();
expect(game.notes).toBeUndefined();
expect(game.coverImage).toBeUndefined();
});
it("should accept valid game object with all fields", () => {
const fullGame: Game = {
coverImage: "https://example.com/hades-cover.jpg",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
dateCompleted: new Date("2024-01-20"),
id: "game456",
links: [
{ title: "Steam", url: "https://store.steampowered.com/app/hades" },
{ title: "Official Site", url: "https://supergiantgames.com/hades" },
],
notes: "One of the best roguelikes ever made",
platform: "Nintendo Switch",
rating: 5,
status: GameStatus.completed,
tags: [ "roguelike", "indie", "action", "mythology" ],
title: "Hades",
updatedAt: new Date("2024-01-20"),
};
expect(fullGame.platform).toBe("Nintendo Switch");
expect(fullGame.rating).toBe(5);
expect(fullGame.tags).toHaveLength(4);
expect(fullGame.links).toHaveLength(2);
});
it("should accept games on different platforms", () => {
const pcGame: Game = {
createdAt: new Date("2024-02-01"),
dateAdded: new Date("2024-02-01"),
id: "game789",
links: [],
platform: "PC",
status: GameStatus.completed,
tags: [ "puzzle", "first-person" ],
title: "Portal 2",
updatedAt: new Date("2024-02-01"),
};
const ps5Game: Game = {
createdAt: new Date("2024-02-05"),
dateAdded: new Date("2024-02-05"),
id: "game999",
links: [],
platform: "PlayStation 5",
status: GameStatus.backlog,
tags: [ "action", "superhero" ],
title: "Spider-Man: Miles Morales",
updatedAt: new Date("2024-02-05"),
};
expect(pcGame.platform).toBe("PC");
expect(ps5Game.platform).toBe("PlayStation 5");
});
});
describe("createGameDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateGameDto = {
status: GameStatus.backlog,
title: "Elden Ring",
};
expect(createDto.platform).toBeUndefined();
expect(createDto.rating).toBeUndefined();
expect(createDto.notes).toBeUndefined();
expect(createDto.coverImage).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateGameDto = {
coverImage: "https://example.com/hollow-knight.jpg",
links: [ { title: "Wiki", url: "https://hollowknight.wiki" } ],
notes: "Beautiful metroidvania with challenging gameplay",
platform: "Nintendo Switch",
rating: 4,
status: GameStatus.playing,
tags: [ "metroidvania", "indie", "platformer" ],
title: "Hollow Knight",
};
expect(fullCreateDto.platform).toBe("Nintendo Switch");
expect(fullCreateDto.rating).toBe(4);
expect(fullCreateDto.tags).toEqual([ "metroidvania", "indie", "platformer" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateGameDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateGameDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates including dateCompleted", () => {
const partialUpdate: UpdateGameDto = {
dateCompleted: new Date("2024-02-10"),
rating: 5,
status: GameStatus.completed,
};
expect(partialUpdate.status).toBe(GameStatus.completed);
expect(partialUpdate.dateCompleted).toEqual(new Date("2024-02-10"));
expect(partialUpdate.rating).toBe(5);
expect(partialUpdate.title).toBeUndefined();
});
it("should accept full update", () => {
const fullUpdate: UpdateGameDto = {
coverImage: "https://example.com/new-cover.jpg",
dateCompleted: new Date("2024-02-15"),
links: [ { title: "New Link", url: "https://newlink.com" } ],
notes: "Updated after completion",
platform: "Xbox Series X",
rating: 3,
status: GameStatus.completed,
tags: [ "updated", "tags" ],
title: "Updated Game Title",
};
expect(fullUpdate.title).toBe("Updated Game Title");
expect(fullUpdate.platform).toBe("Xbox Series X");
expect(fullUpdate.dateCompleted).toEqual(new Date("2024-02-15"));
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+228
View File
@@ -0,0 +1,228 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Like, CreateLikeDto, LikeResponse, LikedItemDto, LikeCountDto } from "../src/lib/like.types";
describe("like Types", () => {
describe("like interface", () => {
it("should accept valid like object for a book", () => {
const bookLike: Like = {
createdAt: new Date("2024-01-15"),
entityId: "book456",
entityType: "book",
id: "like123",
userId: "user123",
};
expect(bookLike.entityType).toBe("book");
expect(bookLike.entityId).toBe("book456");
});
it("should accept valid like object for a game", () => {
const gameLike: Like = {
createdAt: new Date("2024-01-20"),
entityId: "game123",
entityType: "game",
id: "like456",
userId: "user789",
};
expect(gameLike.entityType).toBe("game");
expect(gameLike.entityId).toBe("game123");
});
it("should accept likes for all entity types", () => {
const showLike: Like = {
createdAt: new Date("2024-02-01"),
entityId: "show222",
entityType: "show",
id: "like789",
userId: "user111",
};
const mangaLike: Like = {
createdAt: new Date("2024-02-05"),
entityId: "manga444",
entityType: "manga",
id: "like999",
userId: "user333",
};
const musicLike: Like = {
createdAt: new Date("2024-02-10"),
entityId: "music666",
entityType: "music",
id: "like111",
userId: "user555",
};
const artLike: Like = {
createdAt: new Date("2024-02-15"),
entityId: "art888",
entityType: "art",
id: "like222",
userId: "user777",
};
expect(showLike.entityType).toBe("show");
expect(mangaLike.entityType).toBe("manga");
expect(musicLike.entityType).toBe("music");
expect(artLike.entityType).toBe("art");
});
});
describe("createLikeDto type", () => {
it("should pick only entityType and entityId from Like", () => {
const createDto: CreateLikeDto = {
entityId: "book123",
entityType: "book",
};
expect(createDto.entityType).toBe("book");
expect(createDto.entityId).toBe("book123");
// Verify it only has these two properties
expect(Object.keys(createDto)).toHaveLength(2);
});
it("should accept different entity types", () => {
const gameDto: CreateLikeDto = {
entityId: "game456",
entityType: "game",
};
const artDto: CreateLikeDto = {
entityId: "art789",
entityType: "art",
};
expect(gameDto.entityType).toBe("game");
expect(artDto.entityType).toBe("art");
});
});
describe("likeCountDto interface", () => {
it("should accept valid like count object", () => {
const likeCount: LikeCountDto = {
count: 42,
entityId: "book123",
entityType: "book",
};
expect(likeCount.count).toBe(42);
expect(likeCount.entityType).toBe("book");
});
it("should accept like counts for different entities", () => {
const gameLikeCount: LikeCountDto = {
count: 15,
entityId: "game456",
entityType: "game",
};
const showLikeCount: LikeCountDto = {
count: 0,
entityId: "show789",
entityType: "show",
};
expect(gameLikeCount.count).toBe(15);
expect(showLikeCount.count).toBe(0);
});
});
describe("likedItemDto interface", () => {
it("should accept liked item with unknown item type", () => {
const likedBook: LikedItemDto = {
item: {
author: "F. Scott Fitzgerald",
id: "book456",
title: "The Great Gatsby",
// ... other book properties
},
like: {
createdAt: new Date("2024-01-15"),
entityId: "book456",
entityType: "book",
id: "like123",
userId: "user123",
},
};
expect(likedBook.like.entityType).toBe("book");
expect(likedBook.item).toBeDefined();
});
it("should accept liked items for different entity types", () => {
const likedGame: LikedItemDto = {
item: {
id: "game123",
platform: "Nintendo Switch",
title: "Hades",
// ... other game properties
},
like: {
createdAt: new Date("2024-02-01"),
entityId: "game123",
entityType: "game",
id: "like456",
userId: "user789",
},
};
const likedArt: LikedItemDto = {
item: {
artist: "Jane Doe",
id: "art456",
imageUrl: "https://example.com/sunset.jpg",
title: "Beautiful Sunset",
// ... other art properties
},
like: {
createdAt: new Date("2024-02-10"),
entityId: "art456",
entityType: "art",
id: "like789",
userId: "user999",
},
};
expect(likedGame.like.entityType).toBe("game");
expect(likedArt.like.entityType).toBe("art");
});
});
describe("likeResponse interface", () => {
it("should accept response with liked true", () => {
const likedResponse: LikeResponse = {
count: 10,
liked: true,
};
expect(likedResponse.liked).toBeTruthy();
expect(likedResponse.count).toBe(10);
});
it("should accept response with liked false", () => {
const notLikedResponse: LikeResponse = {
count: 5,
liked: false,
};
expect(notLikedResponse.liked).toBeFalsy();
expect(notLikedResponse.count).toBe(5);
});
it("should accept response with zero count", () => {
const zeroResponse: LikeResponse = {
count: 0,
liked: false,
};
expect(zeroResponse.liked).toBeFalsy();
expect(zeroResponse.count).toBe(0);
});
});
});
+172
View File
@@ -0,0 +1,172 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { MangaStatus } from "../src/lib/manga.types";
import type { Manga, CreateMangaDto, UpdateMangaDto } from "../src/lib/manga.types";
describe("manga Types", () => {
describe("mangaStatus enum", () => {
it("should have the correct values", () => {
expect(MangaStatus.reading).toBe("READING");
expect(MangaStatus.completed).toBe("COMPLETED");
expect(MangaStatus.wantToRead).toBe("WANT_TO_READ");
});
it("should have all expected enum values", () => {
const values = Object.values(MangaStatus);
expect(values).toHaveLength(3);
expect(values).toContain("READING");
expect(values).toContain("COMPLETED");
expect(values).toContain("WANT_TO_READ");
});
});
describe("manga interface", () => {
it("should accept valid manga object with minimal fields", () => {
const manga: Manga = {
author: "Tsugumi Ohba",
createdAt: new Date("2024-01-15"),
dateAdded: new Date("2024-01-15"),
id: "manga123",
links: [],
status: MangaStatus.reading,
tags: [],
title: "Death Note",
updatedAt: new Date("2024-01-16"),
};
expect(manga.dateCompleted).toBeUndefined();
expect(manga.rating).toBeUndefined();
expect(manga.notes).toBeUndefined();
expect(manga.coverImage).toBeUndefined();
});
it("should accept valid manga object with all fields", () => {
const fullManga: Manga = {
author: "Eiichiro Oda",
coverImage: "https://example.com/onepiece-cover.jpg",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
dateCompleted: undefined,
id: "manga456",
links: [
{ title: "MyAnimeList", url: "https://myanimelist.net/manga/13" },
{ title: "Official Site", url: "https://one-piece.com" },
],
notes: "Epic adventure that keeps getting better",
// Still ongoing
rating: 5,
status: MangaStatus.reading,
tags: [ "adventure", "shounen", "pirates", "long-running" ],
title: "One Piece",
updatedAt: new Date("2024-02-01"),
};
expect(fullManga.author).toBe("Eiichiro Oda");
expect(fullManga.rating).toBe(5);
expect(fullManga.tags).toHaveLength(4);
expect(fullManga.links).toHaveLength(2);
});
it("should accept completed manga", () => {
const completedManga: Manga = {
author: "Hiromu Arakawa",
coverImage: "https://example.com/fma-cover.jpg",
createdAt: new Date("2023-12-01"),
dateAdded: new Date("2023-12-01"),
dateCompleted: new Date("2024-01-30"),
id: "manga789",
links: [],
notes: "Perfect from start to finish",
rating: 5,
status: MangaStatus.completed,
tags: [ "shounen", "adventure", "alchemy" ],
title: "Fullmetal Alchemist",
updatedAt: new Date("2024-01-30"),
};
expect(completedManga.status).toBe(MangaStatus.completed);
expect(completedManga.dateCompleted).toEqual(new Date("2024-01-30"));
});
});
describe("createMangaDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateMangaDto = {
author: "Hajime Isayama",
status: MangaStatus.wantToRead,
title: "Attack on Titan",
};
expect(createDto.rating).toBeUndefined();
expect(createDto.notes).toBeUndefined();
expect(createDto.coverImage).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateMangaDto = {
author: "Kohei Horikoshi",
coverImage: "https://example.com/mha-cover.jpg",
links: [ { title: "Wiki", url: "https://mha.wiki" } ],
notes: "Great superhero manga with unique powers",
rating: 4,
status: MangaStatus.reading,
tags: [ "shounen", "superhero", "school" ],
title: "My Hero Academia",
};
expect(fullCreateDto.author).toBe("Kohei Horikoshi");
expect(fullCreateDto.rating).toBe(4);
expect(fullCreateDto.tags).toEqual([ "shounen", "superhero", "school" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateMangaDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateMangaDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates including dateCompleted", () => {
const partialUpdate: UpdateMangaDto = {
dateCompleted: new Date("2024-02-10"),
rating: 4,
status: MangaStatus.completed,
};
expect(partialUpdate.status).toBe(MangaStatus.completed);
expect(partialUpdate.dateCompleted).toEqual(new Date("2024-02-10"));
expect(partialUpdate.rating).toBe(4);
expect(partialUpdate.title).toBeUndefined();
});
it("should accept full update", () => {
const fullUpdate: UpdateMangaDto = {
author: "Different Author",
coverImage: "https://example.com/new-manga-cover.jpg",
dateCompleted: new Date("2024-02-15"),
links: [ { title: "New Link", url: "https://newlink.com" } ],
notes: "Updated after finishing the series",
rating: 3,
status: MangaStatus.completed,
tags: [ "updated", "tags" ],
title: "Updated Manga Title",
};
expect(fullUpdate.title).toBe("Updated Manga Title");
expect(fullUpdate.author).toBe("Different Author");
expect(fullUpdate.dateCompleted).toEqual(new Date("2024-02-15"));
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+200
View File
@@ -0,0 +1,200 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { MusicStatus, MusicType } from "../src/lib/music.types";
import type { Music, CreateMusicDto, UpdateMusicDto } from "../src/lib/music.types";
describe("music Types", () => {
describe("musicType enum", () => {
it("should have the correct values", () => {
expect(MusicType.album).toBe("ALBUM");
expect(MusicType.single).toBe("SINGLE");
expect(MusicType.ep).toBe("EP");
});
it("should have all expected enum values", () => {
const values = Object.values(MusicType);
expect(values).toHaveLength(3);
expect(values).toContain("ALBUM");
expect(values).toContain("SINGLE");
expect(values).toContain("EP");
});
});
describe("musicStatus enum", () => {
it("should have the correct values", () => {
expect(MusicStatus.listening).toBe("LISTENING");
expect(MusicStatus.completed).toBe("COMPLETED");
expect(MusicStatus.wantToListen).toBe("WANT_TO_LISTEN");
});
it("should have all expected enum values", () => {
const values = Object.values(MusicStatus);
expect(values).toHaveLength(3);
expect(values).toContain("LISTENING");
expect(values).toContain("COMPLETED");
expect(values).toContain("WANT_TO_LISTEN");
});
});
describe("music interface", () => {
it("should accept valid music object with minimal fields", () => {
const music: Music = {
artist: "Pink Floyd",
createdAt: new Date("2024-01-15"),
dateAdded: new Date("2024-01-15"),
id: "music123",
links: [],
status: MusicStatus.listening,
tags: [],
title: "Dark Side of the Moon",
type: MusicType.album,
updatedAt: new Date("2024-01-16"),
};
expect(music.dateCompleted).toBeUndefined();
expect(music.rating).toBeUndefined();
expect(music.notes).toBeUndefined();
expect(music.coverArt).toBeUndefined();
});
it("should accept valid music object with all fields", () => {
const fullMusic: Music = {
artist: "Pink Floyd",
coverArt: "https://example.com/the-wall-cover.jpg",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
dateCompleted: new Date("2024-01-20"),
id: "music456",
links: [
{ title: "Spotify", url: "https://spotify.com/album/the-wall" },
{ title: "Apple Music", url: "https://music.apple.com/album/the-wall" },
],
notes: "A rock opera masterpiece",
rating: 5,
status: MusicStatus.completed,
tags: [ "progressive rock", "concept album", "classic" ],
title: "The Wall",
type: MusicType.album,
updatedAt: new Date("2024-01-20"),
};
expect(fullMusic.artist).toBe("Pink Floyd");
expect(fullMusic.rating).toBe(5);
expect(fullMusic.tags).toHaveLength(3);
expect(fullMusic.links).toHaveLength(2);
});
it("should accept different music types", () => {
const single: Music = {
artist: "The Weeknd",
createdAt: new Date("2024-02-01"),
dateAdded: new Date("2024-02-01"),
id: "music789",
links: [],
status: MusicStatus.completed,
tags: [ "pop", "synthwave" ],
title: "Blinding Lights",
type: MusicType.single,
updatedAt: new Date("2024-02-01"),
};
const ep: Music = {
artist: "The Weeknd",
createdAt: new Date("2024-02-05"),
dateAdded: new Date("2024-02-05"),
id: "music999",
links: [],
status: MusicStatus.wantToListen,
tags: [ "r&b", "dark" ],
title: "My Dear Melancholy,",
type: MusicType.ep,
updatedAt: new Date("2024-02-05"),
};
expect(single.type).toBe(MusicType.single);
expect(ep.type).toBe(MusicType.ep);
});
});
describe("createMusicDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateMusicDto = {
artist: "Fleetwood Mac",
status: MusicStatus.wantToListen,
title: "Rumours",
type: MusicType.album,
};
expect(createDto.rating).toBeUndefined();
expect(createDto.notes).toBeUndefined();
expect(createDto.coverArt).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateMusicDto = {
artist: "The Weeknd",
coverArt: "https://example.com/after-hours.jpg",
links: [ { title: "YouTube", url: "https://youtube.com/album/after-hours" } ],
notes: "Dark synthwave vibes",
rating: 4,
status: MusicStatus.listening,
tags: [ "synthwave", "pop", "r&b" ],
title: "After Hours",
type: MusicType.album,
};
expect(fullCreateDto.artist).toBe("The Weeknd");
expect(fullCreateDto.type).toBe(MusicType.album);
expect(fullCreateDto.rating).toBe(4);
expect(fullCreateDto.tags).toEqual([ "synthwave", "pop", "r&b" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateMusicDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateMusicDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates including dateCompleted", () => {
const partialUpdate: UpdateMusicDto = {
dateCompleted: new Date("2024-02-10"),
rating: 5,
status: MusicStatus.completed,
};
expect(partialUpdate.status).toBe(MusicStatus.completed);
expect(partialUpdate.dateCompleted).toEqual(new Date("2024-02-10"));
expect(partialUpdate.rating).toBe(5);
expect(partialUpdate.title).toBeUndefined();
});
it("should accept full update", () => {
const fullUpdate: UpdateMusicDto = {
artist: "Different Artist",
coverArt: "https://example.com/new-cover.jpg",
dateCompleted: new Date("2024-02-15"),
links: [ { title: "New Link", url: "https://newlink.com" } ],
notes: "Updated after listening",
rating: 3,
status: MusicStatus.completed,
tags: [ "updated", "tags" ],
title: "Updated Album Title",
type: MusicType.ep,
};
expect(fullUpdate.title).toBe("Updated Album Title");
expect(fullUpdate.artist).toBe("Different Artist");
expect(fullUpdate.type).toBe(MusicType.ep);
expect(fullUpdate.dateCompleted).toEqual(new Date("2024-02-15"));
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+194
View File
@@ -0,0 +1,194 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { ShowStatus, ShowType } from "../src/lib/show.types";
import type { Show, CreateShowDto, UpdateShowDto } from "../src/lib/show.types";
describe("show Types", () => {
describe("showType enum", () => {
it("should have the correct values", () => {
expect(ShowType.tvSeries).toBe("TV_SERIES");
expect(ShowType.anime).toBe("ANIME");
expect(ShowType.film).toBe("FILM");
expect(ShowType.documentary).toBe("DOCUMENTARY");
});
it("should have all expected enum values", () => {
const values = Object.values(ShowType);
expect(values).toHaveLength(4);
expect(values).toContain("TV_SERIES");
expect(values).toContain("ANIME");
expect(values).toContain("FILM");
expect(values).toContain("DOCUMENTARY");
});
});
describe("showStatus enum", () => {
it("should have the correct values", () => {
expect(ShowStatus.watching).toBe("WATCHING");
expect(ShowStatus.completed).toBe("COMPLETED");
expect(ShowStatus.wantToWatch).toBe("WANT_TO_WATCH");
});
it("should have all expected enum values", () => {
const values = Object.values(ShowStatus);
expect(values).toHaveLength(3);
expect(values).toContain("WATCHING");
expect(values).toContain("COMPLETED");
expect(values).toContain("WANT_TO_WATCH");
});
});
describe("show interface", () => {
it("should accept valid show object with minimal fields", () => {
const show: Show = {
createdAt: new Date("2024-01-15"),
dateAdded: new Date("2024-01-15"),
id: "show123",
links: [],
status: ShowStatus.watching,
tags: [],
title: "Breaking Bad",
type: ShowType.tvSeries,
updatedAt: new Date("2024-01-16"),
};
expect(show.dateCompleted).toBeUndefined();
expect(show.rating).toBeUndefined();
expect(show.notes).toBeUndefined();
expect(show.coverImage).toBeUndefined();
});
it("should accept valid show object with all fields", () => {
const fullShow: Show = {
coverImage: "https://example.com/aot-cover.jpg",
createdAt: new Date("2024-01-01"),
dateAdded: new Date("2024-01-01"),
dateCompleted: new Date("2024-01-20"),
id: "show456",
links: [
{ title: "MyAnimeList", url: "https://myanimelist.net/anime/16498" },
{ title: "Crunchyroll", url: "https://crunchyroll.com/attack-on-titan" },
],
notes: "Incredible story with amazing animation",
rating: 5,
status: ShowStatus.completed,
tags: [ "action", "dark fantasy", "shounen" ],
title: "Attack on Titan",
type: ShowType.anime,
updatedAt: new Date("2024-01-20"),
};
expect(fullShow.type).toBe(ShowType.anime);
expect(fullShow.rating).toBe(5);
expect(fullShow.tags).toHaveLength(3);
expect(fullShow.links).toHaveLength(2);
});
it("should accept different show types", () => {
const film: Show = {
createdAt: new Date("2024-02-01"),
dateAdded: new Date("2024-02-01"),
id: "show789",
links: [],
rating: 5,
status: ShowStatus.completed,
tags: [ "sci-fi", "thriller" ],
title: "Inception",
type: ShowType.film,
updatedAt: new Date("2024-02-01"),
};
const documentary: Show = {
createdAt: new Date("2024-02-05"),
dateAdded: new Date("2024-02-05"),
id: "show999",
links: [],
status: ShowStatus.wantToWatch,
tags: [ "nature", "wildlife" ],
title: "Planet Earth II",
type: ShowType.documentary,
updatedAt: new Date("2024-02-05"),
};
expect(film.type).toBe(ShowType.film);
expect(documentary.type).toBe(ShowType.documentary);
});
});
describe("createShowDto interface", () => {
it("should accept DTO with required fields only", () => {
const createDto: CreateShowDto = {
status: ShowStatus.wantToWatch,
title: "Stranger Things",
type: ShowType.tvSeries,
};
expect(createDto.rating).toBeUndefined();
expect(createDto.notes).toBeUndefined();
expect(createDto.coverImage).toBeUndefined();
expect(createDto.tags).toBeUndefined();
expect(createDto.links).toBeUndefined();
});
it("should accept DTO with all fields", () => {
const fullCreateDto: CreateShowDto = {
coverImage: "https://example.com/death-note.jpg",
links: [ { title: "Netflix", url: "https://netflix.com/death-note" } ],
notes: "Psychological thriller with great plot",
rating: 4,
status: ShowStatus.watching,
tags: [ "psychological", "thriller", "supernatural" ],
title: "Death Note",
type: ShowType.anime,
};
expect(fullCreateDto.type).toBe(ShowType.anime);
expect(fullCreateDto.rating).toBe(4);
expect(fullCreateDto.tags).toEqual([ "psychological", "thriller", "supernatural" ]);
expect(fullCreateDto.links).toHaveLength(1);
});
});
describe("updateShowDto type", () => {
it("should accept empty update DTO", () => {
const emptyUpdate: UpdateShowDto = {};
expect(emptyUpdate).toEqual({});
});
it("should accept partial updates including dateCompleted", () => {
const partialUpdate: UpdateShowDto = {
dateCompleted: new Date("2024-02-10"),
rating: 5,
status: ShowStatus.completed,
};
expect(partialUpdate.status).toBe(ShowStatus.completed);
expect(partialUpdate.dateCompleted).toEqual(new Date("2024-02-10"));
expect(partialUpdate.rating).toBe(5);
expect(partialUpdate.title).toBeUndefined();
});
it("should accept full update", () => {
const fullUpdate: UpdateShowDto = {
coverImage: "https://example.com/new-show-cover.jpg",
dateCompleted: new Date("2024-02-15"),
links: [ { title: "New Link", url: "https://newlink.com" } ],
notes: "Updated after watching",
rating: 3,
status: ShowStatus.completed,
tags: [ "updated", "tags" ],
title: "Updated Show Title",
type: ShowType.documentary,
};
expect(fullUpdate.title).toBe("Updated Show Title");
expect(fullUpdate.type).toBe(ShowType.documentary);
expect(fullUpdate.dateCompleted).toEqual(new Date("2024-02-15"));
expect(fullUpdate.links).toHaveLength(1);
});
});
});
+440
View File
@@ -0,0 +1,440 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { GameStatus, BookStatus, MangaStatus, MusicStatus, MusicType, ShowStatus, ShowType } from "../src";
import { SuggestionEntity, SuggestionStatus } from "../src/lib/suggestion.types";
import type {
Suggestion,
SuggestionUser,
CreateSuggestionDto,
DeclineSuggestionDto,
CreateGameSuggestionDto,
CreateBookSuggestionDto,
CreateMusicSuggestionDto,
CreateArtSuggestionDto,
CreateShowSuggestionDto,
CreateMangaSuggestionDto,
AcceptWithEditsDto,
} from "../src/lib/suggestion.types";
describe("suggestion Types", () => {
describe("suggestionEntity enum", () => {
it("should have the correct values", () => {
expect(SuggestionEntity.game).toBe("GAME");
expect(SuggestionEntity.book).toBe("BOOK");
expect(SuggestionEntity.music).toBe("MUSIC");
expect(SuggestionEntity.art).toBe("ART");
expect(SuggestionEntity.show).toBe("SHOW");
expect(SuggestionEntity.manga).toBe("MANGA");
});
it("should have all expected enum values", () => {
const values = Object.values(SuggestionEntity);
expect(values).toHaveLength(6);
expect(values).toContain("GAME");
expect(values).toContain("BOOK");
expect(values).toContain("MUSIC");
expect(values).toContain("ART");
expect(values).toContain("SHOW");
expect(values).toContain("MANGA");
});
});
describe("suggestionStatus enum", () => {
it("should have the correct values", () => {
expect(SuggestionStatus.unreviewed).toBe("UNREVIEWED");
expect(SuggestionStatus.accepted).toBe("ACCEPTED");
expect(SuggestionStatus.declined).toBe("DECLINED");
});
it("should have all expected enum values", () => {
const values = Object.values(SuggestionStatus);
expect(values).toHaveLength(3);
expect(values).toContain("UNREVIEWED");
expect(values).toContain("ACCEPTED");
expect(values).toContain("DECLINED");
});
});
describe("suggestionUser interface", () => {
it("should accept valid user object", () => {
const user: SuggestionUser = {
avatar: "https://example.com/avatar.png",
id: "user123",
inDiscord: true,
isMod: false,
isStaff: false,
isVip: false,
username: "suggester",
};
expect(user.inDiscord).toBeTruthy();
expect(user.isVip).toBeFalsy();
});
it("should accept user without avatar", () => {
const user: SuggestionUser = {
id: "user456",
inDiscord: true,
isMod: false,
isStaff: true,
isVip: true,
username: "vipuser",
};
expect(user.avatar).toBeUndefined();
expect(user.isVip).toBeTruthy();
expect(user.isStaff).toBeTruthy();
});
});
describe("suggestion interface", () => {
it("should accept game suggestion", () => {
const gameSuggestion: Suggestion = {
createdAt: new Date("2024-01-15"),
entityType: SuggestionEntity.game,
gameData: {
coverImage: "https://example.com/hades.jpg",
notes: "Amazing roguelike",
platform: "Nintendo Switch",
status: GameStatus.backlog,
title: "Hades",
},
id: "sug123",
status: SuggestionStatus.unreviewed,
title: "Hades",
updatedAt: new Date("2024-01-15"),
user: {
id: "user123",
inDiscord: true,
isMod: false,
isStaff: false,
isVip: false,
username: "gamer",
},
userId: "user123",
};
expect(gameSuggestion.entityType).toBe(SuggestionEntity.game);
expect(gameSuggestion.gameData).toBeDefined();
expect(gameSuggestion.bookData).toBeUndefined();
});
it("should accept book suggestion", () => {
const bookSuggestion: Suggestion = {
bookData: {
author: "George Orwell",
isbn: "978-0-452-28423-4",
notes: "Dystopian classic",
status: BookStatus.toRead,
title: "1984",
},
createdAt: new Date("2024-01-20"),
entityType: SuggestionEntity.book,
id: "sug456",
status: SuggestionStatus.accepted,
title: "1984",
updatedAt: new Date("2024-01-21"),
user: {
id: "user456",
inDiscord: false,
isMod: false,
isStaff: false,
isVip: true,
username: "reader",
},
userId: "user456",
};
expect(bookSuggestion.entityType).toBe(SuggestionEntity.book);
expect(bookSuggestion.bookData).toBeDefined();
expect(bookSuggestion.gameData).toBeUndefined();
});
it("should accept declined suggestion with reason", () => {
const declinedSuggestion: Suggestion = {
createdAt: new Date("2024-02-01"),
declineReason: "Already in the library",
entityType: SuggestionEntity.music,
id: "sug789",
musicData: {
artist: "Pink Floyd",
status: MusicStatus.wantToListen,
title: "Dark Side of the Moon",
type: MusicType.album,
},
status: SuggestionStatus.declined,
title: "Dark Side of the Moon",
updatedAt: new Date("2024-02-02"),
user: {
id: "user789",
inDiscord: true,
isMod: false,
isStaff: false,
isVip: false,
username: "suggester",
},
userId: "user789",
};
expect(declinedSuggestion.status).toBe(SuggestionStatus.declined);
expect(declinedSuggestion.declineReason).toBe("Already in the library");
});
it("should accept art suggestion", () => {
const artSuggestion: Suggestion = {
artData: {
artist: "Jane Doe",
description: "A stunning sunset painting",
imageUrl: "https://example.com/sunset.jpg",
title: "Beautiful Sunset",
},
createdAt: new Date("2024-02-10"),
entityType: SuggestionEntity.art,
id: "sug999",
status: SuggestionStatus.unreviewed,
title: "Beautiful Sunset",
updatedAt: new Date("2024-02-10"),
user: {
id: "user999",
inDiscord: true,
isMod: true,
isStaff: false,
isVip: false,
username: "artlover",
},
userId: "user999",
};
expect(artSuggestion.entityType).toBe(SuggestionEntity.art);
expect(artSuggestion.artData).toBeDefined();
});
it("should accept show and manga suggestions", () => {
const showSuggestion: Suggestion = {
createdAt: new Date("2024-02-15"),
entityType: SuggestionEntity.show,
id: "sug111",
showData: {
status: ShowStatus.wantToWatch,
title: "Breaking Bad",
type: ShowType.tvSeries,
},
status: SuggestionStatus.unreviewed,
title: "Breaking Bad",
updatedAt: new Date("2024-02-15"),
user: {
id: "user111",
inDiscord: false,
isMod: false,
isStaff: true,
isVip: false,
username: "tvfan",
},
userId: "user111",
};
const mangaSuggestion: Suggestion = {
createdAt: new Date("2024-02-20"),
entityType: SuggestionEntity.manga,
id: "sug222",
mangaData: {
author: "Eiichiro Oda",
status: MangaStatus.reading,
title: "One Piece",
},
status: SuggestionStatus.accepted,
title: "One Piece",
updatedAt: new Date("2024-02-21"),
user: {
id: "user222",
inDiscord: true,
isMod: true,
isStaff: true,
isVip: true,
username: "mangareader",
},
userId: "user222",
};
expect(showSuggestion.entityType).toBe(SuggestionEntity.show);
expect(mangaSuggestion.entityType).toBe(SuggestionEntity.manga);
});
});
describe("createSuggestionDto types", () => {
it("should accept game suggestion DTO", () => {
const gameDto: CreateGameSuggestionDto = {
coverImage: "https://example.com/hollow.jpg",
entityType: SuggestionEntity.game,
notes: "Great metroidvania",
platform: "PC",
title: "Hollow Knight",
};
expect(gameDto.entityType).toBe(SuggestionEntity.game);
expect(gameDto.platform).toBe("PC");
});
it("should accept book suggestion DTO", () => {
const bookDto: CreateBookSuggestionDto = {
author: "J.R.R. Tolkien",
coverImage: "https://example.com/hobbit.jpg",
entityType: SuggestionEntity.book,
isbn: "978-0-547-92822-7",
notes: "Fantasy classic",
title: "The Hobbit",
};
expect(bookDto.entityType).toBe(SuggestionEntity.book);
expect(bookDto.author).toBe("J.R.R. Tolkien");
});
it("should accept music suggestion DTO", () => {
const musicDto: CreateMusicSuggestionDto = {
artist: "Pink Floyd",
coverArt: "https://example.com/wall.jpg",
entityType: SuggestionEntity.music,
notes: "Rock opera",
title: "The Wall",
type: "ALBUM",
};
expect(musicDto.entityType).toBe(SuggestionEntity.music);
expect(musicDto.type).toBe("ALBUM");
});
it("should accept art suggestion DTO", () => {
const artDto: CreateArtSuggestionDto = {
artist: "Vincent van Gogh",
description: "Famous painting",
entityType: SuggestionEntity.art,
imageUrl: "https://example.com/starry.jpg",
title: "Starry Night",
};
expect(artDto.entityType).toBe(SuggestionEntity.art);
expect(artDto.imageUrl).toBe("https://example.com/starry.jpg");
});
it("should accept show suggestion DTO", () => {
const showDto: CreateShowSuggestionDto = {
coverImage: "https://example.com/office.jpg",
entityType: SuggestionEntity.show,
notes: "Comedy series",
title: "The Office",
type: "TV_SERIES",
};
expect(showDto.entityType).toBe(SuggestionEntity.show);
expect(showDto.type).toBe("TV_SERIES");
});
it("should accept manga suggestion DTO", () => {
const mangaDto: CreateMangaSuggestionDto = {
author: "Tsugumi Ohba",
coverImage: "https://example.com/deathnote.jpg",
entityType: SuggestionEntity.manga,
notes: "Psychological thriller",
title: "Death Note",
};
expect(mangaDto.entityType).toBe(SuggestionEntity.manga);
expect(mangaDto.author).toBe("Tsugumi Ohba");
});
it("should work with union type", () => {
const suggestions: Array<CreateSuggestionDto> = [
{
entityType: SuggestionEntity.game,
title: "Game Title",
},
{
author: "Author Name",
entityType: SuggestionEntity.book,
title: "Book Title",
},
];
expect(suggestions).toHaveLength(2);
expect(suggestions[0].entityType).toBe(SuggestionEntity.game);
expect(suggestions[1].entityType).toBe(SuggestionEntity.book);
});
});
describe("declineSuggestionDto interface", () => {
it("should accept empty decline DTO", () => {
const declineDto: DeclineSuggestionDto = {};
expect(declineDto.reason).toBeUndefined();
});
it("should accept decline DTO with reason", () => {
const declineDto: DeclineSuggestionDto = {
reason: "Already exists in the library",
};
expect(declineDto.reason).toBe("Already exists in the library");
});
});
describe("acceptWithEditsDto interface", () => {
it("should accept empty edits DTO", () => {
const editsDto: AcceptWithEditsDto = {};
expect(editsDto).toEqual({});
});
it("should accept edits for book fields", () => {
const editsDto: AcceptWithEditsDto = {
author: "Corrected Author",
coverImage: "https://example.com/new-cover.jpg",
isbn: "978-0-123-45678-9",
links: [ { label: "Goodreads", url: "https://goodreads.com" } ],
notes: "Updated notes",
tags: [ "fiction", "classic" ],
title: "Corrected Title",
};
expect(editsDto.title).toBe("Corrected Title");
expect(editsDto.author).toBe("Corrected Author");
expect(editsDto.tags).toHaveLength(2);
});
it("should accept edits for music fields", () => {
const editsDto: AcceptWithEditsDto = {
artist: "Artist Name",
coverArt: "https://example.com/album.jpg",
title: "Album Title",
type: "ALBUM",
};
expect(editsDto.artist).toBe("Artist Name");
expect(editsDto.type).toBe("ALBUM");
expect(editsDto.coverArt).toBe("https://example.com/album.jpg");
});
it("should accept edits for game fields", () => {
const editsDto: AcceptWithEditsDto = {
coverImage: "https://example.com/game.jpg",
notes: "Action RPG",
platform: "PlayStation 5",
title: "Game Title",
};
expect(editsDto.platform).toBe("PlayStation 5");
});
it("should accept edits for art fields", () => {
const editsDto: AcceptWithEditsDto = {
artist: "Artist Name",
description: "Beautiful artwork",
imageUrl: "https://example.com/art.jpg",
title: "Art Title",
};
expect(editsDto.description).toBe("Beautiful artwork");
expect(editsDto.imageUrl).toBe("https://example.com/art.jpg");
});
});
});