-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from sora32127/commnet_feed
フィードページの改修
- Loading branch information
Showing
4 changed files
with
395 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,111 @@ | ||
import { expect, test } from "vitest"; | ||
import { ArchiveDataEntry } from "./db.server"; | ||
import { ArchiveDataEntry, getFeedPosts, getNewestPostIdsForTest, getOldestPostIdsForTest, getUnboundedLikesPostIdsForTest, PostCardDataSchema } from "./db.server"; | ||
import { describe } from "node:test"; | ||
|
||
|
||
test("記事ID23576の正しいデータを返すこと", async () => { | ||
const archiveDataEntry = await ArchiveDataEntry.getData(23576); | ||
expect(archiveDataEntry.postId).toBe(23576); | ||
expect(archiveDataEntry.postTitle).toBe('無神論者の火'); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: 'クリスマス', tagId: 381 }); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: '学生', tagId: 21 }); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: '小学生', tagId: 35 }); | ||
expect(archiveDataEntry.countLikes).toBeGreaterThan(30); | ||
expect(archiveDataEntry.countDislikes).toBeGreaterThan(5); | ||
expect(archiveDataEntry.postDateGmt).toEqual(new Date('2023-02-11T05:57:26.000Z')); | ||
expect(archiveDataEntry.postContent).not.toBe(''); | ||
expect(archiveDataEntry.similarPosts).toHaveLength(15); | ||
expect(archiveDataEntry.previousPost.postTitle).toBe('無知識でアナルにローターを入れるべきでは無い'); | ||
expect(archiveDataEntry.nextPost.postTitle).toBe('無能が消去法で大学を決めるべきではない'); | ||
describe("記事ID23576の正しいデータを返すこと", async () => { | ||
test("記事ID23576の正しいデータを返すこと", async () => { | ||
const archiveDataEntry = await ArchiveDataEntry.getData(23576); | ||
expect(archiveDataEntry.postId).toBe(23576); | ||
expect(archiveDataEntry.postTitle).toBe('無神論者の火'); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: 'クリスマス', tagId: 381 }); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: '学生', tagId: 21 }); | ||
expect(archiveDataEntry.tags).toContainEqual({ tagName: '小学生', tagId: 35 }); | ||
expect(archiveDataEntry.countLikes).toBeGreaterThan(30); | ||
expect(archiveDataEntry.countDislikes).toBeGreaterThan(5); | ||
expect(archiveDataEntry.postDateGmt).toEqual(new Date('2023-02-11T05:57:26.000Z')); | ||
expect(archiveDataEntry.postContent).not.toBe(''); | ||
expect(archiveDataEntry.similarPosts).toHaveLength(15); | ||
expect(archiveDataEntry.previousPost.postTitle).toBe('無知識でアナルにローターを入れるべきでは無い'); | ||
expect(archiveDataEntry.nextPost.postTitle).toBe('無能が消去法で大学を決めるべきではない'); | ||
}) | ||
}); | ||
|
||
describe("getFeedPostsが正しいデータを返すこと", async () => { | ||
const likeFromHour = 0; | ||
const likeToHour = 24; | ||
const chunkSize = 12; | ||
describe("古い順の場合", async () => { | ||
test("古い順, 1ページ目", async () => { | ||
const oldestPostIds = await getOldestPostIdsForTest(chunkSize); | ||
const pagingNumber = 1; | ||
const type = "timeAsc"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.meta.totalCount).toBeGreaterThan(9000); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(oldestPostIds[i]); | ||
} | ||
}) | ||
test("古い順, 2ページ目", async () => { | ||
const oldestPostIds = await getOldestPostIdsForTest(chunkSize); | ||
const pagingNumber = 2; | ||
const type = "timeAsc"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(oldestPostIds[i+chunkSize]); | ||
} | ||
}) | ||
}) | ||
|
||
describe("新着順の場合", async () => { | ||
test("新着順, 1ページ目", async () => { | ||
const newestPostIds = await getNewestPostIdsForTest(chunkSize); | ||
const pagingNumber = 1; | ||
const type = "timeDesc"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(newestPostIds[i]); | ||
} | ||
}) | ||
test("新着順, 2ページ目", async () => { | ||
const newestPostIds = await getNewestPostIdsForTest(chunkSize); | ||
const pagingNumber = 2; | ||
const type = "timeDesc"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(newestPostIds[i+chunkSize]); | ||
} | ||
}) | ||
}) | ||
describe("いいね順の場合", async () => { | ||
test("いいね順, 1ページ目", async () => { | ||
const pagingNumber = 1; | ||
const type = "likes"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result.length).toBeGreaterThan(0); | ||
// 時間によって違うのでテストが難しい | ||
}) | ||
}) | ||
describe("無期限いいね順の場合", async () => { | ||
test("無期限いいね順, 1ページ目", async () => { | ||
const unboundedLikesPostIds = await getUnboundedLikesPostIdsForTest(chunkSize); | ||
const pagingNumber = 1; | ||
const type = "unboundedLikes"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(unboundedLikesPostIds[i]); | ||
} | ||
}) | ||
test("無期限いいね順, 2ページ目", async () => { | ||
const unboundedLikesPostIds = await getUnboundedLikesPostIdsForTest(chunkSize); | ||
const pagingNumber = 2; | ||
const type = "unboundedLikes"; | ||
const feedPosts = await getFeedPosts(pagingNumber, type, chunkSize); | ||
expect(feedPosts.result).toHaveLength(chunkSize); | ||
for (let i = 0; i < chunkSize; i++) { | ||
const post = PostCardDataSchema.parse(feedPosts.result[i]); | ||
expect(post.postId).toBe(unboundedLikesPostIds[i+chunkSize]); | ||
} | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7f63a9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
healthy-person-emulator-dotorg-kmxg – ./
healthy-person-emulator-dotorg-kmxg-sora32127s-projects.vercel.app
healthy-person-emulator-dotorg-k-git-12b613-sora32127s-projects.vercel.app
healthy-person-emulator.org
healthy-person-emulator-dotorg.vercel.app