Skip to content
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
4 changes: 4 additions & 0 deletions src/features/order/order-subscription.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type SellerOrderUpdate {
productName: String!
"""커스텀 주문 여부(첫 품목의 커스텀 방식이 NONE이 아니면 true)."""
hasCustom: Boolean!
"""
확정 마감 시각. 이때까지 확정하지 않으면 자동 취소된다. 접수(SUBMITTED) 상태가 아니거나 결제 도입 전 주문이면 null.
"""
confirmDeadlineAt: DateTime
"""주문 행의 updated_at. 폐기 규칙의 비교 키다."""
updatedAt: DateTime!
}
Expand Down
1 change: 1 addition & 0 deletions src/features/order/services/order-admin.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ describe('AdminOrderService (real DB)', () => {
totalPrice: order.total_price,
productName: 'Product snapshot',
hasCustom: false,
confirmDeadlineAt: null,
updatedAt: row.updated_at.toISOString(),
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ describe('AdminDepositService (real DB)', () => {
status: 'SUBMITTED',
productName: '딸기 케이크',
hasCustom: false,
confirmDeadlineAt: new Date(NOW.getTime() + DAY_MS).toISOString(),
}),
]);
topic.stop();
Expand Down
72 changes: 72 additions & 0 deletions src/features/order/services/order-events-mappers.helper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
toSellerOrderUpdateEvent,
type SellerOrderUpdateRow,
} from '@/features/order/services/order-events-mappers.helper';
import { OrderStatus } from '@/generated/prisma/client';

const DEADLINE = new Date('2026-09-16T09:00:00.000Z');

function row(o: Partial<SellerOrderUpdateRow> = {}): SellerOrderUpdateRow {
return {
id: 1n,
order_number: 'ORD-1',
status: OrderStatus.SUBMITTED,
pickup_at: new Date('2026-09-16T10:00:00.000Z'),
buyer_name: '차차',
total_price: 30000,
confirm_deadline_at: DEADLINE,
updated_at: new Date('2026-09-16T07:00:00.000Z'),
items: [
{ product_name_snapshot: '딸기 케이크', custom_mode_snapshot: 'NONE' },
],
...o,
};
}

describe('toSellerOrderUpdateEvent', () => {
it('주문 행을 ISO 날짜 문자열 payload로 옮긴다', () => {
expect(toSellerOrderUpdateEvent('SUBMITTED', row())).toEqual({
kind: 'SUBMITTED',
orderId: '1',
orderNumber: 'ORD-1',
status: 'SUBMITTED',
pickupAt: '2026-09-16T10:00:00.000Z',
buyerName: '차차',
totalPrice: 30000,
productName: '딸기 케이크',
hasCustom: false,
confirmDeadlineAt: '2026-09-16T09:00:00.000Z',
updatedAt: '2026-09-16T07:00:00.000Z',
});
});

// 확정·취소 뒤에도 행에 마감이 남으므로 모든 상태를 전수로 본다
it.each(
Object.values(OrderStatus).map((status) => ({
status,
expected:
status === OrderStatus.SUBMITTED ? DEADLINE.toISOString() : null,
})),
)(
'마감이 남은 $status 주문의 확정 마감은 $expected이다',
({ status, expected }) => {
expect(
toSellerOrderUpdateEvent('STATUS_CHANGED', row({ status }))
.confirmDeadlineAt,
).toBe(expected);
},
);

it('결제 도입 전 접수 주문(마감 없음)의 확정 마감은 null이다', () => {
expect(
toSellerOrderUpdateEvent('SUBMITTED', row({ confirm_deadline_at: null }))
.confirmDeadlineAt,
).toBeNull();
});

it('품목이 없으면 상품명은 빈 문자열, 커스텀 여부는 false다', () => {
expect(
toSellerOrderUpdateEvent('STATUS_CHANGED', row({ items: [] })),
).toMatchObject({ productName: '', hasCustom: false });
});
});
12 changes: 11 additions & 1 deletion src/features/order/services/order-events-mappers.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type {
SellerOrderUpdateEvent,
SellerOrderUpdateKind,
} from '@/features/order/types/order-seller-output.type';
import type { Order, OrderItem } from '@/generated/prisma/client';
import {
OrderStatus,
type Order,
type OrderItem,
} from '@/generated/prisma/client';

export type SellerOrderUpdateRow = Pick<
Order,
Expand All @@ -13,6 +17,7 @@ export type SellerOrderUpdateRow = Pick<
| 'pickup_at'
| 'buyer_name'
| 'total_price'
| 'confirm_deadline_at'
| 'updated_at'
> & {
/** 첫 품목이 상품명·커스텀 여부를 정한다 */
Expand All @@ -34,6 +39,11 @@ export function toSellerOrderUpdateEvent(
totalPrice: row.total_price,
productName: firstItem?.product_name_snapshot ?? '',
hasCustom: isCustomOrderItem(firstItem),
// 확정·취소 뒤에도 행에 값이 남으므로 접수 상태일 때만 낸다
confirmDeadlineAt:
row.status === OrderStatus.SUBMITTED && row.confirm_deadline_at
? row.confirm_deadline_at.toISOString()
: null,
updatedAt: row.updated_at.toISOString(),
};
}
1 change: 1 addition & 0 deletions src/features/order/services/order-events.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const EVENT: SellerOrderUpdateEvent = {
totalPrice: 56000,
productName: '딸기 케이크',
hasCustom: false,
confirmDeadlineAt: '2026-09-16T09:00:00.000Z',
updatedAt: '2026-09-16T07:00:00.000Z',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,13 @@ describe('OrderLifecycleScheduler (real DB)', () => {
'order.status_changed',
'refund.requested',
]);
// 행에는 마감이 남지만 접수를 벗어났으므로 이벤트에는 싣지 않는다
expect(topic.received).toEqual([
expect.objectContaining({ kind: 'STATUS_CHANGED', status: 'CANCELED' }),
expect.objectContaining({
kind: 'STATUS_CHANGED',
status: 'CANCELED',
confirmDeadlineAt: null,
}),
]);
topic.stop();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,22 @@ describe('SellerOrderPickupService (real DB)', () => {
});
// 접수 + 24h(9/17 15:00 KST)보다 이른 픽업 → 마감 = 새 픽업
const earlier = new Date('2026-09-16T08:00:00.000Z');
const topic = await collectTopic(pubSub, `order.seller.${store.id}`);

await reschedule(account.id, order.id, earlier);

expect(await orderRow(order.id)).toMatchObject({
confirm_deadline_at: earlier,
confirm_reminder_sent_at: null,
});
// 구독 이벤트도 다시 잰 마감을 싣는다
expect(topic.received).toEqual([
expect.objectContaining({
kind: 'PICKUP_RESCHEDULED',
confirmDeadlineAt: earlier.toISOString(),
}),
]);
topic.stop();
// 더 늦은 픽업이면 접수 + 24시간이 마감이다
await reschedule(account.id, order.id, PICKUP_AT);
expect((await orderRow(order.id)).confirm_deadline_at).toEqual(
Expand Down
9 changes: 7 additions & 2 deletions src/features/order/services/order-seller.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,11 @@ describe('SellerOrderService (real DB)', () => {
});

describe('sellerOrderUpdated 발행', () => {
it('상태 변경 시 매장 토픽에 1건 — 첫 품목 상품명·커스텀 여부와 갱신된 updated_at을 싣는다', async () => {
it('상태 변경 시 매장 토픽에 1건 — 첫 품목 상품명·커스텀 여부와 갱신된 updated_at을 싣고, 접수를 벗어나면 확정 마감은 null이다', async () => {
const { account, store } = await setupSellerWithStore(prisma);
const order = await createOrder(prisma);
const order = await createOrder(prisma, {
confirm_deadline_at: new Date(Date.now() + 60 * 60_000),
});
await createOrderItem(prisma, {
order_id: order.id,
store_id: store.id,
Expand Down Expand Up @@ -1159,9 +1161,12 @@ describe('SellerOrderService (real DB)', () => {
totalPrice: order.total_price,
productName: '확정 품목',
hasCustom: true,
confirmDeadlineAt: null,
updatedAt: row.updated_at.toISOString(),
},
]);
// 확정 뒤에도 행에는 마감이 남는다 — 이벤트가 상태로 가린다
expect(row.confirm_deadline_at).toEqual(order.confirm_deadline_at);
expect(row.updated_at.getTime()).toBeGreaterThan(
order.updated_at.getTime(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('OrderSubscriptionService (real DB)', () => {
totalPrice: 10000,
productName: '케이크',
hasCustom: false,
confirmDeadlineAt: null,
updatedAt: '2026-09-16T07:00:00.000Z',
};

Expand Down
2 changes: 2 additions & 0 deletions src/features/order/types/order-seller-output.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ export interface SellerOrderUpdateEvent {
totalPrice: number;
productName: string;
hasCustom: boolean;
/** 접수 상태가 아니거나 결제 도입 전 주문이면 null. */
confirmDeadlineAt: string | null;
updatedAt: string;
}
Loading