Skip to content

Commit

Permalink
ソーステクストをnumberとpageIdでuniqueにした (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttizze authored Sep 29, 2024
2 parents 48a04a7 + f71bbdd commit d331f35
Show file tree
Hide file tree
Showing 30 changed files with 537 additions and 286 deletions.
98 changes: 0 additions & 98 deletions .github/workflows/create-branch-on-issue-assign.yml

This file was deleted.

14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ services:
volumes:
- db:/var/lib/postgresql/data

test_db:
image: postgres:16
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgres
ports:
- '5433:5432'
volumes:
- test_db:/var/lib/postgresql/data

redis:
image: redis:6.2-alpine
restart: always
Expand Down Expand Up @@ -49,6 +61,8 @@ services:
volumes:
db:
driver: local
test_db:
driver: local
redis:
driver: local
minio_data:
Expand Down
1 change: 0 additions & 1 deletion web/app/features/translate/functions/mutations.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export async function getLatestSourceTexts(pageId: number) {
orderBy: {
createdAt: "desc",
},
distinct: ["number"],
select: {
id: true,
number: true,
Expand Down
18 changes: 9 additions & 9 deletions web/app/routes/$userName+/functions/queries.server.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { prisma } from "~/utils/prisma";
import { sanitizeUser } from "~/utils/sanitizeUser";
import type { PageListItem, sanitizedUserWithPages } from "../types";

export async function fetchSanitizedUserWithPages(
userName: string,
isOwnProfile: boolean,
): Promise<sanitizedUserWithPages | null> {
) {
const user = await prisma.user.findUnique({
where: { userName },
include: {
pages: {
select: {
id: true,
title: true,
slug: true,
isPublished: true,
createdAt: true,
include: {
sourceTexts: {
where: {
number: 0,
},
},
},
where: {
isArchived: false,
Expand All @@ -28,8 +27,9 @@ export async function fetchSanitizedUserWithPages(

if (!user) return null;

const pages: PageListItem[] = user.pages.map((page) => ({
const pages = user.pages.map((page) => ({
...page,
title: page.sourceTexts.filter((item) => item.number === 0)[0].text,
}));
return {
...sanitizeUser(user),
Expand Down
32 changes: 23 additions & 9 deletions web/app/routes/$userName+/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,37 @@ describe("UserProfile", () => {
pages: {
create: [
{
title: "Public Page",
slug: "public-page",
isPublished: true,
content: "This is a test content",
sourceTexts: {
create: {
number: 0,
text: "Public Page",
},
},
},
{
title: "Private Page",
slug: "private-page",
isPublished: false,
content: "This is a test content2",
sourceTexts: {
create: {
number: 0,
text: "Private Page",
},
},
},
{
title: "Archived Page",
slug: "archived-page",
isArchived: true,
content: "This is a test content3",
sourceTexts: {
create: {
number: 0,
text: "Archived Page",
},
},
},
],
},
Expand Down Expand Up @@ -124,17 +139,16 @@ describe("UserProfile", () => {

const menuButtons = await screen.findAllByLabelText("More options");
expect(menuButtons.length).toBeGreaterThan(0);

await userEvent.click(menuButtons[0]);

expect(await screen.findByText("Edit")).toBeInTheDocument();
expect(await screen.findByText("Make Private")).toBeInTheDocument();
await userEvent.click(await screen.findByText("Make Private"));

waitFor(() => {
userEvent.click(menuButtons[0]);
expect(screen.findByText("Make Public")).toBeInTheDocument();
});
// const menuButtons2 = await screen.findAllByLabelText("More options");
// expect(menuButtons2.length).toBeGreaterThan(0);
// await userEvent.click(menuButtons2[0]);
// await screen.debug();
// expect(await screen.findByText("Make Public")).toBeInTheDocument();
});

test("action handles archive correctly", async () => {
Expand Down
1 change: 1 addition & 0 deletions web/app/routes/$userName+/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
isOwner,
);
if (!sanitizedUserWithPages) throw new Response("Not Found", { status: 404 });

const pageCreatedAt = new Date(
sanitizedUserWithPages.createdAt,
).toLocaleDateString();
Expand Down
Loading

0 comments on commit d331f35

Please sign in to comment.