diff --git a/src/api/member.js b/src/api/member.js
index 208f30f..55d0c5a 100644
--- a/src/api/member.js
+++ b/src/api/member.js
@@ -43,6 +43,13 @@ async function updateMember(id, user_type) {
return Vue.axios.put("/admin/member", request)
}
+async function updateCreatorLocalizedNameJa(creatorId, displayName) {
+ return Vue.axios.put(
+ "/api/v2/admin/creators/" + creatorId + "/localized-names/ja",
+ {displayName}
+ )
+}
+
async function getCreatorAllList() {
return Vue.axios.get("/admin/member/creator/all/list")
}
@@ -90,6 +97,7 @@ export {
getCreatorList,
searchCreator,
updateMember,
+ updateCreatorLocalizedNameJa,
getCreatorAllList,
resetPassword,
blockMember,
diff --git a/src/views/Creator/CreatorList.vue b/src/views/Creator/CreatorList.vue
index 26db57c..6906dba 100644
--- a/src/views/Creator/CreatorList.vue
+++ b/src/views/Creator/CreatorList.vue
@@ -66,9 +66,15 @@
이용중지/탈퇴일
|
+
+ 일본어 표시 이름
+ |
공유
|
+
+ 관리
+ |
@@ -113,6 +119,7 @@
{{ item.signUpDate }} |
{{ item.signOutDate }} |
+ {{ japaneseNameOf(item) || '미등록' }} |
|
+
+
+ 수정
+
+ |
@@ -138,6 +153,118 @@
+
+
+
+
+ 계정 상세
+
+
+
+ 이메일 :
+
+
+ {{ email }}
+
+
+
+
+
+
+ 원본 이름 :
+
+
+ {{ nickname }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 권한
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 취소
+
+
+ 수정
+
+
+
+
+
+
+
+
+
+
@@ -151,23 +278,45 @@ export default {
data() {
return {
is_loading: false,
+ is_saving: false,
+ is_composing: false,
page: 1,
total_page: 0,
total_creator_count: 0,
search_word: '',
accounts: [],
account: {},
+ member: null,
+ email: null,
+ nickname: null,
+ user_type: null,
+ japanese_display_name: '',
+ japanese_display_name_initial: '',
+ japanese_display_name_error: '',
+ show_popup_dialog: false,
utm_source: '',
utm_medium: '',
utm_campaign: '',
}
},
+ computed: {
+ japanese_display_name_hint() {
+ return this.japanese_display_name_initial.length === 0
+ ? '일본어 표시 이름이 등록되지 않았습니다. 비워두면 해제됩니다.'
+ : '비워두면 일본어 표시 이름이 해제됩니다.'
+ },
+ },
+
async created() {
await this.getAccounts()
},
methods: {
+ japaneseNameOf(item) {
+ return (item && item.localizedNames && item.localizedNames.ja) || ''
+ },
+
notifyError(message) {
this.$dialog.notify.error(message)
},
@@ -247,6 +396,135 @@ export default {
}
},
+ showPopupDialog(account) {
+ this.member = account
+
+ if (account.userType === '일반회원') {
+ this.user_type = 'USER'
+ } else if (account.userType === '에이전트') {
+ this.user_type = 'AGENT'
+ } else if (account.userType === '콘텐츠 관리자') {
+ this.user_type = 'CONTENT_MANAGER'
+ } else {
+ this.user_type = 'CREATOR'
+ }
+
+ this.email = account.email
+ this.nickname = account.nickname
+ this.japanese_display_name_initial = this.japaneseNameOf(account)
+ this.japanese_display_name = this.japanese_display_name_initial
+ this.japanese_display_name_error = ''
+ this.is_composing = false
+
+ this.show_popup_dialog = true
+ },
+
+ cancel() {
+ this.member = null
+ this.email = null
+ this.nickname = null
+ this.user_type = null
+ this.japanese_display_name = ''
+ this.japanese_display_name_initial = ''
+ this.japanese_display_name_error = ''
+ this.is_composing = false
+ this.show_popup_dialog = false
+ },
+
+ submitByEnter() {
+ if (this.is_composing || this.is_saving) return
+ this.modify()
+ },
+
+ async modify() {
+ if (this.is_saving) return
+
+ const value = this.japanese_display_name || ''
+ if (Array.from(value).length > 255) {
+ this.japanese_display_name_error = '일본어 표시 이름은 255자 이내로 입력하세요.'
+ return
+ }
+ this.japanese_display_name_error = ''
+
+ const target = this.member
+ const is_name_changed = value !== this.japanese_display_name_initial
+ const is_user_type_changed = !(
+ (this.user_type === 'CREATOR' && target.userType === '크리에이터') ||
+ (this.user_type === 'USER' && target.userType === '일반회원') ||
+ (this.user_type === 'AGENT' && target.userType === '에이전트') ||
+ (this.user_type === 'CONTENT_MANAGER' && target.userType === '콘텐츠 관리자')
+ )
+
+ if (!is_name_changed && !is_user_type_changed) {
+ this.notifyError('변경사항이 없습니다.')
+ return
+ }
+
+ this.is_saving = true
+ try {
+ if (is_name_changed) {
+ const res = await api.updateCreatorLocalizedNameJa(target.id, value)
+ if (res.status === 200 && res.data.success === true) {
+ this.applyJapaneseName(target.id, res.data.data.displayName)
+ if (this.member && this.member.id === target.id) {
+ this.japanese_display_name_initial = res.data.data.displayName || ''
+ }
+ this.notifySuccess('일본어 표시 이름이 저장되었습니다.')
+ } else {
+ if (res.data.errorProperty === 'displayName') {
+ this.japanese_display_name_error = res.data.message || '일본어 표시 이름을 저장하지 못했습니다.'
+ }
+ this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
+ return
+ }
+ }
+
+ if (is_user_type_changed) {
+ const res = await api.updateMember(target.id, this.user_type)
+ if (res.status === 200 && res.data.success === true) {
+ this.notifySuccess('수정되었습니다.')
+ if (this.member && this.member.id === target.id) {
+ this.cancel()
+ }
+ await this.refreshList()
+ } else {
+ this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
+ }
+ return
+ }
+
+ if (this.member && this.member.id === target.id) {
+ this.cancel()
+ }
+ } catch (e) {
+ this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
+ } finally {
+ this.is_saving = false
+ }
+ },
+
+ applyJapaneseName(id, displayName) {
+ const account = this.accounts.find(item => item.id === id)
+ if (!account) return
+
+ const localizedNames = { ...(account.localizedNames || {}) }
+ if (displayName === null || displayName === undefined || displayName === '') {
+ delete localizedNames.ja
+ } else {
+ localizedNames.ja = displayName
+ }
+
+ this.$set(account, 'localizedNames', localizedNames)
+ },
+
+ async refreshList() {
+ if (this.search_word.length >= 2) {
+ await this.searchAccount()
+ } else {
+ await this.getAccounts()
+ }
+ },
+
async shareCreatorChannel(item) {
this.is_loading = true
try {
diff --git a/tests/creator_localized_name.test.js b/tests/creator_localized_name.test.js
new file mode 100644
index 0000000..da7e5f6
--- /dev/null
+++ b/tests/creator_localized_name.test.js
@@ -0,0 +1,226 @@
+const assert = require('assert').strict
+const fs = require('fs')
+const path = require('path')
+const Module = require('module')
+const { transformSync } = require('@babel/core')
+const compiler = require('vue-template-compiler')
+const Vue = require('vue')
+
+const root = path.resolve(__dirname, '..')
+const originalResolve = Module._resolveFilename
+Module._resolveFilename = function(request, parent, ...rest) {
+ return originalResolve.call(this, request.startsWith('@/') ? path.join(root, 'src', request.slice(2)) : request, parent, ...rest)
+}
+const originalJs = require.extensions['.js']
+function compileScript(source, filename) {
+ return transformSync(source, {
+ filename,
+ babelrc: false,
+ configFile: false,
+ plugins: ['@babel/plugin-transform-modules-commonjs']
+ }).code
+}
+require.extensions['.js'] = (module, filename) => {
+ if (!filename.startsWith(path.join(root, 'src') + path.sep)) return originalJs(module, filename)
+ module._compile(compileScript(fs.readFileSync(filename, 'utf8'), filename), filename)
+}
+require.extensions['.vue'] = (module, filename) => {
+ const { script, template } = compiler.parseComponent(fs.readFileSync(filename, 'utf8'))
+ const compiled = compiler.compile(template.content)
+ assert.deepEqual(compiled.errors, [], `${filename}: 템플릿 컴파일`)
+ module._compile(compileScript(script.content, filename), filename)
+ Object.assign(module.exports.default, compiler.compileToFunctions(template.content))
+}
+
+const api = require('../src/api/member')
+const CreatorList = require('../src/views/Creator/CreatorList.vue').default
+const tests = []
+const test = (name, run) => tests.push({ name, run })
+
+const creator = (overrides = {}) => ({
+ id: 123, email: 'a@b.c', nickname: '하늘', userType: '크리에이터', container: 'aos', ...overrides
+})
+
+function page(accounts = [creator()]) {
+ const errors = []
+ const successes = []
+ const vm = new Vue({ ...CreatorList, created: undefined })
+ vm.$dialog = { notify: { error: message => errors.push(message), success: message => successes.push(message) } }
+ vm.accounts = accounts
+ return { vm, errors, successes }
+}
+
+function deferred() {
+ let resolve
+ const promise = new Promise(done => { resolve = done })
+ return { promise, resolve }
+}
+
+const ok = displayName => ({ status: 200, data: { success: true, message: null, data: { creatorId: 123, locale: 'ja', originalNickname: '하늘', displayName }, errorProperty: null } })
+
+test('API: JA 표시 이름은 정확한 PUT 경로와 displayName 본문만 전송한다', async () => {
+ const calls = []
+ Vue.axios = { put: async (...args) => { calls.push(args); return ok('ソラ') } }
+ await api.updateCreatorLocalizedNameJa(123, 'ソラ')
+ await api.updateCreatorLocalizedNameJa(123, '')
+ assert.deepEqual(calls, [
+ ['/api/v2/admin/creators/123/localized-names/ja', { displayName: 'ソラ' }],
+ ['/api/v2/admin/creators/123/localized-names/ja', { displayName: '' }]
+ ])
+ assert.equal(typeof api.updateCreatorLocalizedNameJa, 'function')
+})
+
+test('초안: JA 없음은 빈 입력, 있음은 등록값으로 초기화하고 원본을 복사하지 않는다', () => {
+ const { vm } = page()
+ vm.showPopupDialog(creator({ localizedNames: {} }))
+ assert.equal(vm.japanese_display_name, '')
+ assert.equal(vm.nickname, '하늘')
+ assert.ok(vm.japanese_display_name_hint.includes('등록되지 않았습니다'))
+
+ vm.japanese_display_name = '편집중'
+ vm.japanese_display_name_error = '이전 오류'
+ vm.showPopupDialog(creator({ id: 7, nickname: 'Sky', localizedNames: { ja: 'ソラ', en: 'Sky' } }))
+ assert.equal(vm.japanese_display_name, 'ソラ')
+ assert.equal(vm.japanese_display_name_error, '')
+ assert.equal(vm.nickname, 'Sky')
+})
+
+test('검증: code point 255 허용, 256 및 공백 256 차단, 자동 잘라내기 없음', async () => {
+ const { vm, errors } = page()
+ Vue.axios = { put: async () => { throw new Error('호출되면 안 됨') } }
+ for (const value of ['😀'.repeat(256), ' '.repeat(256)]) {
+ vm.showPopupDialog(creator({ localizedNames: {} }))
+ vm.japanese_display_name = value
+ await vm.modify()
+ assert.ok(vm.japanese_display_name_error.length > 0)
+ assert.equal(vm.japanese_display_name, value)
+ assert.equal(vm.show_popup_dialog, true)
+ }
+ assert.deepEqual(errors, [])
+
+ const calls = []
+ Vue.axios = { put: async (...args) => { calls.push(args); return ok('😀'.repeat(255)) } }
+ vm.showPopupDialog(creator({ localizedNames: {} }))
+ vm.japanese_display_name = '😀'.repeat(255)
+ await vm.modify()
+ assert.equal(calls.length, 1)
+ assert.equal(vm.japanese_display_name_error, '')
+})
+
+test('저장: 공백·이모지를 가공 없이 전송하고 성공 시 JA만 갱신한다', async () => {
+ const calls = []
+ Vue.axios = { put: async (...args) => { calls.push(args); return ok(' 手動 Name 😀 ') } }
+ const account = creator({ localizedNames: { en: 'Sky' } })
+ const { vm, successes } = page([account])
+ vm.showPopupDialog(account)
+ vm.japanese_display_name = ' 手動 Name 😀 '
+ await vm.modify()
+ assert.deepEqual(calls[0][1], { displayName: ' 手動 Name 😀 ' })
+ assert.deepEqual(account.localizedNames, { en: 'Sky', ja: ' 手動 Name 😀 ' })
+ assert.equal(account.nickname, '하늘')
+ assert.equal(successes.length, 1)
+ assert.equal(vm.show_popup_dialog, false)
+
+ vm.showPopupDialog(account)
+ assert.equal(vm.japanese_display_name, ' 手動 Name 😀 ')
+})
+
+test('해제: 빈 문자열을 전송하고 null 응답에서 JA 키만 제거한다', async () => {
+ const calls = []
+ Vue.axios = { put: async (...args) => { calls.push(args); return ok(null) } }
+ const account = creator({ localizedNames: { ja: 'ソラ', en: 'Sky' } })
+ const { vm } = page([account])
+ vm.showPopupDialog(account)
+ vm.japanese_display_name = ''
+ await vm.modify()
+ assert.deepEqual(calls[0][1], { displayName: '' })
+ assert.deepEqual(account.localizedNames, { en: 'Sky' })
+ vm.showPopupDialog(account)
+ assert.equal(vm.japanese_display_name, '')
+ assert.ok(vm.japanese_display_name_hint.includes('등록되지 않았습니다'))
+})
+
+test('실패: success false에서 서버 메시지·필드 오류와 입력을 유지하고 저장 상태를 바꾸지 않는다', async () => {
+ Vue.axios = { put: async () => ({ status: 200, data: { success: false, message: '서버 오류 메시지', data: null, errorProperty: 'displayName' } }) }
+ const account = creator({ localizedNames: { ja: 'ソラ' } })
+ const { vm, errors, successes } = page([account])
+ vm.showPopupDialog(account)
+ vm.japanese_display_name = '新しい'
+ await vm.modify()
+ assert.deepEqual(errors, ['서버 오류 메시지'])
+ assert.deepEqual(successes, [])
+ assert.equal(vm.japanese_display_name_error, '서버 오류 메시지')
+ assert.equal(vm.japanese_display_name, '新しい')
+ assert.equal(vm.show_popup_dialog, true)
+ assert.deepEqual(account.localizedNames, { ja: 'ソラ' })
+
+ Vue.axios = { put: async () => { throw new Error('network') } }
+ await vm.modify()
+ assert.equal(vm.japanese_display_name, '新しい')
+ assert.deepEqual(account.localizedNames, { ja: 'ソラ' })
+ assert.equal(vm.is_saving, false)
+})
+
+test('상호작용: 취소는 무요청, 중복 저장 방지, IME 조합 중 Enter 제출 차단', async () => {
+ const account = creator({ localizedNames: {} })
+ const { vm, errors } = page([account])
+ Vue.axios = { put: async () => { throw new Error('호출되면 안 됨') } }
+ vm.showPopupDialog(account)
+ vm.japanese_display_name = 'ソラ'
+ vm.cancel()
+ assert.equal(vm.show_popup_dialog, false)
+ assert.equal(vm.japanese_display_name, '')
+ assert.deepEqual(errors, [])
+
+ const gate = deferred()
+ let count = 0
+ Vue.axios = { put: async () => { count += 1; await gate.promise; return ok('ソラ') } }
+ vm.showPopupDialog(account)
+ vm.japanese_display_name = 'ソラ'
+ const first = vm.modify()
+ await vm.modify()
+ vm.is_composing = true
+ vm.submitByEnter()
+ gate.resolve()
+ await first
+ assert.equal(count, 1)
+})
+
+test('대상 보호: 응답은 요청한 ID에만 적용하고 다른 항목을 덮어쓰지 않는다', async () => {
+ const first = creator({ id: 1, localizedNames: {} })
+ const second = creator({ id: 2, localizedNames: { ja: '他' } })
+ const { vm } = page([first, second])
+ const gate = deferred()
+ Vue.axios = { put: async () => { await gate.promise; return { status: 200, data: { success: true, message: null, data: { creatorId: 1, locale: 'ja', originalNickname: '하늘', displayName: 'ソラ' }, errorProperty: null } } } }
+ vm.showPopupDialog(first)
+ vm.japanese_display_name = 'ソラ'
+ const saving = vm.modify()
+ vm.showPopupDialog(second)
+ gate.resolve()
+ await saving
+ assert.deepEqual(first.localizedNames, { ja: 'ソラ' })
+ assert.deepEqual(second.localizedNames, { ja: '他' })
+ assert.equal(vm.japanese_display_name, '他')
+})
+
+test('목록: JA 미등록은 미등록으로 표시하고 수정 버튼을 노출한다', () => {
+ const { vm } = page([creator({ localizedNames: {} }), creator({ id: 2, localizedNames: { ja: 'ソラ' } })])
+ assert.equal(vm.japaneseNameOf(vm.accounts[0]), '')
+ assert.equal(vm.japaneseNameOf(vm.accounts[1]), 'ソラ')
+ const source = fs.readFileSync(path.join(root, 'src/views/Creator/CreatorList.vue'), 'utf8')
+ assert.ok(source.includes('showPopupDialog(item)'))
+ assert.ok(!source.includes('maxlength="255"'))
+ assert.ok(!source.includes('v-model.trim="japanese_display_name"'))
+})
+
+;(async () => {
+ for (const { name, run } of tests) {
+ try {
+ await run()
+ console.log(`PASS ${name}`)
+ } catch (error) {
+ process.exitCode = 1
+ console.error(`FAIL ${name}`, error)
+ }
+ }
+})()