From c245539e4613c586825af317a7b8cd9ee7d1ad80 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Thu, 22 Oct 2026 20:07:25 +0900 Subject: [PATCH] =?UTF-8?q?feat(gift):=20=EA=B4=80=EB=A6=AC=EC=9E=90=20?= =?UTF-8?q?=EC=84=A0=EB=AC=BC=ED=95=A8=20=EC=8B=A0=EC=B2=AD=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=EC=95=A1=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버 availableActions에 CANCEL이 포함된 경우에만 목록/상세에 신청 취소 버튼을 노출하고, 기존 액션 확인창·dispatch 프레임워크를 재사용해 body 없는 POST /api/v2/admin/gifts/{applicationNo}/cancel을 호출한다. - giftActions에 CANCEL(신청 취소) 추가 및 cancelGift API 추가 - 확인창에 신청번호와 발신자 전액 리워드캔 환불 안내 표시 - 성공 시 필터/페이지를 유지한 채 목록과 열린 상세 재조회, 실패 시 현재 상태만 재조회(재시도 없음) - 취소 노출/요청/성공/실패 시나리오 단위 테스트 추가 --- src/api/gift.js | 7 +- src/utils/gift.js | 3 +- src/views/Gift/GiftActions.vue | 2 +- src/views/Gift/GiftList.vue | 20 ++++-- tests/gift.test.js | 115 +++++++++++++++++++++++++++++++-- 5 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/api/gift.js b/src/api/gift.js index bfbf4b8..60ae505 100644 --- a/src/api/gift.js +++ b/src/api/gift.js @@ -36,4 +36,9 @@ async function markUndeliverable(applicationNo, reason) { return response.data } -export { getGifts, getGift, arriveMailbox, completeInspection, completeDelivery, markUndeliverable } +async function cancelGift(applicationNo) { + const response = await Vue.axios.post(`${baseUrl}/${encodeURIComponent(applicationNo)}/cancel`) + return response.data +} + +export { getGifts, getGift, arriveMailbox, completeInspection, completeDelivery, markUndeliverable, cancelGift } diff --git a/src/utils/gift.js b/src/utils/gift.js index 1fe0de3..b860ef8 100644 --- a/src/utils/gift.js +++ b/src/utils/gift.js @@ -13,7 +13,8 @@ export const giftActions = [ { value: 'ARRIVE_MAILBOX', label: '사서함 도착 처리', method: 'arriveMailbox' }, { value: 'COMPLETE_INSPECTION', label: '검수 완료 처리', method: 'completeInspection' }, { value: 'COMPLETE_DELIVERY', label: '전달 완료 처리', method: 'completeDelivery' }, - { value: 'MARK_UNDELIVERABLE', label: '전달 불가 처리', method: 'markUndeliverable' } + { value: 'MARK_UNDELIVERABLE', label: '전달 불가 처리', method: 'markUndeliverable' }, + { value: 'CANCEL', label: '신청 취소', method: 'cancelGift' } ] export function validateUndeliverableReason(reason) { diff --git a/src/views/Gift/GiftActions.vue b/src/views/Gift/GiftActions.vue index 7b9db6f..5706fed 100644 --- a/src/views/Gift/GiftActions.vue +++ b/src/views/Gift/GiftActions.vue @@ -3,7 +3,7 @@ 상태 변경 확인

신청번호: {{ pendingAction.applicationNo }}

-

{{ pendingAction.label }}하시겠습니까?

+

+ 신청번호 {{ pendingAction.applicationNo }}의 선물 신청을 취소하시겠습니까? +

+

+ {{ pendingAction.label }}하시겠습니까? +

+

+ 사용한 캔 전액이 발신자에게 리워드캔으로 환불됩니다. +

{ +test('API: 상세 및 다섯 가지 POST 경로/본문을 정확하게 전달한다', async () => { const calls = [] Vue.axios = { get: async (...args) => { calls.push(['GET', ...args]); return { data: envelope(detail()) } }, @@ -90,21 +90,23 @@ test('API: 상세 및 네 가지 POST 경로/본문을 정확하게 전달한다 await api.completeInspection('G/001') await api.completeDelivery('G/001') await api.markUndeliverable('G/001', '파손') + await api.cancelGift('G/001') assert.deepEqual(calls, [ ['GET', '/api/v2/admin/gifts/G%2F001'], ['POST', '/api/v2/admin/gifts/G%2F001/arrive-mailbox'], ['POST', '/api/v2/admin/gifts/G%2F001/complete-inspection'], ['POST', '/api/v2/admin/gifts/G%2F001/complete-delivery'], - ['POST', '/api/v2/admin/gifts/G%2F001/mark-undeliverable', { reason: '파손' }] + ['POST', '/api/v2/admin/gifts/G%2F001/mark-undeliverable', { reason: '파손' }], + ['POST', '/api/v2/admin/gifts/G%2F001/cancel'] ]) }) test('액션: 서버 availableActions에 있는 버튼만 실제 템플릿에서 노출한다', () => { assert.deepEqual(giftActions.map(action => [action.value, action.label]), [ ['ARRIVE_MAILBOX', '사서함 도착 처리'], ['COMPLETE_INSPECTION', '검수 완료 처리'], - ['COMPLETE_DELIVERY', '전달 완료 처리'], ['MARK_UNDELIVERABLE', '전달 불가 처리'] + ['COMPLETE_DELIVERY', '전달 완료 처리'], ['MARK_UNDELIVERABLE', '전달 불가 처리'], ['CANCEL', '신청 취소'] ]) - const scenarios = [[], ['ARRIVE_MAILBOX', 'MARK_UNDELIVERABLE'], ['COMPLETE_INSPECTION', 'MARK_UNDELIVERABLE'], ['COMPLETE_DELIVERY', 'MARK_UNDELIVERABLE'], [], [], []] + const scenarios = [['CANCEL'], ['ARRIVE_MAILBOX', 'MARK_UNDELIVERABLE'], ['COMPLETE_INSPECTION', 'MARK_UNDELIVERABLE'], ['COMPLETE_DELIVERY', 'MARK_UNDELIVERABLE'], [], [], []] for (const actions of scenarios.concat([['UNKNOWN'], ['MARK_UNDELIVERABLE']])) { const vm = new Vue({ ...GiftActions, propsData: { actions } }) const buttons = nodes(vm._render()).filter(node => node.tag === 'v-btn') @@ -403,6 +405,111 @@ test('메뉴: ADMIN에 선물함 리스트를 추가하고 기존 서버 메뉴 } }) +test('취소: 서버 availableActions에 CANCEL이 있을 때만 목록과 상세에 노출하고 기존 dispatch로 실행한다', () => { + const { vm } = page() + vm.gifts = [{ + applicationNo: 'G-001', senderNickname: '발송인', recipientNickname: '수취인', + sizeName: '소형', sizeCode: 'S', categoryName: '문구', classificationNumber: 'C1', + courierCompanyName: null, trackingNumber: null, status: 'RECEIVED', statusName: '접수 완료', availableActions: ['CANCEL'] + }] + vm.detail = detail({ status: 'RECEIVED', statusName: '접수 완료', availableActions: ['CANCEL'] }) + vm.show_detail_dialog = true + const components = nodes(vm._render()).filter(node => node.componentOptions && node.componentOptions.Ctor.options.name === 'GiftActions') + assert.equal(components.length, 2) + for (const component of components) { + const actions = Array.from(component.componentOptions.propsData.actions) + assert.deepEqual(actions, ['CANCEL']) + const buttons = nodes(new Vue({ ...GiftActions, propsData: { actions } })._render()).filter(node => node.tag === 'v-btn') + assert.deepEqual(buttons.map(button => nodes(button).map(node => node.text || '').join('').trim()), ['신청 취소']) + } + components[0].componentOptions.listeners.select('CANCEL') + assert.deepEqual({ ...vm.pendingAction }, { value: 'CANCEL', label: '신청 취소', method: 'cancelGift', applicationNo: 'G-001' }) + vm.cancelAction() + for (const actions of [[], ['ARRIVE_MAILBOX'], ['COMPLETE_INSPECTION'], ['COMPLETE_DELIVERY', 'MARK_UNDELIVERABLE']]) { + const buttons = nodes(new Vue({ ...GiftActions, propsData: { actions } })._render()).filter(node => node.tag === 'v-btn') + assert.equal(buttons.map(button => nodes(button).map(node => node.text || '').join('').trim()).includes('신청 취소'), false) + } + vm.requestAction({ applicationNo: 'G-002', status: 'RECEIVED', availableActions: [] }, 'CANCEL') + assert.equal(vm.pendingAction, null) + assert.equal(vm.show_confirm_dialog, false) +}) + +test('취소 확인창: 신청번호와 전액 리워드캔 환불 안내를 표시하고 닫으면 요청하지 않는다', async () => { + const { vm } = page() + let posts = 0 + Vue.axios = { post: async () => { posts++; return { data: envelope({}) } }, get: async () => ({ data: envelope(list()) }) } + vm.requestAction(detail({ status: 'RECEIVED', statusName: '접수 완료', availableActions: ['CANCEL'] }), 'CANCEL') + assert.equal(vm.show_confirm_dialog, true) + assert.equal(vm.show_reason_dialog, false) + const text = nodes(vm._render()).map(node => node.text || '').join(' ') + for (const part of ['G-001', '취소하시겠습니까?', '사용한 캔 전액이 발신자에게 리워드캔으로 환불됩니다.']) assert.ok(text.includes(part), part) + vm.cancelConfirmation() + assert.equal(vm.show_confirm_dialog, false) + assert.equal(vm.pendingAction, null) + await vm.executeAction() + assert.equal(posts, 0) +}) + +test('취소: 확정 시 본문 없이 한 번만 요청하고 필터/페이지를 유지한 채 목록과 상세를 갱신한다', async () => { + const { vm, successes, errors } = page() + const pending = deferred() + const calls = [] + Vue.axios = { + post: async (...args) => { + calls.push(['POST', ...args]) + await pending.promise + return { data: envelope({ applicationNo: 'G-001', status: 'CANCELED', statusName: '신청 취소', occurredAt: '2026-09-30T12:00:00Z' }) } + }, + get: async (url, config) => { + calls.push(['GET', url, config]) + return { data: envelope(config ? list({ page: 2, totalCount: 60 }) : detail({ status: 'CANCELED', statusName: '신청 취소', availableActions: [] })) } + } + } + vm.appliedFilters = { status: 'RECEIVED', applicationNo: '', nickname: '발송인' } + vm.page = 3 + vm.detail = detail({ status: 'RECEIVED', statusName: '접수 완료', availableActions: ['CANCEL'] }) + vm.show_detail_dialog = true + vm.requestAction(vm.detail, 'CANCEL') + const operation = vm.executeAction() + await vm.executeAction() + pending.resolve() + await operation + assert.deepEqual(calls.filter(call => call[0] === 'POST'), [['POST', '/api/v2/admin/gifts/G-001/cancel']]) + assert.deepEqual(calls.find(call => call[1] === '/api/v2/admin/gifts')[2].params, { status: 'RECEIVED', nickname: '발송인', page: 2, size: 20 }) + assert.ok(calls.some(call => call[1] === '/api/v2/admin/gifts/G-001')) + assert.equal(vm.page, 3) + assert.equal(vm.detail.status, 'CANCELED') + assert.equal(vm.detail.statusName, '신청 취소') + assert.deepEqual(Array.from(vm.detail.availableActions), []) + assert.deepEqual(successes, ['신청 취소되었습니다.']) + assert.deepEqual(errors, []) + assert.equal(vm.is_operating, false) + assert.equal(vm.show_confirm_dialog, false) +}) + +test('취소 실패: 가짜 취소 없이 공통 오류를 표시하고 서버 현재 상태를 재조회한다', async () => { + for (const fail of [async () => ({ data: { success: false, message: '이미 변경된 상태입니다.' } }), async () => { throw { response: { data: { message: '통신 실패' } } } }]) { + const { vm, errors, successes } = page() + const calls = [] + Vue.axios = { + post: fail, + get: async (url, config) => { + calls.push(url) + return { data: envelope(config ? list() : detail({ status: 'DELIVERED', statusName: '전달 완료', availableActions: [] })) } + } + } + vm.detail = detail({ status: 'RECEIVED', statusName: '접수 완료', availableActions: ['CANCEL'] }) + vm.show_detail_dialog = true + vm.requestAction(vm.detail, 'CANCEL') + await vm.executeAction() + assert.equal(errors.length, 1) + assert.equal(successes.length, 0) + assert.deepEqual(calls.slice().sort(), ['/api/v2/admin/gifts', '/api/v2/admin/gifts/G-001']) + assert.equal(vm.detail.status, 'DELIVERED') + assert.equal(vm.is_operating, false) + } +}) + ;(async () => { for (const { name, run } of tests) { try {