feat(sub-banner): 서브 배너 생성·수정 폼에 언어 선택 추가
- 생성·수정 폼에 KO/JA/EN 언어 select 추가 (신규 기본값 KO, 수정은 저장된 lang 유지) - multipart request JSON 파트에 정규 대문자 lang 을 항상 포함해 전송 - 목록에 언어 열 추가, lang 누락 응답은 KO 로 간주하지 않고 계약 미충족 안내 - EN 은 현재 앱 공개 국가 매핑에서 미노출됨을 폼에 안내 - 400 등 4xx 거부 시 입력값·선택 파일·날짜를 보존하고 재전송을 막지 않도록 처리 - 언어 관련 focused test 추가
This commit is contained in:
+22
-1
@@ -20,6 +20,23 @@ export const SUB_BANNER_PLACEMENTS = [
|
||||
{value: 'CONTENT_RECOMMENDATION', text: '콘텐츠'}
|
||||
]
|
||||
|
||||
export const SUB_BANNER_LANGS = [
|
||||
{value: 'KO', text: '한국어'},
|
||||
{value: 'JA', text: '일본어'},
|
||||
{value: 'EN', text: '영어'}
|
||||
]
|
||||
|
||||
export const SUB_BANNER_DEFAULT_LANG = 'KO'
|
||||
|
||||
export function langLabel(lang) {
|
||||
const found = SUB_BANNER_LANGS.find((item) => item.value === lang)
|
||||
return found ? found.text : ''
|
||||
}
|
||||
|
||||
export function isSubBannerLang(lang) {
|
||||
return SUB_BANNER_LANGS.some((item) => item.value === lang)
|
||||
}
|
||||
|
||||
export function placementLabel(placement) {
|
||||
const found = SUB_BANNER_PLACEMENTS.find((item) => item.value === placement)
|
||||
return found ? found.text : ''
|
||||
@@ -150,6 +167,8 @@ export function createSubBannerForm(banner = {}) {
|
||||
return {
|
||||
id: banner.id === undefined ? null : banner.id,
|
||||
placement: banner.placement || SUB_BANNER_PLACEMENTS[0].value,
|
||||
// 저장된 언어가 있으면 그대로 사용하고, 신규 등록일 때만 KO 를 기본값으로 쓴다.
|
||||
lang: isSubBannerLang(banner.lang) ? banner.lang : SUB_BANNER_DEFAULT_LANG,
|
||||
image: null,
|
||||
image_url: banner.imageUrl || null,
|
||||
web_url: banner.webUrl === null || banner.webUrl === undefined ? '' : String(banner.webUrl),
|
||||
@@ -236,7 +255,9 @@ function baseRequest(form) {
|
||||
placement: form.placement,
|
||||
webUrl: urls.webUrl,
|
||||
androidDeepLink: urls.androidDeepLink,
|
||||
iosDeepLink: urls.iosDeepLink
|
||||
iosDeepLink: urls.iosDeepLink,
|
||||
// 언어는 생성·수정 모두 현재 선택을 정규 대문자 코드로 항상 보낸다.
|
||||
lang: isSubBannerLang(form.lang) ? form.lang : SUB_BANNER_DEFAULT_LANG
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<th class="text-center">
|
||||
이미지
|
||||
</th>
|
||||
<th class="text-center">
|
||||
언어
|
||||
</th>
|
||||
<th class="text-center">
|
||||
웹 URL
|
||||
</th>
|
||||
@@ -99,6 +102,7 @@
|
||||
class="list-image"
|
||||
>
|
||||
</td>
|
||||
<td>{{ langText(item) }}</td>
|
||||
<td>{{ item.webUrl || '-' }}</td>
|
||||
<td>{{ item.androidDeepLink || '-' }}</td>
|
||||
<td>{{ item.iosDeepLink || '-' }}</td>
|
||||
@@ -121,7 +125,7 @@
|
||||
</tr>
|
||||
<tr v-if="sub_banners.length === 0">
|
||||
<td
|
||||
colspan="8"
|
||||
colspan="9"
|
||||
class="text-center"
|
||||
>
|
||||
등록된 배너가 없습니다.
|
||||
@@ -162,6 +166,30 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
<v-row align="center">
|
||||
<v-col cols="4">
|
||||
<label for="sub-banner-lang">언어</label>
|
||||
</v-col>
|
||||
<v-col cols="8">
|
||||
<v-select
|
||||
id="sub-banner-lang"
|
||||
v-model="sub_banner.lang"
|
||||
:items="langs"
|
||||
item-text="text"
|
||||
item-value="value"
|
||||
label="언어 선택"
|
||||
:error-messages="form_errors.lang"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
<v-col class="guide-text">
|
||||
영어(EN)는 저장과 목록 조회는 가능하지만 현재 앱 공개 국가 매핑(JP → 일본어, 그 외 → 한국어)에서는 노출되지 않습니다.
|
||||
배너 소재 언어와 연결된 이벤트 언어는 운영자가 직접 맞춰 주세요.
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
<v-row align="center">
|
||||
<v-col cols="4">
|
||||
@@ -339,7 +367,9 @@ import {
|
||||
buildSubBannerUpdateRequest,
|
||||
createSubBannerForm,
|
||||
formatScheduleRange,
|
||||
langLabel,
|
||||
scheduleStatus,
|
||||
SUB_BANNER_LANGS,
|
||||
SUB_BANNER_PLACEMENTS,
|
||||
validateSubBannerForm
|
||||
} from "@/utils/sub_banner"
|
||||
@@ -355,6 +385,7 @@ export default {
|
||||
show_write_dialog: false,
|
||||
show_delete_confirm_dialog: false,
|
||||
placements: SUB_BANNER_PLACEMENTS,
|
||||
langs: SUB_BANNER_LANGS,
|
||||
selected_placement: SUB_BANNER_PLACEMENTS[0].value,
|
||||
sub_banners: [],
|
||||
selected_sub_banner: {},
|
||||
@@ -376,6 +407,16 @@ export default {
|
||||
this.$dialog.notify.success(message)
|
||||
},
|
||||
|
||||
// 400 등 4xx 는 ApiResponse 가 아닌 표준 Spring Boot body 일 수 있어 단정하지 않는다.
|
||||
clientErrorMessage(error) {
|
||||
const response = error && error.response
|
||||
if (!response || response.status < 400 || response.status >= 500) return null
|
||||
|
||||
const body = response.data
|
||||
const message = body && typeof body === 'object' ? (body.message || body.error) : null
|
||||
return message || '입력값을 서버가 거부했습니다. 값을 확인한 뒤 다시 시도해 주세요.'
|
||||
},
|
||||
|
||||
imageAdd(payload) {
|
||||
const file = payload
|
||||
|
||||
@@ -427,6 +468,11 @@ export default {
|
||||
return scheduleStatus(subBanner)
|
||||
},
|
||||
|
||||
langText(subBanner) {
|
||||
// lang 이 없는 응답을 KO 로 간주하지 않는다.
|
||||
return langLabel(subBanner.lang) || '-'
|
||||
},
|
||||
|
||||
validate() {
|
||||
const errors = validateSubBannerForm(
|
||||
this.sub_banner,
|
||||
@@ -480,9 +526,15 @@ export default {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
} catch (e) {
|
||||
const clientError = this.clientErrorMessage(e)
|
||||
if (clientError !== null) {
|
||||
// 서버가 확실히 거부했으므로 입력값·선택 파일·날짜를 그대로 두고 재전송도 막지 않는다.
|
||||
this.notifyError(clientError)
|
||||
} else {
|
||||
// 결과가 불명확하므로 자동 재시도 없이 중복 전송을 막고 목록으로 상태를 확인한다.
|
||||
this.submit_blocked = true
|
||||
this.notifyError('응답을 받지 못했습니다. 등록 여부를 목록에서 확인해 주세요.')
|
||||
}
|
||||
} finally {
|
||||
this.is_loading = false
|
||||
}
|
||||
@@ -521,8 +573,13 @@ export default {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
} catch (e) {
|
||||
const clientError = this.clientErrorMessage(e)
|
||||
if (clientError !== null) {
|
||||
this.notifyError(clientError)
|
||||
} else {
|
||||
this.submit_blocked = true
|
||||
this.notifyError('응답을 받지 못했습니다. 수정 여부를 목록에서 확인해 주세요.')
|
||||
}
|
||||
} finally {
|
||||
this.is_loading = false
|
||||
}
|
||||
@@ -561,6 +618,11 @@ export default {
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
// 서버가 id 오름차순으로 내려주므로 재정렬하지 않고 전부 표시한다.
|
||||
this.sub_banners = Array.isArray(res.data.data) ? res.data.data : []
|
||||
|
||||
// 응답에 lang 이 없으면 KO 로 간주하지 않고 계약 미충족을 알린다.
|
||||
if (this.sub_banners.some((item) => !item || item.lang === undefined)) {
|
||||
this.notifyError('목록 응답에 lang 이 없습니다. 언어 계약이 적용된 서버인지 확인해 주세요.')
|
||||
}
|
||||
} else {
|
||||
// 조회 실패를 빈 목록으로 오인하지 않는다.
|
||||
this.notifyError(res.data.message || '목록을 불러오지 못했습니다. 다시 시도해 주세요.')
|
||||
|
||||
+148
-3
@@ -38,6 +38,7 @@ const {
|
||||
buildSubBannerUpdateRequest,
|
||||
createSubBannerForm,
|
||||
formatScheduleRange,
|
||||
langLabel,
|
||||
normalizeUrls,
|
||||
placementLabel,
|
||||
resolveSubBannerTarget,
|
||||
@@ -55,6 +56,7 @@ const envelope = (data, success = true, message = null) => ({ success, message,
|
||||
const subBanner = (overrides = {}) => ({
|
||||
id: 1,
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
lang: 'KO',
|
||||
imageUrl: 'https://cdn.example.test/promo.jpg',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: null,
|
||||
@@ -186,7 +188,8 @@ test('주소 수정: 전부 비우면 오류, 한 필드만 비우면 해당 값
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: 'sampleapp://promo',
|
||||
iosDeepLink: null
|
||||
iosDeepLink: null,
|
||||
lang: 'KO'
|
||||
})
|
||||
})
|
||||
|
||||
@@ -267,7 +270,8 @@ test('등록 요청: 네 기본 필드는 항상 보내고 날짜 미입력은
|
||||
placement: 'CONTENT_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: 'sampleapp://promo',
|
||||
iosDeepLink: null
|
||||
iosDeepLink: null,
|
||||
lang: 'KO'
|
||||
})
|
||||
assert.deepEqual(buildSubBannerCreateRequest({ ...base, start_date: '2026-11-01T09:30' }).startDate, '2026-11-01 09:30')
|
||||
assert.deepEqual(buildSubBannerCreateRequest({ ...base, end_date: '2026-11-30T23:59' }).endDate, '2026-11-30 23:59')
|
||||
@@ -283,7 +287,8 @@ test('수정 요청: 미변경 경계는 생략해 보존하고 지운 경계만
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: 'sampleapp://promo',
|
||||
iosDeepLink: null
|
||||
iosDeepLink: null,
|
||||
lang: 'KO'
|
||||
}
|
||||
|
||||
// loaded date 재전송: 값이 같으면 생략해 저장 값을 보존한다.
|
||||
@@ -394,6 +399,7 @@ test('등록: image 와 application/json request 파트를 보내고 목록을
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: null,
|
||||
iosDeepLink: null,
|
||||
lang: 'KO',
|
||||
startDate: '2026-11-01 09:30'
|
||||
})
|
||||
assert.deepEqual(successes, ['등록되었습니다.'])
|
||||
@@ -451,6 +457,7 @@ test('수정: 목록 객체로 폼을 채우고 일정만 바꾸면 image 를
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: 'sampleapp://promo',
|
||||
iosDeepLink: null,
|
||||
lang: 'KO',
|
||||
endDate: '2026-12-31 23:59'
|
||||
})
|
||||
assert.deepEqual(successes, ['수정되었습니다.'])
|
||||
@@ -550,6 +557,144 @@ test('중복 제출 방지: 진행 중 재호출과 timeout 이후 재전송을
|
||||
assert.equal(timeoutPage.errors.length, 1)
|
||||
})
|
||||
|
||||
test('언어: 신규 기본값은 KO 이고 선택한 코드가 정규 대문자로 직렬화된다', () => {
|
||||
assert.equal(createSubBannerForm().lang, 'KO')
|
||||
assert.equal(langLabel('KO'), '한국어')
|
||||
assert.equal(langLabel('JA'), '일본어')
|
||||
assert.equal(langLabel('EN'), '영어')
|
||||
assert.equal(langLabel('ko'), '')
|
||||
|
||||
for (const lang of ['KO', 'JA', 'EN']) {
|
||||
const created = buildSubBannerCreateRequest(form({ lang, web_url: 'https://example.test/promo' }))
|
||||
assert.deepEqual(created, {
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: null,
|
||||
iosDeepLink: null,
|
||||
lang
|
||||
})
|
||||
|
||||
const saved = subBanner({ lang })
|
||||
const updated = buildSubBannerUpdateRequest(createSubBannerForm(saved), saved)
|
||||
assert.deepEqual(Object.keys(updated), ['placement', 'webUrl', 'androidDeepLink', 'iosDeepLink', 'lang'])
|
||||
assert.equal(updated.lang, lang)
|
||||
}
|
||||
})
|
||||
|
||||
test('언어: 수정 폼은 저장된 JA/EN 으로 미리 선택되고 다른 값만 바꿔도 보존된다', async () => {
|
||||
stubFormData()
|
||||
const { vm } = page()
|
||||
const calls = []
|
||||
Vue.axios = {
|
||||
put: async (...args) => { calls.push(args); return { status: 200, data: envelope(subBanner({ lang: 'JA' })) } },
|
||||
get: async () => ({ status: 200, data: envelope([subBanner({ lang: 'JA' })]) })
|
||||
}
|
||||
|
||||
const saved = subBanner({ id: 55, lang: 'JA', startDate: '2026-11-01 09:30', endDate: '2026-11-30 23:59' })
|
||||
vm.showModifyDialog(saved)
|
||||
assert.equal(vm.sub_banner.lang, 'JA')
|
||||
|
||||
// 이미지와 종료 일시만 바꿔도 저장된 언어가 그대로 전송된다.
|
||||
vm.imageAdd({ name: 'new.jpg', type: 'image/jpeg' })
|
||||
vm.sub_banner.end_date = '2026-12-31T23:59'
|
||||
await vm.modify()
|
||||
|
||||
assert.equal(calls[0][0], '/admin/sub-banners/55')
|
||||
assert.equal(calls[0][1].get('image').name, 'new.jpg')
|
||||
assert.deepEqual(requestOf(calls[0][1]), {
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: null,
|
||||
iosDeepLink: null,
|
||||
lang: 'JA',
|
||||
endDate: '2026-12-31 23:59'
|
||||
})
|
||||
|
||||
const en = subBanner({ id: 56, lang: 'EN' })
|
||||
vm.showModifyDialog(en)
|
||||
assert.equal(vm.sub_banner.lang, 'EN')
|
||||
|
||||
// 언어만 바꿔도 나머지 값은 그대로다.
|
||||
vm.sub_banner.lang = 'KO'
|
||||
await vm.modify()
|
||||
assert.deepEqual(requestOf(calls[1][1]), {
|
||||
placement: 'HOME_RECOMMENDATION',
|
||||
webUrl: 'https://example.test/promo',
|
||||
androidDeepLink: null,
|
||||
iosDeepLink: null,
|
||||
lang: 'KO'
|
||||
})
|
||||
assert.equal(calls[1][1].has('image'), false)
|
||||
})
|
||||
|
||||
test('언어 오류: 400 Boot body 와 success=false 모두 입력·이미지·날짜를 보존한다', async () => {
|
||||
stubFormData()
|
||||
const bootError = {
|
||||
response: {
|
||||
status: 400,
|
||||
data: { timestamp: '2026-11-01T00:00:00.000+00:00', status: 400, error: 'Bad Request', message: '지원하지 않는 언어입니다.', path: '/admin/sub-banners' }
|
||||
}
|
||||
}
|
||||
|
||||
const { vm, errors, successes } = page()
|
||||
Vue.axios = {
|
||||
post: async () => { throw bootError },
|
||||
get: async () => ({ status: 200, data: envelope([subBanner()]) })
|
||||
}
|
||||
|
||||
vm.showCreateDialog()
|
||||
vm.sub_banner.lang = 'EN'
|
||||
vm.sub_banner.web_url = 'https://example.test/promo'
|
||||
vm.sub_banner.start_date = '2026-11-01T09:30'
|
||||
vm.imageAdd({ name: 'promo.jpg', type: 'image/jpeg' })
|
||||
await vm.submit()
|
||||
|
||||
assert.deepEqual(errors, ['지원하지 않는 언어입니다.'])
|
||||
assert.deepEqual(successes, [])
|
||||
// 400 은 서버가 확실히 거부한 것이므로 재전송을 막지 않고 상태를 보존한다.
|
||||
assert.equal(vm.submit_blocked, false)
|
||||
assert.equal(vm.show_write_dialog, true)
|
||||
assert.equal(vm.sub_banner.lang, 'EN')
|
||||
assert.equal(vm.sub_banner.web_url, 'https://example.test/promo')
|
||||
assert.equal(vm.sub_banner.start_date, '2026-11-01T09:30')
|
||||
assert.equal(vm.sub_banner.image.name, 'promo.jpg')
|
||||
|
||||
const failed = page()
|
||||
Vue.axios = { put: async () => ({ status: 200, data: envelope(null, false, '언어 값이 올바르지 않습니다.') }) }
|
||||
failed.vm.showModifyDialog(subBanner({ id: 9, lang: 'JA', startDate: '2026-11-01 09:30' }))
|
||||
failed.vm.sub_banner.lang = 'EN'
|
||||
await failed.vm.modify()
|
||||
|
||||
assert.deepEqual(failed.errors, ['언어 값이 올바르지 않습니다.'])
|
||||
assert.equal(failed.vm.sub_banner.lang, 'EN')
|
||||
assert.equal(failed.vm.sub_banner.start_date, '2026-11-01T09:30')
|
||||
assert.equal(failed.vm.sub_banner.image_url, 'https://cdn.example.test/promo.jpg')
|
||||
})
|
||||
|
||||
test('목록: 언어를 표시하고 lang 이 없는 응답은 KO 로 간주하지 않는다', async () => {
|
||||
const { vm, errors } = page()
|
||||
Vue.axios = {
|
||||
get: async () => ({
|
||||
status: 200,
|
||||
data: envelope([subBanner({ id: 1, lang: 'KO' }), subBanner({ id: 2, lang: 'JA' }), subBanner({ id: 3, lang: 'EN' })])
|
||||
})
|
||||
}
|
||||
|
||||
await vm.getSubBanners()
|
||||
const rendered = activatorText(vm)
|
||||
assert.ok(rendered.includes('한국어'))
|
||||
assert.ok(rendered.includes('일본어'))
|
||||
assert.ok(rendered.includes('영어'))
|
||||
assert.deepEqual(errors, [])
|
||||
|
||||
const missing = subBanner({ id: 4 })
|
||||
delete missing.lang
|
||||
Vue.axios = { get: async () => ({ status: 200, data: envelope([missing]) }) }
|
||||
await vm.getSubBanners()
|
||||
assert.equal(errors.length, 1)
|
||||
assert.equal(vm.langText(missing), '-')
|
||||
})
|
||||
|
||||
;(async () => {
|
||||
for (const { name, run } of tests) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user