Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Bugfix/DEV-107 ] 마이 페이지 구독 정보 조회 api 경로 변경 #172

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
const { result } = renderHook(
() =>
useQuery({
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: "myPage" }),
}),
{ wrapper: createQueryProviderWrapper() },
);
Expand Down Expand Up @@ -76,7 +76,7 @@
);

const user = userEvent.setup();
const emialDayButton = screen.getByRole("button", {

Check failure on line 79 in src/main/components/EmailManagementMenu/EmailManagementMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/main/components/EmailManagementMenu/EmailManagementMenu.test.tsx > 이메일 관련 구독 관리 컴포넌트 테스트 > 이메일 요일 변경하기 테스트

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name "매일 받을래요" Here are the accessible roles: article: Name "": <article class="flex h-[66px] items-center justify-between py-[10px]" /> Name "": <article class="flex h-[66px] items-center justify-between py-[10px]" /> -------------------------------------------------- paragraph: Name "": <p class="sub2-medium" /> Name "": <p class="sub2-medium" /> -------------------------------------------------- button: Name "오전 9시": <button aria-controls="radix-:r6:" aria-expanded="false" aria-haspopup="dialog" class="sub2-medium rounded-lg bg-text-gray3 px-2 py-1" data-state="closed" type="button" /> Name "주말에는 안 받을래요": <button aria-controls="radix-:r9:" aria-expanded="false" aria-haspopup="dialog" class="sub2-medium rounded-lg bg-text-gray3 px-2 py-1" data-state="closed" type="button" /> -------------------------------------------------- Ignored nodes: comments, script, style <body style="" > <div> <section class="flex flex-col" > <article class="flex h-[66px] items-center justify-between py-[10px]" > <p class="sub2-medium" > 이메일 받는 시간 </p> <button aria-controls="radix-:r6:" aria-expanded="false" aria-haspopup="dialog" class="sub2-medium rounded-lg bg-text-gray3 px-2 py-1" data-state="closed" type="button" > 오전 9 시 </button> </article> <article class="flex h-[66px] items-center justify-between py-[10px]" > <p class="sub2-medium" > 이메일 받는 요일 </p> <button aria-controls="radix-:r9:" aria-expanded="false" aria-haspopup="dialog" class="sub2-medium rounded-lg bg-text-gray3 px-2 py-1" data-state="closed" type="button" > 주말에는 안 받을래요 </button> </article> </section> </div> <div /> <div /> </body> ❯ Object.getElementError node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/config.js:37:19 ❯ node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/query-helpers.js:76:38 ❯ node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ src/main/components/EmailManagementMenu/EmailManagementMenu.test.tsx:79:35
name: "매일 받을래요",
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/components/EmailManagementMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import EmailTimeManagementDialog from "../EmailTimeManagementDialog";

export default function SubscriptionEmailManagement() {
const { data } = useQuery({
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: "myPage" }),
select: ({ data }) => {
const subscriptionManagementModel = new SubscriptionManagementModel({
initSubscriptionManagementServerList: data.data.workbooks,
Expand Down
10 changes: 1 addition & 9 deletions src/main/components/SubscriptionManagementItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface SubscriptionManagementItemProps
className: HTMLDivElement["className"];
}
export default function SubscriptionManagementItem({
workbookTitle,
workbookId,
isSubscription,
dayInfo,
Expand All @@ -27,15 +28,6 @@ export default function SubscriptionManagementItem({
const [isToggleSubscription, setIsToggleSubscription] =
useState(isSubscription);

const { data: workbookTitle } = useQuery({
...getWorkbookQueryOptions({
workbookId,
isWebpBrowser: true,
}),
select: ({ data }) => {
return data.data.title;
},
});
const { mutate: unsubscriptionWorkbook } = useMutation({
...postUnsubscriptionWorkbookMutationOptions(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("워크북 구독 리스트 관리 컴포넌트 테스트", () => {
const { result } = renderHook(
() =>
useQuery({
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: "myPage" }),
}),
{ wrapper: createQueryProviderWrapper() },
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/components/SubscriptionManagementList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SubscriptionManagementItem from "../SubscriptionManagementItem";

export default function SubscriptionManagementList() {
const { data } = useQuery({
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: "myPage" }),
select: ({ data }) => {
const subscriptionManagementModel = new SubscriptionManagementModel({
initSubscriptionManagementServerList: data.data.workbooks,
Expand Down
2 changes: 1 addition & 1 deletion src/main/components/WorkbookCardList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function WorkbookCardList({
code: code !== undefined ? code : ENTIRE_CATEGORY,
}),
{
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: undefined }),
enabled: isLogin === true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
code: ENTIRE_CATEGORY,
}),
{
...getSubscriptionWorkbooksQueryOptions(),
...getSubscriptionWorkbooksQueryOptions({ pageType: undefined }),
enabled: true,
},
],
Expand All @@ -95,7 +95,7 @@

await waitFor(() => {
workbookListResult.current.forEach((value) => {
expect(value.isSuccess).toBeTruthy();

Check failure on line 98 in src/main/components/WorkbookCardsWrapper/workbookcardsWrapper.test.tsx

View workflow job for this annotation

GitHub Actions / test

src/main/components/WorkbookCardsWrapper/workbookcardsWrapper.test.tsx > 메인페이지 내 카테고리별 워크북 카드 리스트 테스트 > 로그인 상태이고, cardtype LEARN 일때, 바텀 버튼 클릭 테스트

AssertionError: expected false to be truthy Ignored nodes: comments, script, style <html> <head /> <body> <div> <section class="ml-[20px] mb-[73px] mt-[78px]" > <header> <h2 class="h2-bold" > Workbooks </h2> </header> <div class="overflow-x-auto ml-0" data-orientation="horizontal" dir="ltr" > <div aria-orientation="horizontal" class="sub2-bold flex gap-3 py-[10px]" data-orientation="horizontal" role="tablist" style="outline: none;" tabindex="0" > <button aria-controls="radix-:r7:-content-전체" aria-selected="true" class="box-border flex flex-col gap-[10px] pt-[10px] min-w-[48px]" data-orientation="horizontal" data-radix-collection-item="" data-state="active" id="radix-:r7:-trigger-전체" name="전체" role="tab" tabindex="-1" type="button" > <span class="flex w-full items-center justify-center" > 전체 </span> <span class="w-full border-b-2 border-black" /> </button> <button aria-controls="radix-:r7:-content-경제" aria-selected="false" class="text-text-gray2 box-border flex flex-col gap-[10px] pt-[10px] min-w-[48px]" data-orientation="horizontal" data-radix-collection-item="" data-state="inactive" id="radix-:r7:-trigger-경제" name="경제" role="tab" tabindex="-1" type="button" > <span class="flex w-full items-center justify-center" > 경제 </span> </button> <button aria-controls="radix-:r7:-content-IT" aria-selected="false" class="text-text-gray2 box-border flex flex-col gap-[10px] pt-[10px] min-w-[48px]" data-orientation="horizontal" data-radix-collection-item="" data-state="inactive" id="radix-:r7:-trigger-IT" name="IT" role="tab" tabindex="-1" type="button" > <span class="flex w-full items-center justify-center" > IT </span> </button> <button aria-controls="radix-:r7:-content-마케팅" aria-selected="false" class="text-text-gray2 box-border flex flex-col gap-[10px] pt-[10px] min-w-[48px]" data-orientation="horizontal" data-radix-collection-item="" data-state="inactive" id="radix-:r7:-trigger-마케팅" name="마케팅" role="tab" tabindex="-1" type="button" > <span class="flex w-full items-center justify-center" > 마케팅 </span> </button> <button aria-controls="radix-:r7:-content-문화" aria-selected="false" class="text-text-gray2 box-border flex flex-col gap-[10px] pt-[10px] min-w-[48px]" data-orientation="horizontal" data-radix-collection-item="" data-state="inactive" id="radix-:r7:-trigger-문화" name="문화" role="tab" tabindex="-1" type="button" > <span class="flex w-full items-center justify-center" > 문화 </span> </button> <button aria-controls="radix-:r7:-content-과학"
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mockData: WorkbookSubscriptionInfo[] = [
rank: 0,
totalSubscriber: 100,
articleInfo: "{}",
subscription: { date: "1111111", time: "09:00" },
subscription: { dateTimeCode: "1111111", time: "09:00" },
},
{
id: 2,
Expand All @@ -23,7 +23,7 @@ const mockData: WorkbookSubscriptionInfo[] = [
rank: 0,
totalSubscriber: 1,
articleInfo: "{}",
subscription: { date: "1111111", time: "09:00" },
subscription: { dateTimeCode: "1111111", time: "09:00" },
},
{
id: 3,
Expand All @@ -33,7 +33,7 @@ const mockData: WorkbookSubscriptionInfo[] = [
rank: 0,
totalSubscriber: 2,
articleInfo: "{}",
subscription: { date: "0011111", time: "09:00" },
subscription: { dateTimeCode: "0011111", time: "09:00" },
},
];

Expand Down
30 changes: 23 additions & 7 deletions src/main/models/SubscriptionManagementModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
SubscriptionEmailClientInfo,
SubscriptionEmailServerInfo,
} from "@main/types/emailInfo";
import { SubscriptionManagementClientInfo , WorkbookSubscriptionInfo } from "@main/types/workbook";

import {
SubscriptionManagementClientInfo,
WorkbookSubscriptionInfo,
} from "@main/types/workbook";

export class SubscriptionManagementModel {
constructor({
Expand All @@ -21,6 +23,9 @@ export class SubscriptionManagementModel {

get SubscriptionMangementClientList(): SubscriptionManagementClientInfo[] {
return this.subscriptionManagementServerList.map((subscriptionInfo) => ({
workbookTitle: this.getWorkbookTitle({
workbookInfo: subscriptionInfo.workbookInfo,
}),
workbookId: subscriptionInfo.id.toString(),
isSubscription: true,
dayInfo: {
Expand All @@ -33,9 +38,10 @@ export class SubscriptionManagementModel {
get SubscriptionEmailManagementClientInfo(): SubscriptionEmailClientInfo {
const subscriptionServerInfo =
this.subscriptionManagementServerList[0].subscription;

return {
day: this.getDayClientInfo({ date: subscriptionServerInfo.date }),
day: this.getDayClientInfo({
dateTimeCode: subscriptionServerInfo.dateTimeCode,
}),
time: this.getTimeClientInfo({ time: subscriptionServerInfo.time }),
};
}
Expand All @@ -54,12 +60,12 @@ export class SubscriptionManagementModel {
}

private getDayClientInfo({
date,
dateTimeCode,
}: Pick<
SubscriptionEmailServerInfo,
"date"
"dateTimeCode"
>): SubscriptionEmailClientInfo["day"] {
switch (date) {
switch (dateTimeCode) {
case SUBSCRIPTION_EMAIL_SERVER_INFO.DAY["EVERY_DAYS"]:
return SUBSCRIPTION_DAYS["EVERY_DAYS"];

Expand Down Expand Up @@ -88,5 +94,15 @@ export class SubscriptionManagementModel {
}
}

private getWorkbookTitle({
workbookInfo,
}: Pick<WorkbookSubscriptionInfo, "workbookInfo">) {
if (workbookInfo) {
const title = JSON.parse(workbookInfo)?.title as string;
return title;
}
return "";
}

private subscriptionManagementServerList: WorkbookSubscriptionInfo[];
}
19 changes: 14 additions & 5 deletions src/main/remotes/getSubscriptionWorkbooksQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ import {
} from "@main/types/workbook";
import { UseQueryOptions } from "@tanstack/react-query";
import { API_ROUTE, QUERY_KEY } from ".";
import { PageType } from "@shared/types/view";

const getSubscriptionWorkbooks = (): Promise<
const getSubscriptionWorkbooks = ({
pageType,
}: {
pageType?: PageType;
}): Promise<
ApiResponse<WorkbookServerInfoListRes<WorkbookSubscriptionInfo>>
> => {
return fewFetch().get(API_ROUTE.SUBSCRIBE_WORKBOOKS);
return fewFetch().get(API_ROUTE.SUBSCRIBE_WORKBOOKS({ pageType }));
};

export const getSubscriptionWorkbooksQueryOptions = (): UseQueryOptions<
export const getSubscriptionWorkbooksQueryOptions = ({
pageType,
}: {
pageType?: PageType;
}): UseQueryOptions<
ApiResponse<WorkbookServerInfoListRes<WorkbookSubscriptionInfo>>,
unknown,
WorkbookSubscriptionInfo[]
> => {
return {
queryKey: [QUERY_KEY.GET_SUBSCRIBE_WORKBOOKS],
queryFn: () => getSubscriptionWorkbooks(),
queryKey: [QUERY_KEY.GET_SUBSCRIBE_WORKBOOKS, pageType],
queryFn: () => getSubscriptionWorkbooks({ pageType }),
select: (data) => data.data.data.workbooks,
};
};
4 changes: 3 additions & 1 deletion src/main/remotes/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ArticlesInfiniteQueryParams } from "@main/types/article";

import { CategoryClientInfo } from "@common/types/category";
import { PageType } from "@shared/types/view";

export const API_ROUTE = {
CATEGORY: "/api/v1/workbooks/categories",
WORKBOOKS_WITH_CATEGORY: ({ code }: { code: CategoryClientInfo["code"] }) =>
`/api/v1/workbooks?category=${code}&view=mainCard`,
SUBSCRIBE_WORKBOOKS: `/api/v1/subscriptions/workbooks`,
SUBSCRIBE_WORKBOOKS: ({ pageType }: { pageType?: PageType }) =>
`/api/v1/subscriptions/workbooks${pageType ? `?view=${pageType}` : ""}`,
ARTICLE_CATEGORY: "/api/v1/articles/categories",
ARICLES_WITH_CATEGORY: ({
code,
Expand Down
2 changes: 1 addition & 1 deletion src/main/types/emailInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export interface SubscriptionEmailClientInfo {
}
export interface SubscriptionEmailServerInfo {
time: (typeof SUBSCRIPTION_EMAIL_SERVER_INFO.TIME)[keyof typeof SUBSCRIPTION_EMAIL_SERVER_INFO.TIME];
date: string;
dateTimeCode: string;
}
2 changes: 2 additions & 0 deletions src/main/types/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export interface WorkbookSubscriptionInfo
totalSubscriber: number;
articleInfo: string; // JSON문자열
subscription: SubscriptionEmailServerInfo;
workbookInfo?: string; // JSON 문자열
}

export type SubscriptionManagementClientInfo = {
workbookTitle: string;
workbookId: string;
isSubscription: boolean;
dayInfo: {
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PageType = "myPage";
Loading