Normalize JSON response structure

This commit is contained in:
Pig Fang 2019-04-23 11:47:45 +08:00
parent 6507f2699f
commit 0486ddc5a1
73 changed files with 608 additions and 607 deletions

View File

@ -461,8 +461,8 @@ class AdminController extends Controller
$user->save();
return json([
'errno' => 0,
'msg' => trans('admin.users.operations.permission'),
'code' => 0,
'message' => trans('admin.users.operations.permission'),
]);
} elseif ($action == 'delete') {
$user->delete();

View File

@ -155,8 +155,8 @@ class AuthController extends Controller
Auth::login($user);
return json([
'errno' => 0,
'msg' => trans('auth.register.success'),
'code' => 0,
'message' => trans('auth.register.success'),
]);
}
@ -191,8 +191,8 @@ class AuthController extends Controller
// Rate limit
if ($remain > 0) {
return json([
'errno' => 2,
'msg' => trans('auth.forgot.frequent-mail'),
'code' => 2,
'message' => trans('auth.forgot.frequent-mail'),
'remain' => $remain,
]);
}

View File

@ -43,8 +43,8 @@ class PluginController extends Controller
}
return json([
'errno' => 1,
'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
'code' => 1,
'message' => trans('admin.plugins.operations.unsatisfied.notice'),
'reason' => $reason,
]);
}

View File

@ -341,8 +341,8 @@ class SkinlibController extends Controller
$t->save();
return json([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => (! $t->public ? trans('general.private') : trans('general.public'))]),
'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => (! $t->public ? trans('general.private') : trans('general.public'))]),
'public' => $t->public,
]);
}

View File

@ -95,8 +95,8 @@ class UserController extends Controller
$gap = option('sign_gap_time');
return json([
'errno' => 0,
'msg' => trans('user.sign-success', ['score' => $acquiredScore]),
'code' => 0,
'message' => trans('user.sign-success', ['score' => $acquiredScore]),
'score' => $user->score,
'storage' => $this->calculatePercentageUsed($user->getStorageUsed(), option('score_per_storage')),
'remaining_time' => $gap > 1 ? round($gap) : $gap,
@ -252,8 +252,8 @@ class UserController extends Controller
return response()
->json([
'errno' => 0,
'msg' => trans('user.profile.delete.success'),
'code' => 0,
'message' => trans('user.profile.delete.success'),
]);
}

View File

@ -13,8 +13,8 @@ class CheckPlayerExist
if ($request->has('pid') && $request->isMethod('post')) {
if (is_null(Player::find($request->input('pid')))) {
return response()->json([
'errno' => 1,
'msg' => trans('general.unexistent-player'),
'code' => 1,
'message' => trans('general.unexistent-player'),
]);
} else {
return $next($request);

View File

@ -21,8 +21,8 @@ class CheckPlayerOwner
if ($player->uid != auth()->id()) {
return response()->json([
'errno' => 1,
'msg' => trans('admin.players.no-permission'),
'code' => 1,
'message' => trans('admin.players.no-permission'),
]);
}
}

View File

@ -51,13 +51,13 @@ if (! function_exists('json')) {
} elseif (count($args) == 3 && is_array($args[2])) {
// The third argument is array of extra fields
return Response::json(array_merge([
'errno' => $args[1],
'msg' => $args[0],
'code' => $args[1],
'message' => $args[0],
], $args[2]));
} else {
return Response::json([
'errno' => Arr::get($args, 1, 1),
'msg' => $args[0],
'code' => Arr::get($args, 1, 1),
'message' => $args[0],
]);
}
}

View File

@ -60,16 +60,16 @@ export default {
},
methods: {
async addPlayer() {
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/add',
{ player_name: this.name }
)
if (errno === 0) {
if (code === 0) {
$('#modal-add-player').modal('hide')
this.$message.success(msg)
this.$message.success(message)
this.$emit('add')
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -82,7 +82,7 @@ export default {
return this.$message.info(this.$t('user.emptySelectedTexture'))
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/set',
{
pid: this.selected,
@ -92,11 +92,11 @@ export default {
},
}
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
$('#modal-use-as').modal('hide')
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
avatarUrl(player) {

View File

@ -86,15 +86,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/closet/rename',
{ tid: this.tid, new_name: newTextureName }
)
if (errno === 0) {
if (code === 0) {
this.textureName = newTextureName
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -26,11 +26,11 @@ export default {
methods: {
async resend() {
this.pending = true
const { errno, msg } = await this.$http.post('/user/email-verification')
if (errno === 0) {
this.$message.success(msg)
const { code, message } = await this.$http.post('/user/email-verification')
if (code === 0) {
this.$message.success(message)
} else {
this.$message.error(msg)
this.$message.error(message)
}
this.pending = false
},

View File

@ -22,15 +22,15 @@ export default Vue.extend<{
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/closet/add',
{ tid: this.tid, name: value }
)
if (errno === 0) {
this.$message.success(msg!)
if (code === 0) {
this.$message.success(message!)
this.$emit('like-toggled', true)
} else {
this.$message.warning(msg!)
this.$message.warning(message!)
}
},
},

View File

@ -22,18 +22,18 @@ export default Vue.extend({
}
const {
errno, msg, reason,
code, message, reason,
} = await this.$http.post(
'/admin/plugins/manage',
{ action: 'enable', name }
) as { errno: number, msg: string, reason: string[] }
if (errno === 0) {
this.$message.success(msg)
) as { code: number, message: string, reason: string[] }
if (code === 0) {
this.$message.success(message)
this.$set(this.plugins[originalIndex], 'enabled', true)
} else {
const div = document.createElement('div')
const p = document.createElement('p')
p.textContent = msg
p.textContent = message
div.appendChild(p)
const ul = document.createElement('ul')
reason.forEach(item => {

View File

@ -15,15 +15,15 @@ export default Vue.extend<{
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/closet/remove',
{ tid: this.tid }
)
if (errno === 0) {
if (code === 0) {
this.$emit('item-removed')
this.$message.success(msg!)
this.$message.success(message!)
} else {
this.$message.warning(msg!)
this.$message.warning(message!)
}
},
},

View File

@ -14,17 +14,17 @@ export default Vue.extend<{
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/profile/avatar',
{ tid: this.tid }
)
if (errno === 0) {
this.$message.success(msg!)
if (code === 0) {
this.$message.success(message!)
Array.from(document.querySelectorAll<HTMLImageElement>('[alt="User Image"]'))
.forEach(el => (el.src += `?${new Date().getTime()}`))
} else {
this.$message.warning(msg!)
this.$message.warning(message!)
}
},
},

View File

@ -11,9 +11,9 @@ export async function logout() {
return
}
const { msg } = await post('/auth/logout')
const { message } = await post('/auth/logout')
setTimeout(() => (window.location.href = blessing.base_url), 1000)
Message.success(msg)
Message.success(message)
}
const button = document.querySelector('#logout-button')

View File

@ -43,8 +43,8 @@ export async function walkFetch(request: Request): Promise<any> {
errors: { [field: string]: string[] }
} = await response.json()
return {
errno: 1,
msg: Object.keys(errors).map(field => errors[field][0])[0],
code: 1,
message: Object.keys(errors).map(field => errors[field][0])[0],
}
}

View File

@ -8,7 +8,7 @@ export function showAjaxError(error: Error): void {
}
export function showModal(
msg: string, title = 'Message',
message: string, title = 'Message',
type = 'default',
options: ModalOptions = {}
): void {
@ -30,7 +30,7 @@ export function showModal(
<h4 class="modal-title">${title}</h4>
</div>
<div class="modal-body">
<p>${msg}</p>
<p>${message}</p>
</div>
<div class="modal-footer">
<button type="button" ${onClick} class="btn ${btnType}">${btnText}</button>

View File

@ -45,7 +45,7 @@ declare module 'vue/types/vue' {
$http: {
get(url: string, params?: object)
post(url: string, data?: object): { errno?: number, msg?: string }
post(url: string, data?: object): { code?: number, message?: string }
}
$route: string[]

View File

@ -49,10 +49,10 @@ export default {
this.currentSkin = `skin-${color}`
},
async submit() {
const { msg } = await this.$http.post('/admin/customize?action=color', {
const { message } = await this.$http.post('/admin/customize?action=color', {
color_scheme: this.currentSkin,
})
this.$message.success(msg)
this.$message.success(message)
},
},
}

View File

@ -140,16 +140,16 @@ export default {
async installPlugin({ name, originalIndex }) {
this.installing = name
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/plugins/market/download',
{ name }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
this.plugins[originalIndex].update_available = false
this.plugins[originalIndex].installed = true
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
this.installing = ''

View File

@ -174,18 +174,18 @@ export default {
const player = this.players[this.textureChanges.originalIndex]
const { type, tid } = this.textureChanges
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/players?action=texture',
{
pid: player.pid, type, tid,
}
)
if (errno === 0) {
if (code === 0) {
player[`tid_${type}`] = tid
this.$message.success(msg)
this.$message.success(message)
$('.modal').modal('hide')
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async changeName(player) {
@ -199,15 +199,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/players?action=name',
{ pid: player.pid, name: value }
)
if (errno === 0) {
if (code === 0) {
player.name = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async changeOwner(player) {
@ -220,15 +220,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/players?action=owner',
{ pid: player.pid, uid: value }
)
if (errno === 0) {
if (code === 0) {
player.uid = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async deletePlayer({ pid, originalIndex }) {
@ -240,15 +240,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/players?action=delete',
{ pid }
)
if (errno === 0) {
if (code === 0) {
this.$delete(this.players, originalIndex)
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -128,15 +128,15 @@ export default {
return row.enabled ? 'plugin-enabled' : 'plugin'
},
async disablePlugin({ name, originalIndex }) {
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/plugins/manage',
{ action: 'disable', name }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
this.plugins[originalIndex].enabled = false
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async deletePlugin({ name, originalIndex }) {
@ -146,15 +146,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/plugins/manage',
{ action: 'delete', name }
)
if (errno === 0) {
if (code === 0) {
this.$delete(this.plugins, originalIndex)
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -122,16 +122,16 @@ export default {
},
async resolve(report, action) {
const {
errno, msg, status,
code, message, status,
} = await this.$http.post(
'/admin/reports',
{ id: report.id, action }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
report.status = status
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -60,13 +60,13 @@ export default {
})
setTimeout(() => this.polling(), POLLING_INTERVAL)
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/update/download',
{ action: 'download' }
)
this.updating = false
if (errno) {
this.$alert(msg, { type: 'error' })
if (code) {
this.$alert(message, { type: 'error' })
return
}
await this.$alert(this.$t('admin.updateCompleted'), { type: 'success' })

View File

@ -174,27 +174,27 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=email',
{ uid: user.uid, email: value }
)
if (errno === 0) {
if (code === 0) {
user.email = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async toggleVerification(user) {
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=verification',
{ uid: user.uid }
)
if (errno === 0) {
if (code === 0) {
user.verified = !user.verified
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async changeNickName(user) {
@ -208,15 +208,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=nickname',
{ uid: user.uid, nickname: value }
)
if (errno === 0) {
if (code === 0) {
user.nickname = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async changePassword(user) {
@ -229,11 +229,11 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=password',
{ uid: user.uid, password: value }
)
errno === 0 ? this.$message.success(msg) : this.$message.warning(msg)
code === 0 ? this.$message.success(message) : this.$message.warning(message)
},
async changeScore(user) {
let value
@ -247,15 +247,15 @@ export default {
}
const score = Number.parseInt(value)
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=score',
{ uid: user.uid, score }
)
if (errno === 0) {
if (code === 0) {
user.score = score
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async changePermission(user) {
@ -287,15 +287,15 @@ export default {
}
const value = vnode.children[1].elm.selectedIndex - 1
const { errno, msg } = await this.$http.post('/admin/users?action=permission', {
const { code, message } = await this.$http.post('/admin/users?action=permission', {
uid: user.uid,
permission: value,
})
if (errno === 0) {
if (code === 0) {
user.permission = +value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async deleteUser({ uid, originalIndex }) {
@ -307,15 +307,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/admin/users?action=delete',
{ uid }
)
if (errno === 0) {
if (code === 0) {
this.$delete(this.users, originalIndex)
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -76,18 +76,18 @@ export default {
}
this.pending = true
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/auth/forgot',
{ email, captcha: await this.$refs.captcha.execute() }
)
if (errno === 0) {
if (code === 0) {
this.infoMsg = ''
this.warningMsg = ''
this.successMsg = msg
this.successMsg = message
this.pending = false
} else {
this.infoMsg = ''
this.warningMsg = msg
this.warningMsg = message
this.pending = false
this.$refs.captcha.refresh()
}

View File

@ -99,7 +99,7 @@ export default {
this.pending = true
const {
errno, msg, login_fails: loginFails,
code, message, login_fails: loginFails,
} = await this.$http.post(
'/auth/login',
{
@ -111,8 +111,8 @@ export default {
: void 0,
}
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
setTimeout(() => {
window.location = `${blessing.base_url}/${blessing.redirect_to || 'user'}`
}, 1000)
@ -128,7 +128,7 @@ export default {
this.tooManyFails = true
}
this.infoMsg = ''
this.warningMsg = msg
this.warningMsg = message
this.pending = false
this.$refs.captcha.refresh()
}

View File

@ -164,7 +164,7 @@ export default {
}
this.pending = true
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/auth/register',
Object.assign({
email,
@ -172,14 +172,14 @@ export default {
captcha: await this.$refs.captcha.execute(),
}, this.requirePlayer ? { player_name: playerName } : { nickname })
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
setTimeout(() => {
window.location = `${blessing.base_url}/user`
}, 1000)
} else {
this.infoMsg = ''
this.warningMsg = msg
this.warningMsg = message
this.$refs.captcha.refresh()
this.pending = false
}

View File

@ -79,16 +79,16 @@ export default {
}
this.pending = true
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
`/auth/reset/${this.uid}${location.search}`,
{ password }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
window.location = `${blessing.base_url}/auth/login`
} else {
this.infoMsg = ''
this.warningMsg = msg
this.warningMsg = message
this.pending = false
}
},

View File

@ -262,15 +262,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/skinlib/rename',
{ tid: this.tid, new_name: value }
)
if (errno === 0) {
if (code === 0) {
this.name = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.error(msg)
this.$message.error(message)
}
},
async changeModel() {
@ -293,15 +293,15 @@ export default {
}
const value = ['steve', 'alex', 'cape'][vnode.children[1].elm.selectedIndex]
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/skinlib/model',
{ tid: this.tid, model: value }
)
if (errno === 0) {
if (code === 0) {
this.type = value
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async togglePrivacy() {
@ -316,15 +316,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/skinlib/privacy',
{ tid: this.tid }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
this.public = !this.public
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async deleteTexture() {
@ -337,19 +337,19 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/skinlib/delete',
{ tid: this.tid }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
setTimeout(() => (window.location = `${this.baseUrl}/skinlib`), 1000)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async report() {
const message = (() => {
const prompt = (() => {
if (this.reportScore > 0) {
return this.$t('skinlib.report.positive', { score: this.reportScore })
} else if (this.reportScore < 0) {
@ -359,7 +359,7 @@ export default {
})()
let reason
try {
({ value: reason } = await this.$prompt(message, {
({ value: reason } = await this.$prompt(prompt, {
title: this.$t('skinlib.report.title'),
inputPlaceholder: this.$t('skinlib.report.reason'),
}))
@ -367,14 +367,14 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/skinlib/report',
{ tid: this.tid, reason }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
fetchPlayersList() {

View File

@ -160,15 +160,15 @@ export default {
this.uploading = true
const {
errno, msg, tid,
code, message, tid,
} = await this.$http.post('/skinlib/upload', data)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
setTimeout(() => {
window.location = `${blessing.base_url}/skinlib/show/${tid}`
}, 1000)
} else {
this.$message.error(msg)
this.$message.error(message)
this.uploading = false
}
},

View File

@ -55,16 +55,16 @@ export default {
},
async submit() {
this.pending = true
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/bind',
{ player: this.selected }
)
this.pending = false
if (errno === 0) {
await this.$alert(msg)
if (code === 0) {
await this.$alert(message)
window.location.href = `${blessing.base_url}/user`
} else {
this.message = msg
this.message = message
}
},
},

View File

@ -189,14 +189,14 @@ export default {
async sign() {
const result = await this.$http.post('/user/sign')
if (result.errno === 0) {
this.$message.success(result.msg)
if (result.code === 0) {
this.$message.success(result.message)
this.score = result.score
this.lastSignAt = new Date()
this.storageUsed = result.storage.used
this.storageTotal = result.storage.total
} else {
this.$message.warning(result.msg)
this.$message.warning(result.message)
}
},
},

View File

@ -230,15 +230,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/rename',
{ pid: player.pid, new_player_name: value }
)
if (errno === 0) {
this.$message.success(msg)
if (code === 0) {
this.$message.success(message)
player.name = value
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async clearTexture() {
@ -246,19 +246,19 @@ export default {
return this.$message.warning(this.$t('user.noClearChoice'))
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/texture/clear',
Object.assign({ pid: this.selected }, this.clear)
)
if (errno === 0) {
if (code === 0) {
$('.modal').modal('hide')
this.$message.success(msg)
this.$message.success(message)
const player = this.players.find(({ pid }) => pid === this.selected)
Object.keys(this.clear)
.filter(type => this.clear[type])
.forEach(type => (player[`tid_${type}`] = 0))
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
async deletePlayer(player, index) {
@ -271,15 +271,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/player/delete',
{ pid: player.pid }
)
if (errno === 0) {
if (code === 0) {
this.$delete(this.players, index)
this.$message.success(msg)
this.$message.success(message)
} else {
this.$message.warning(msg)
this.$message.warning(message)
}
},
},

View File

@ -216,11 +216,11 @@ export default {
return
}
const { msg } = await this.$http.post(
const { message } = await this.$http.post(
'/user/profile/avatar',
{ tid: 0 }
)
this.$message.success(msg)
this.$message.success(message)
Array.from(document.querySelectorAll('[alt="User Image"]'))
.forEach(el => (el.src += `?${new Date().getTime()}`))
},
@ -253,15 +253,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/profile?action=password',
{ current_password: oldPassword, new_password: newPassword }
)
if (errno === 0) {
await this.$alert(msg)
if (code === 0) {
await this.$alert(message)
return (window.location = `${blessing.base_url}/auth/login`)
}
return this.$alert(msg, { type: 'warning' })
return this.$alert(message, { type: 'warning' })
},
async changeNickName() {
const { nickname } = this
@ -276,16 +276,16 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/profile?action=nickname',
{ new_nickname: nickname }
)
if (errno === 0) {
if (code === 0) {
Array.from(document.querySelectorAll('.nickname'))
.forEach(el => (el.textContent = nickname))
return this.$message.success(msg)
return this.$message.success(message)
}
return this.$alert(msg, { type: 'warning' })
return this.$alert(message, { type: 'warning' })
},
async changeEmail() {
const { email } = this
@ -304,15 +304,15 @@ export default {
return
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/profile?action=email',
{ new_email: email, password: this.currentPassword }
)
if (errno === 0) {
await this.$message.success(msg)
if (code === 0) {
await this.$message.success(message)
return (window.location = `${blessing.base_url}/auth/login`)
}
return this.$alert(msg, { type: 'warning' })
return this.$alert(message, { type: 'warning' })
},
async deleteAccount() {
const { deleteConfirm: password } = this
@ -321,15 +321,15 @@ export default {
return this.$alert(this.$t('user.emptyDeletePassword'), { type: 'error' })
}
const { errno, msg } = await this.$http.post(
const { code, message } = await this.$http.post(
'/user/profile?action=delete',
{ password }
)
if (errno === 0) {
await this.$alert(msg, { type: 'success' })
if (code === 0) {
await this.$alert(message, { type: 'success' })
window.location = `${blessing.base_url}/auth/login`
} else {
return this.$alert(msg, { type: 'warning' })
return this.$alert(message, { type: 'warning' })
}
},
},

View File

@ -12,8 +12,8 @@ test('add player', async () => {
window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValueOnce([])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValue({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(AddPlayerDialog)
const button = wrapper.find('[data-test=addPlayer]')
wrapper.find('input[type="text"]').setValue('the-new')

View File

@ -5,8 +5,8 @@ import ApplyToPlayerDialog from '@/components/ApplyToPlayerDialog.vue'
test('submit applying texture', async () => {
window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValue([{ pid: 1 }])
Vue.prototype.$http.post.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValue({ errno: 0, msg: 'ok' })
Vue.prototype.$http.post.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(ApplyToPlayerDialog)
const button = wrapper.find('[data-test=submit]')

View File

@ -36,8 +36,8 @@ test('click item body', () => {
test('rename texture', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 0 })
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValueOnce({ code: 0 })
.mockResolvedValueOnce({ code: 1 })
Vue.prototype.$prompt.mockImplementationOnce(() => Promise.reject(new Error()))
.mockImplementation((_, options) => {
if (options.inputValidator) {
@ -68,8 +68,8 @@ test('rename texture', async () => {
test('remove texture', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 0 })
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValueOnce({ code: 0 })
.mockResolvedValueOnce({ code: 1 })
Vue.prototype.$confirm
.mockRejectedValueOnce({})
.mockResolvedValue('confirm')
@ -93,8 +93,8 @@ test('remove texture', async () => {
test('set as avatar', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 0 })
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValueOnce({ code: 0 })
.mockResolvedValueOnce({ code: 1 })
Vue.prototype.$confirm
.mockRejectedValueOnce({})
.mockResolvedValue('confirm')

View File

@ -11,8 +11,8 @@ test('message box should not be render if verified', () => {
test('resend email', async () => {
window.blessing.extra = { unverified: true }
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(EmailVerification)
const button = wrapper.find('a')

View File

@ -59,7 +59,7 @@ test('liked state', () => {
})
test('remove from closet', async () => {
Vue.prototype.$http.post.mockResolvedValue({ errno: 0 })
Vue.prototype.$http.post.mockResolvedValue({ code: 0 })
Vue.prototype.$confirm.mockResolvedValue('confirm')
const wrapper = mount(SkinLibItem, {
propsData: {
@ -73,8 +73,8 @@ test('remove from closet', async () => {
test('add to closet', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0 })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0 })
Vue.prototype.$prompt
.mockImplementationOnce(() => Promise.reject())
.mockImplementation((_, { inputValidator }) => {

View File

@ -9,7 +9,7 @@ test('log out', async () => {
MessageBox.confirm
.mockRejectedValueOnce('cancel')
.mockResolvedValue('confirm')
post.mockResolvedValue({ msg: '' })
post.mockResolvedValue({ message: '' })
await logout()
expect(post).not.toBeCalled()

View File

@ -133,11 +133,11 @@ test('process Laravel validation errors', async () => {
})
const result: {
errno: number,
msg: string
code: number,
message: string
} = await net.walkFetch({ headers: new Headers() } as Request)
expect(result.errno).toBe(1)
expect(result.msg).toBe('required')
expect(result.code).toBe(1)
expect(result.message).toBe('required')
})
test('inject to Vue instance', () => {

View File

@ -14,7 +14,7 @@ test('preview color', () => {
})
test('submit color', () => {
Vue.prototype.$http.post.mockResolvedValue({ errno: 0, msg: '' })
Vue.prototype.$http.post.mockResolvedValue({ code: 0, message: '' })
const wrapper = mount(Customization)
wrapper.findAll('a').at(4)
.trigger('click')

View File

@ -53,8 +53,8 @@ test('install plugin', async () => {
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Market)
await flushPromises()
const button = wrapper.find('button')
@ -81,7 +81,7 @@ test('update plugin', async () => {
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ code: 1, message: '1' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')

View File

@ -24,8 +24,8 @@ test('change texture', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
@ -59,8 +59,8 @@ test('change player name', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockImplementationOnce(() => Promise.reject())
.mockImplementation((_, options) => {
@ -95,8 +95,8 @@ test('change owner', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockRejectedValueOnce('')
.mockResolvedValue({ value: '3' } as MessageBoxData)
@ -126,8 +126,8 @@ test('delete player', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')

View File

@ -57,9 +57,9 @@ test('enable plugin', async () => {
])
Vue.prototype.$http.post
.mockResolvedValueOnce({
errno: 1, msg: '1', reason: ['`a<div></div>`b'],
code: 1, message: '1', reason: ['`a<div></div>`b'],
})
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
@ -105,8 +105,8 @@ test('disable plugin', async () => {
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
const wrapper = mount(Plugins)
await flushPromises()
const button = wrapper.find('.actions').find('a')
@ -130,8 +130,8 @@ test('delete plugin', async () => {
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')

View File

@ -36,9 +36,9 @@ test('link to skin library', async () => {
test('delete texture', async () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] })
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({
errno: 0, msg: 'ok', status: 1,
code: 0, message: 'ok', status: 1,
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
@ -62,7 +62,7 @@ test('ban uploader', async () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] })
Vue.prototype.$http.post
.mockResolvedValue({
errno: 0, msg: 'ok', status: 1,
code: 0, message: 'ok', status: 1,
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
@ -82,7 +82,7 @@ test('reject', async () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] })
Vue.prototype.$http.post
.mockResolvedValue({
errno: 0, msg: 'ok', status: 2,
code: 0, message: 'ok', status: 2,
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()

View File

@ -17,7 +17,7 @@ test('perform update', async () => {
modal() {},
}))
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({})
const wrapper = mount(Update)
const button = wrapper.find('button')

View File

@ -235,8 +235,8 @@ test('change email', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockImplementationOnce(() => Promise.reject())
.mockImplementation((_, options) => {
@ -273,8 +273,8 @@ test('toggle verification', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
@ -298,8 +298,8 @@ test('change nickname', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockImplementationOnce(() => Promise.reject())
.mockImplementation((_, options) => {
@ -336,8 +336,8 @@ test('change password', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
Vue.prototype.$prompt
.mockRejectedValueOnce('')
.mockResolvedValue({ value: 'password' }as MessageBoxData)
@ -371,8 +371,8 @@ test('change score', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockRejectedValueOnce('')
.mockResolvedValue({ value: '45' }as MessageBoxData)
@ -414,8 +414,8 @@ test('change permission', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$msgbox
.mockImplementationOnce(() => Promise.reject())
.mockImplementationOnce(options => {
@ -473,8 +473,8 @@ test('delete user', async () => {
],
})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')

View File

@ -16,8 +16,8 @@ const Captcha = Vue.extend({
test('submit forgot form', async () => {
jest.spyOn(Date, 'now')
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Forgot, { stubs: { Captcha } })
const form = wrapper.find('form')
const info = wrapper.find('.callout-info')

View File

@ -21,11 +21,11 @@ test('show captcha if too many login fails', () => {
test('login', async () => {
window.blessing.extra = { tooManyFails: false }
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ errno: 1, login_fails: 4 })
.mockResolvedValueOnce({ errno: 1, login_fails: 4 })
.mockResolvedValueOnce({ errno: 1, login_fails: 4 })
.mockResolvedValueOnce({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 1, login_fails: 4 })
.mockResolvedValueOnce({ code: 1, login_fails: 4 })
.mockResolvedValueOnce({ code: 1, login_fails: 4 })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Login, { stubs: { Captcha } })
const form = wrapper.find('form')
const info = wrapper.find('.callout-info')

View File

@ -27,8 +27,8 @@ test('require player name', () => {
test('register', async () => {
jest.spyOn(Date, 'now')
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Register, { stubs: { Captcha } })
const form = wrapper.find('form')
const info = wrapper.find('.callout-info')
@ -96,7 +96,7 @@ test('register', async () => {
test('register with player name', async () => {
window.blessing.extra = { player: true }
Vue.prototype.$http.post.mockResolvedValue({ errno: 0, msg: 'ok' })
Vue.prototype.$http.post.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(Register, { stubs: { Captcha } })
const form = wrapper.find('form')
const info = wrapper.find('.callout-info')

View File

@ -4,8 +4,8 @@ import Reset from '@/views/auth/Reset.vue'
test('reset password', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Reset, {
mocks: {
$route: ['/auth/reset/1', '1'],

View File

@ -184,7 +184,7 @@ test('hide "set avatar" button when texture is cape', async () => {
test('add to closet', async () => {
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false })
Vue.prototype.$http.get.mockResolvedValue({ name: 'wow', likes: 2 })
Vue.prototype.$http.post.mockResolvedValue({ errno: 0, msg: '' })
Vue.prototype.$http.post.mockResolvedValue({ code: 0, message: '' })
Vue.prototype.$prompt.mockResolvedValue({ value: 'a' } as MessageBoxData)
const wrapper = mount<Component>(Show, {
mocks: {
@ -201,7 +201,7 @@ test('add to closet', async () => {
test('remove from closet', async () => {
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
Vue.prototype.$http.get.mockResolvedValue({ likes: 2 })
Vue.prototype.$http.post.mockResolvedValue({ errno: 0 })
Vue.prototype.$http.post.mockResolvedValue({ code: 0 })
const wrapper = mount<Component>(Show, {
mocks: {
$route: ['/skinlib/show/1', '1'],
@ -218,8 +218,8 @@ test('change texture name', async () => {
Object.assign(window.blessing.extra, { admin: true })
Vue.prototype.$http.get.mockResolvedValue({ name: 'old-name' })
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$prompt
.mockImplementationOnce(() => Promise.reject('cancel'))
.mockImplementation((_, { inputValidator }) => {
@ -256,8 +256,8 @@ test('change texture name', async () => {
test('change texture model', async () => {
Vue.prototype.$http.get.mockResolvedValue({ type: 'steve' })
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$msgbox
.mockImplementationOnce(() => Promise.reject())
.mockImplementation(options => {
@ -299,8 +299,8 @@ test('change texture model', async () => {
test('toggle privacy', async () => {
Vue.prototype.$http.get.mockResolvedValue({ public: true })
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
@ -338,8 +338,8 @@ test('toggle privacy', async () => {
test('delete texture', async () => {
Vue.prototype.$http.get.mockResolvedValue({})
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValue({ errno: 0, msg: '0' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
@ -374,8 +374,8 @@ test('delete texture', async () => {
test('report texture', async () => {
Vue.prototype.$http.get.mockResolvedValue({ report: 0 })
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'duplicated' })
.mockResolvedValue({ errno: 0, msg: 'success' })
.mockResolvedValueOnce({ code: 1, message: 'duplicated' })
.mockResolvedValue({ code: 0, message: 'success' })
Vue.prototype.$prompt
.mockRejectedValueOnce('')
.mockRejectedValueOnce('')

View File

@ -114,9 +114,9 @@ test('process input file', () => {
test('upload file', async () => {
(window as Window & { Request: jest.Mock }).Request = jest.fn()
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({
errno: 0, msg: '0', tid: 1,
code: 0, message: '0', tid: 1,
})
const wrapper = mount(Upload, {

View File

@ -22,8 +22,8 @@ test('show input box', async () => {
test('submit', async () => {
Vue.prototype.$http.get.mockResolvedValue([])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
.mockResolvedValueOnce({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Bind)
const form = wrapper.find('form')

View File

@ -140,9 +140,9 @@ test('sign', async () => {
user: { lastSignAt: Date.now() - 30 * 3600 * 1000 },
}))
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: '1' })
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({
errno: 0,
code: 0,
score: 233,
storage: { used: 3, total: 4 },
})

View File

@ -73,8 +73,8 @@ test('change player name', async () => {
{ pid: 1, name: 'old' },
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValue({ errno: 0 })
.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0 })
Vue.prototype.$prompt.mockImplementationOnce(() => Promise.reject('cancel'))
.mockImplementation((_, { inputValidator }) => {
if (inputValidator) {
@ -107,8 +107,8 @@ test('delete player', async () => {
{ pid: 1, name: 'to-be-deleted' },
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValue({ errno: 0 })
.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0 })
Vue.prototype.$confirm
.mockRejectedValueOnce({})
.mockResolvedValue('confirm')
@ -137,7 +137,7 @@ test('toggle preview mode', () => {
test('add player', async () => {
window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValueOnce([])
Vue.prototype.$http.post.mockResolvedValue({ errno: 0 })
Vue.prototype.$http.post.mockResolvedValue({ code: 0 })
const wrapper = mount(Players)
const button = wrapper.find('[data-test=addPlayer]')
@ -155,8 +155,8 @@ test('clear texture', async () => {
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1 })
.mockResolvedValue({ errno: 0, msg: 'ok' })
.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
const button = wrapper.find('[data-test=clearTexture]')

View File

@ -23,7 +23,7 @@ test('reset avatar', async () => {
Vue.prototype.$confirm
.mockRejectedValueOnce('close')
.mockResolvedValue('confirm')
Vue.prototype.$http.post.mockResolvedValue({ msg: 'ok' })
Vue.prototype.$http.post.mockResolvedValue({ message: 'ok' })
const wrapper = mount(Profile)
const button = wrapper.find('[data-test=resetAvatar]')
document.body.innerHTML += '<img alt="User Image" src="a">'
@ -44,8 +44,8 @@ test('reset avatar', async () => {
test('change password', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'w' })
.mockResolvedValueOnce({ errno: 0, msg: 'o' })
.mockResolvedValueOnce({ code: 1, message: 'w' })
.mockResolvedValueOnce({ code: 0, message: 'o' })
const wrapper = mount(Profile)
const button = wrapper.find('[data-test=changePassword]')
@ -84,8 +84,8 @@ test('change password', async () => {
test('change nickname', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'w' })
.mockResolvedValue({ errno: 0, msg: 'o' })
.mockResolvedValueOnce({ code: 1, message: 'w' })
.mockResolvedValue({ code: 0, message: 'o' })
Vue.prototype.$confirm
.mockRejectedValueOnce('close')
.mockResolvedValue('confirm')
@ -119,8 +119,8 @@ test('change nickname', async () => {
test('change email', async () => {
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'w' })
.mockResolvedValue({ errno: 0, msg: 'o' })
.mockResolvedValueOnce({ code: 1, message: 'w' })
.mockResolvedValue({ code: 0, message: 'o' })
Vue.prototype.$confirm
.mockRejectedValueOnce('close')
.mockResolvedValue('confirm')
@ -158,8 +158,8 @@ test('change email', async () => {
test('delete account', async () => {
window.blessing.extra = { admin: true }
Vue.prototype.$http.post
.mockResolvedValueOnce({ errno: 1, msg: 'w' })
.mockResolvedValue({ errno: 0, msg: 'o' })
.mockResolvedValueOnce({ code: 1, message: 'w' })
.mockResolvedValue({ code: 0, message: 'o' })
const wrapper = mount(Profile)
const button = wrapper.find('[data-test=deleteAccount]')

View File

@ -43,8 +43,8 @@ class AdminControllerTest extends BrowserKitTestCase
// Change color
$this->get('/admin/customize?action=color&color_scheme=purple')
->seeJson([
'errno' => 0,
'msg' => trans('admin.customize.change-color.success'),
'code' => 0,
'message' => trans('admin.customize.change-color.success'),
]);
$this->assertEquals('purple', option('color_scheme'));
@ -308,8 +308,8 @@ class AdminControllerTest extends BrowserKitTestCase
// Operate on an not-existed user
$this->postJson('/admin/users')
->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.non-existent'),
'code' => 1,
'message' => trans('admin.users.operations.non-existent'),
]);
$user = factory(User::class)->create();
@ -317,16 +317,16 @@ class AdminControllerTest extends BrowserKitTestCase
// Operate without `action` field
$this->postJson('/admin/users', ['uid' => $user->uid])
->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.invalid'),
'code' => 1,
'message' => trans('admin.users.operations.invalid'),
]);
// An admin operating on a super admin should be forbidden
$superAdmin = factory(User::class, 'superAdmin')->create();
$this->postJson('/admin/users', ['uid' => $superAdmin->uid])
->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.no-permission'),
'code' => 1,
'message' => trans('admin.users.operations.no-permission'),
]);
// Action is `email` but without `email` field
@ -348,8 +348,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'email', 'email' => $superAdmin->email]
)->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.email.existed', ['email' => $superAdmin->email]),
'code' => 1,
'message' => trans('admin.users.operations.email.existed', ['email' => $superAdmin->email]),
]);
// Set email successfully
@ -357,8 +357,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'email', 'email' => 'a@b.c']
)->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.email.success'),
'code' => 0,
'message' => trans('admin.users.operations.email.success'),
]);
$this->seeInDatabase('users', [
'uid' => $user->uid,
@ -370,8 +370,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'verification']
)->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.verification.success'),
'code' => 0,
'message' => trans('admin.users.operations.verification.success'),
]);
$this->seeInDatabase('users', [
'uid' => $user->uid,
@ -397,8 +397,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'nickname', 'nickname' => 'nickname']
)->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.nickname.success', ['new' => 'nickname']),
'code' => 0,
'message' => trans('admin.users.operations.nickname.success', ['new' => 'nickname']),
]);
$this->seeInDatabase('users', [
'uid' => $user->uid,
@ -431,8 +431,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'password', 'password' => '12345678']
)->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.password.success'),
'code' => 0,
'message' => trans('admin.users.operations.password.success'),
]);
$user = User::find($user->uid);
$this->assertTrue($user->verifyPassword('12345678'));
@ -456,8 +456,8 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/users',
['uid' => $user->uid, 'action' => 'score', 'score' => 123]
)->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.score.success'),
'code' => 0,
'message' => trans('admin.users.operations.score.success'),
]);
$this->seeInDatabase('users', [
'uid' => $user->uid,
@ -479,8 +479,8 @@ class AdminControllerTest extends BrowserKitTestCase
'action' => 'permission',
'permission' => -1,
])->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.permission'),
'code' => 0,
'message' => trans('admin.users.operations.permission'),
]);
$user = User::find($user->uid);
$this->assertEquals(User::BANNED, $user->permission);
@ -488,8 +488,8 @@ class AdminControllerTest extends BrowserKitTestCase
// Delete a user
$this->postJson('/admin/users', ['uid' => $user->uid, 'action' => 'delete'])
->seeJson([
'errno' => 0,
'msg' => trans('admin.users.operations.delete.success'),
'code' => 0,
'message' => trans('admin.users.operations.delete.success'),
]);
$this->assertNull(User::find($user->uid));
}
@ -501,8 +501,8 @@ class AdminControllerTest extends BrowserKitTestCase
// Operate on a not-existed player
$this->postJson('/admin/players', ['pid' => -1])
->seeJson([
'errno' => 1,
'msg' => trans('general.unexistent-player'),
'code' => 1,
'message' => trans('general.unexistent-player'),
]);
// An admin cannot operate another admin's player
@ -511,24 +511,24 @@ class AdminControllerTest extends BrowserKitTestCase
'/admin/players',
['pid' => factory(Player::class)->create(['uid' => $admin->uid])->pid]
)->seeJson([
'errno' => 1,
'msg' => trans('admin.players.no-permission'),
'code' => 1,
'message' => trans('admin.players.no-permission'),
]);
$superAdmin = factory(User::class, 'superAdmin')->create();
$this->postJson(
'/admin/players',
['pid' => factory(Player::class)->create(['uid' => $superAdmin->uid])->pid]
)->seeJson([
'errno' => 1,
'msg' => trans('admin.players.no-permission'),
'code' => 1,
'message' => trans('admin.players.no-permission'),
]);
// For self is OK
$this->actingAs($admin)->postJson(
'/admin/players',
['pid' => factory(Player::class)->create(['uid' => $admin->uid])->pid]
)->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.invalid'),
'code' => 1,
'message' => trans('admin.users.operations.invalid'),
]);
// Change texture without `type` field
@ -565,8 +565,8 @@ class AdminControllerTest extends BrowserKitTestCase
'type' => 'skin',
'tid' => -1,
])->seeJson([
'errno' => 1,
'msg' => trans('admin.players.textures.non-existent', ['tid' => -1]),
'code' => 1,
'message' => trans('admin.players.textures.non-existent', ['tid' => -1]),
]);
$skin = factory(Texture::class)->create();
@ -579,8 +579,8 @@ class AdminControllerTest extends BrowserKitTestCase
'type' => 'skin',
'tid' => $skin->tid,
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
'code' => 0,
'message' => trans('admin.players.textures.success', ['player' => $player->name]),
]);
$player = Player::find($player->pid);
$this->assertEquals($skin->tid, $player->tid_skin);
@ -592,8 +592,8 @@ class AdminControllerTest extends BrowserKitTestCase
'type' => 'cape',
'tid' => $cape->tid,
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
'code' => 0,
'message' => trans('admin.players.textures.success', ['player' => $player->name]),
]);
$player = Player::find($player->pid);
$this->assertEquals($cape->tid, $player->tid_cape);
@ -605,8 +605,8 @@ class AdminControllerTest extends BrowserKitTestCase
'type' => 'skin',
'tid' => 0,
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
'code' => 0,
'message' => trans('admin.players.textures.success', ['player' => $player->name]),
]);
$player = Player::find($player->pid);
$this->assertEquals(0, $player->tid_skin);
@ -618,8 +618,8 @@ class AdminControllerTest extends BrowserKitTestCase
'type' => 'cape',
'tid' => 0,
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.textures.success', ['player' => $player->name]),
'code' => 0,
'message' => trans('admin.players.textures.success', ['player' => $player->name]),
]);
$player = Player::find($player->pid);
$this->assertEquals(0, $player->tid_cape);
@ -647,8 +647,8 @@ class AdminControllerTest extends BrowserKitTestCase
'action' => 'owner',
'uid' => -1,
])->seeJson([
'errno' => 1,
'msg' => trans('admin.users.operations.non-existent'),
'code' => 1,
'message' => trans('admin.users.operations.non-existent'),
]);
// Change owner successfully
@ -658,8 +658,8 @@ class AdminControllerTest extends BrowserKitTestCase
'action' => 'owner',
'uid' => $user->uid,
])->seeJson([
'errno' => 0,
'msg' => trans(
'code' => 0,
'message' => trans(
'admin.players.owner.success',
['player' => $player->name, 'user' => $user->nickname]
),
@ -679,8 +679,8 @@ class AdminControllerTest extends BrowserKitTestCase
'action' => 'name',
'name' => 'new_name',
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.name.success', ['player' => 'new_name']),
'code' => 0,
'message' => trans('admin.players.name.success', ['player' => 'new_name']),
'name' => 'new_name',
]);
@ -690,7 +690,7 @@ class AdminControllerTest extends BrowserKitTestCase
'pid' => $player->pid,
'action' => 'name',
'name' => 'abc',
])->seeJson(['errno' => 0]);
])->seeJson(['code' => 0]);
$player->refresh();
$this->assertEquals('abc', $player->user->nickname);
@ -699,8 +699,8 @@ class AdminControllerTest extends BrowserKitTestCase
'pid' => $player->pid,
'action' => 'delete',
])->seeJson([
'errno' => 0,
'msg' => trans('admin.players.delete.success'),
'code' => 0,
'message' => trans('admin.players.delete.success'),
]);
$this->assertNull(Player::find($player->pid));
}
@ -710,8 +710,8 @@ class AdminControllerTest extends BrowserKitTestCase
$user = factory(User::class)->create();
$this->get('/admin/user/'.$user->uid)
->seeJson([
'errno' => 0,
'msg' => 'success',
'code' => 0,
'message' => 'success',
'user' => [
'uid' => $user->uid,
'email' => $user->email,
@ -726,8 +726,8 @@ class AdminControllerTest extends BrowserKitTestCase
$this->get('/admin/user/-1')
->seeJson([
'errno' => 1,
'msg' => 'No such user.',
'code' => 1,
'message' => 'No such user.',
]);
}
}

View File

@ -79,8 +79,8 @@ class AuthControllerTest extends TestCase
'password' => 'wrong-password',
])->assertJson(
[
'errno' => 1,
'msg' => trans('auth.validation.password'),
'code' => 1,
'message' => trans('auth.validation.password'),
'login_fails' => 1,
]
);
@ -105,8 +105,8 @@ class AuthControllerTest extends TestCase
'identification' => 'nope@nope.net',
'password' => '12345678',
])->assertJson([
'errno' => 2,
'msg' => trans('auth.validation.user'),
'code' => 2,
'message' => trans('auth.validation.user'),
]);
$this->flushSession();
@ -118,8 +118,8 @@ class AuthControllerTest extends TestCase
'password' => '12345678',
])->assertJson(
[
'errno' => 0,
'msg' => trans('auth.login.success'),
'code' => 0,
'message' => trans('auth.login.success'),
]
);
$this->assertFalse(Cache::has($loginFailsCacheKey));
@ -135,8 +135,8 @@ class AuthControllerTest extends TestCase
]
)->assertJson(
[
'errno' => 0,
'msg' => trans('auth.login.success'),
'code' => 0,
'message' => trans('auth.login.success'),
]
);
$this->assertAuthenticated();
@ -146,15 +146,15 @@ class AuthControllerTest extends TestCase
{
$this->postJson('/auth/logout')
->assertJson([
'errno' => 1,
'msg' => trans('auth.logout.fail'),
'code' => 1,
'message' => trans('auth.logout.fail'),
]);
$user = factory(User::class)->create();
$this->actingAs($user)->postJson('/auth/logout')->assertJson(
[
'errno' => 0,
'msg' => trans('auth.logout.success'),
'code' => 0,
'message' => trans('auth.logout.success'),
]
);
$this->assertGuest();
@ -257,8 +257,8 @@ class AuthControllerTest extends TestCase
'captcha' => 'a',
]
)->assertJson([
'errno' => 2,
'msg' => trans('user.player.add.repeated'),
'code' => 2,
'message' => trans('user.player.add.repeated'),
]);
$this->assertNull(User::where('email', 'a@b.c')->first());
@ -317,8 +317,8 @@ class AuthControllerTest extends TestCase
'captcha' => 'a',
]
)->assertJson([
'errno' => 7,
'msg' => trans('auth.register.close'),
'code' => 7,
'message' => trans('auth.register.close'),
]);
// Reopen for test
@ -335,8 +335,8 @@ class AuthControllerTest extends TestCase
'captcha' => 'a',
]
)->assertJson([
'errno' => 7,
'msg' => trans('auth.register.max', ['regs' => option('regs_per_ip')]),
'code' => 7,
'message' => trans('auth.register.max', ['regs' => option('regs_per_ip')]),
]);
Option::set('regs_per_ip', 100);
@ -353,8 +353,8 @@ class AuthControllerTest extends TestCase
);
$newUser = User::where('email', 'a@b.c')->first();
$response->assertJson([
'errno' => 0,
'msg' => trans('auth.register.success'),
'code' => 0,
'message' => trans('auth.register.success'),
]);
$this->assertTrue($newUser->verifyPassword('12345678'));
$this->assertDatabaseHas('users', [
@ -376,7 +376,7 @@ class AuthControllerTest extends TestCase
'player_name' => 'name',
'captcha' => 'a',
]
)->assertJson(['errno' => 0]);
)->assertJson(['code' => 0]);
$this->assertNotNull(Player::where('player', 'name'));
}
@ -397,8 +397,8 @@ class AuthControllerTest extends TestCase
$this->postJson('/auth/forgot', [
'captcha' => 'a',
])->assertJson([
'errno' => 1,
'msg' => trans('auth.forgot.disabled'),
'code' => 1,
'message' => trans('auth.forgot.disabled'),
]);
config(['mail.driver' => 'smtp']);
@ -409,8 +409,8 @@ class AuthControllerTest extends TestCase
$this->postJson('/auth/forgot', [
'captcha' => 'a',
])->assertJson([
'errno' => 2,
'msg' => trans('auth.forgot.frequent-mail'),
'code' => 2,
'message' => trans('auth.forgot.frequent-mail'),
]);
Cache::flush();
$this->flushSession();
@ -421,16 +421,16 @@ class AuthControllerTest extends TestCase
'email' => 'nope@nope.net',
'captcha' => 'a',
])->assertJson([
'errno' => 1,
'msg' => trans('auth.forgot.unregistered'),
'code' => 1,
'message' => trans('auth.forgot.unregistered'),
]);
$this->postJson('/auth/forgot', [
'email' => $user->email,
'captcha' => 'a',
])->assertJson([
'errno' => 0,
'msg' => trans('auth.forgot.success'),
'code' => 0,
'message' => trans('auth.forgot.success'),
]);
$this->assertTrue(Cache::has($lastMailCacheKey));
Cache::flush();
@ -448,8 +448,8 @@ class AuthControllerTest extends TestCase
'email' => $user->email,
'captcha' => 'a',
])->assertJson([
'errno' => 2,
'msg' => trans('auth.forgot.failed', ['msg' => 'A fake exception.']),
'code' => 2,
'message' => trans('auth.forgot.failed', ['msg' => 'A fake exception.']),
]);
// Addition: Mailable test
@ -495,8 +495,8 @@ class AuthControllerTest extends TestCase
$url, [
'password' => '12345678',
])->assertJson([
'errno' => 0,
'msg' => trans('auth.reset.success'),
'code' => 0,
'message' => trans('auth.reset.success'),
]);
// We must re-query the user model,
// because the old instance hasn't been changed

View File

@ -113,8 +113,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/add',
['tid' => $texture->tid, 'name' => $name]
)->assertJson([
'errno' => 7,
'msg' => trans('user.closet.add.lack-score'),
'code' => 7,
'message' => trans('user.closet.add.lack-score'),
]);
// Add a not-existed texture
@ -123,8 +123,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/add',
['tid' => -1, 'name' => 'my']
)->assertJson([
'errno' => 1,
'msg' => trans('user.closet.add.not-found'),
'code' => 1,
'message' => trans('user.closet.add.not-found'),
]);
// Add a texture successfully
@ -133,8 +133,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/add',
['tid' => $texture->tid, 'name' => $name]
)->assertJson([
'errno' => 0,
'msg' => trans('user.closet.add.success', ['name' => $name]),
'code' => 0,
'message' => trans('user.closet.add.success', ['name' => $name]),
]);
$this->assertEquals($likes + 1, Texture::find($texture->tid)->likes);
$this->user = User::find($this->user->uid);
@ -148,8 +148,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/add',
['tid' => $texture->tid, 'name' => $name]
)->assertJson([
'errno' => 1,
'msg' => trans('user.closet.add.repeated'),
'code' => 1,
'message' => trans('user.closet.add.repeated'),
]);
}
@ -184,8 +184,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/rename',
['tid' => -1, 'new_name' => $name]
)->assertJson([
'errno' => 1,
'msg' => trans('user.closet.remove.non-existent'),
'code' => 1,
'message' => trans('user.closet.remove.non-existent'),
]);
// Rename a closet item successfully
@ -194,8 +194,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/rename',
['tid' => $texture->tid, 'new_name' => $name]
)->assertJson([
'errno' => 0,
'msg' => trans('user.closet.rename.success', ['name' => 'new']),
'code' => 0,
'message' => trans('user.closet.rename.success', ['name' => 'new']),
]);
$this->assertEquals(1, $this->user->closet()->where('item_name', 'new')->count());
}
@ -220,8 +220,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/remove',
['tid' => -1]
)->assertJson([
'errno' => 1,
'msg' => trans('user.closet.remove.non-existent'),
'code' => 1,
'message' => trans('user.closet.remove.non-existent'),
]);
// Should return score if `return_score` is true
@ -232,8 +232,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/remove',
['tid' => $texture->tid]
)->assertJson([
'errno' => 0,
'msg' => trans('user.closet.remove.success'),
'code' => 0,
'message' => trans('user.closet.remove.success'),
]);
$this->assertEquals($likes, Texture::find($texture->tid)->likes);
$this->assertEquals($score + option('score_per_closet_item'), $this->user->score);
@ -251,8 +251,8 @@ class ClosetControllerTest extends TestCase
'/user/closet/remove',
['tid' => $texture->tid]
)->assertJson([
'errno' => 0,
'msg' => trans('user.closet.remove.success'),
'code' => 0,
'message' => trans('user.closet.remove.success'),
]);
$this->assertEquals($likes, Texture::find($texture->tid)->likes);
$this->assertEquals($score, $this->user->score);

View File

@ -30,8 +30,8 @@ class MarketControllerTest extends TestCase
$this->postJson('/admin/plugins/market/download', [
'name' => 'non-existent-plugin',
])->assertJson([
'errno' => 1,
'msg' => trans('admin.plugins.market.non-existent', ['plugin' => 'non-existent-plugin']),
'code' => 1,
'message' => trans('admin.plugins.market.non-existent', ['plugin' => 'non-existent-plugin']),
]);
// Download
@ -40,13 +40,13 @@ class MarketControllerTest extends TestCase
app()->instance(PackageManager::class, new Concerns\FakePackageManager(null, true));
$this->postJson('/admin/plugins/market/download', [
'name' => 'fake-test-download',
])->assertJson(['errno' => 1]);
])->assertJson(['code' => 1]);
$this->appendToGuzzleQueue([new Response(200, [], $fakeRegistry)]);
app()->bind(PackageManager::class, Concerns\FakePackageManager::class);
$this->postJson('/admin/plugins/market/download', [
'name' => 'fake-test-download',
])->assertJson(['errno' => 0, 'msg' => trans('admin.plugins.market.install-success')]);
])->assertJson(['code' => 0, 'message' => trans('admin.plugins.market.install-success')]);
}
public function testCheckUpdates()

View File

@ -147,15 +147,15 @@ class MiddlewareTest extends TestCase
'pid' => -1,
'new_player_name' => 'name',
])->assertJson([
'errno' => 1,
'msg' => trans('general.unexistent-player'),
'code' => 1,
'message' => trans('general.unexistent-player'),
]);
$this->actingAs($user)
->postJson('/user/player/rename', [
'pid' => $player->pid,
'new_player_name' => 'name',
])->assertJson([
'errno' => 0,
'code' => 0,
]);
}
@ -173,8 +173,8 @@ class MiddlewareTest extends TestCase
->postJson('/user/player/rename', [
'pid' => $player->pid,
])->assertJson([
'errno' => 1,
'msg' => trans('admin.players.no-permission'),
'code' => 1,
'message' => trans('admin.players.no-permission'),
]);
$this->actingAs($owner)
@ -182,7 +182,7 @@ class MiddlewareTest extends TestCase
'pid' => $player->pid,
'new_player_name' => 'name',
])->assertJson([
'errno' => 0,
'code' => 0,
]);
}

View File

@ -65,8 +65,8 @@ class PlayerControllerTest extends TestCase
'/user/player/add',
['player_name' => 'no_score']
)->assertJson([
'errno' => 7,
'msg' => trans('user.player.add.lack-score'),
'code' => 7,
'message' => trans('user.player.add.lack-score'),
]);
$this->expectsEvents(Events\CheckPlayerExists::class);
@ -77,8 +77,8 @@ class PlayerControllerTest extends TestCase
$this->actingAs($user)->postJson('/user/player/add', [
'player_name' => '角色名',
])->assertJson([
'errno' => 0,
'msg' => trans('user.player.add.success', ['name' => '角色名']),
'code' => 0,
'message' => trans('user.player.add.success', ['name' => '角色名']),
]);
$this->expectsEvents(Events\PlayerWillBeAdded::class);
$this->expectsEvents(Events\PlayerWasAdded::class);
@ -94,16 +94,16 @@ class PlayerControllerTest extends TestCase
// Add a existed player
$this->postJson('/user/player/add', ['player_name' => '角色名'])
->assertJson([
'errno' => 6,
'msg' => trans('user.player.add.repeated'),
'code' => 6,
'message' => trans('user.player.add.repeated'),
]);
// Single player
option(['single_player' => true]);
$this->postJson('/user/player/add', ['player_name' => 'abc'])
->assertJson([
'errno' => 1,
'msg' => trans('user.player.add.single'),
'code' => 1,
'message' => trans('user.player.add.single'),
]);
}
@ -116,8 +116,8 @@ class PlayerControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/player/delete', ['pid' => $player->pid])
->assertJson([
'errno' => 0,
'msg' => trans('user.player.delete.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.delete.success', ['name' => $player->name]),
]);
$this->assertNull(Player::find($player->pid));
$this->expectsEvents(Events\PlayerWasDeleted::class);
@ -133,8 +133,8 @@ class PlayerControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/player/delete', ['pid' => $player->pid])
->assertJson([
'errno' => 0,
'msg' => trans('user.player.delete.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.delete.success', ['name' => $player->name]),
]);
$this->assertEquals(
$user->score,
@ -147,8 +147,8 @@ class PlayerControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/player/delete', ['pid' => $player->pid])
->assertJson([
'errno' => 1,
'msg' => trans('user.player.delete.single'),
'code' => 1,
'message' => trans('user.player.delete.single'),
]);
$this->assertNotNull(Player::find($player->pid));
}
@ -193,8 +193,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'new_player_name' => $name,
])->assertJson([
'errno' => 6,
'msg' => trans('user.player.rename.repeated'),
'code' => 6,
'message' => trans('user.player.rename.repeated'),
]);
// Success
@ -202,8 +202,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'new_player_name' => 'new_name',
])->assertJson([
'errno' => 0,
'msg' => trans(
'code' => 0,
'message' => trans(
'user.player.rename.success',
['old' => $player->name, 'new' => 'new_name']
),
@ -215,7 +215,7 @@ class PlayerControllerTest extends TestCase
$this->postJson('/user/player/rename', [
'pid' => $player->pid,
'new_player_name' => 'abc',
])->assertJson(['errno' => 0]);
])->assertJson(['code' => 0]);
$this->assertEquals('abc', $player->user->nickname);
}
@ -232,8 +232,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'tid' => ['skin' => -1],
])->assertJson([
'errno' => 6,
'msg' => trans('skinlib.un-existent'),
'code' => 6,
'message' => trans('skinlib.un-existent'),
]);
// Set for "skin" type
@ -241,8 +241,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'tid' => ['skin' => $skin->tid],
])->assertJson([
'errno' => 0,
'msg' => trans('user.player.set.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.set.success', ['name' => $player->name]),
]);
$this->assertEquals($skin->tid, Player::find($player->pid)->tid_skin);
@ -251,8 +251,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'tid' => ['cape' => $cape->tid],
])->assertJson([
'errno' => 0,
'msg' => trans('user.player.set.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.set.success', ['name' => $player->name]),
]);
$this->assertEquals($cape->tid, Player::find($player->pid)->tid_cape);
@ -261,8 +261,8 @@ class PlayerControllerTest extends TestCase
'pid' => $player->pid,
'tid' => ['nope' => $skin->tid], // TID must be valid
])->assertJson([
'errno' => 0,
'msg' => trans('user.player.set.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.set.success', ['name' => $player->name]),
]);
}
@ -284,8 +284,8 @@ class PlayerControllerTest extends TestCase
'cape' => 1,
'nope' => 1, // Invalid texture type is acceptable
])->assertJson([
'errno' => 0,
'msg' => trans('user.player.clear.success', ['name' => $player->name]),
'code' => 0,
'message' => trans('user.player.clear.success', ['name' => $player->name]),
]);
$this->assertEquals(0, Player::find($player->pid)->tid_skin);
$this->assertEquals(0, Player::find($player->pid)->tid_cape);
@ -304,8 +304,8 @@ class PlayerControllerTest extends TestCase
$this->postJson('/user/player/bind', ['player' => 'abc'])
->assertJson([
'errno' => 0,
'msg' => trans('user.player.bind.success'),
'code' => 0,
'message' => trans('user.player.bind.success'),
]);
Event::assertDispatched(Events\CheckPlayerExists::class);
Event::assertDispatched(Events\PlayerWillBeAdded::class);
@ -321,12 +321,12 @@ class PlayerControllerTest extends TestCase
$player3 = factory(Player::class)->create(['uid' => $user->uid]);
$this->postJson('/user/player/bind', ['player' => $player2->name])
->assertJson([
'errno' => 1,
'msg' => trans('user.player.rename.repeated'),
'code' => 1,
'message' => trans('user.player.rename.repeated'),
]);
$this->postJson('/user/player/bind', ['player' => $player->name])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertNull(Player::where('name', $player3->name)->first());
}
}

View File

@ -50,15 +50,15 @@ class PluginControllerTest extends TestCase
// An not-existed plugin
$this->postJson('/admin/plugins/manage', ['name' => 'nope'])
->assertJson([
'errno' => 1,
'msg' => trans('admin.plugins.operations.not-found'),
'code' => 1,
'message' => trans('admin.plugins.operations.not-found'),
]);
// Invalid action
$this->postJson('/admin/plugins/manage', ['name' => 'fake-plugin-for-test'])
->assertJson([
'errno' => 1,
'msg' => trans('admin.invalid-action'),
'code' => 1,
'message' => trans('admin.invalid-action'),
]);
// Enable a plugin with unsatisfied dependencies
@ -72,8 +72,8 @@ class PluginControllerTest extends TestCase
'name' => 'fake-plugin-for-test',
'action' => 'enable',
])->assertJson([
'errno' => 1,
'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
'code' => 1,
'message' => trans('admin.plugins.operations.unsatisfied.notice'),
'reason' => [
trans('admin.plugins.operations.unsatisfied.version', [
'name' => 'fake-plugin-with-config-view',
@ -91,8 +91,8 @@ class PluginControllerTest extends TestCase
'name' => 'fake-plugin-for-test',
'action' => 'enable',
])->assertJson([
'errno' => 0,
'msg' => trans(
'code' => 0,
'message' => trans(
'admin.plugins.operations.enabled',
['plugin' => plugin('fake-plugin-for-test')->title]
),
@ -103,8 +103,8 @@ class PluginControllerTest extends TestCase
'name' => 'fake-plugin-for-test',
'action' => 'disable',
])->assertJson([
'errno' => 0,
'msg' => trans(
'code' => 0,
'message' => trans(
'admin.plugins.operations.disabled',
['plugin' => plugin('fake-plugin-for-test')->title]
),
@ -115,8 +115,8 @@ class PluginControllerTest extends TestCase
'name' => 'fake-plugin-for-test',
'action' => 'delete',
])->assertJson([
'errno' => 0,
'msg' => trans('admin.plugins.operations.deleted'),
'code' => 0,
'message' => trans('admin.plugins.operations.deleted'),
]);
$this->assertFalse(file_exists(base_path('plugins/fake-plugin-for-test/')));
}

View File

@ -35,16 +35,16 @@ class ReportControllerTest extends TestCase
option(['reporter_score_modification' => -5]);
$this->postJson('/skinlib/report', ['tid' => $texture->tid, 'reason' => 'reason'])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.upload.lack-score'),
'code' => 1,
'message' => trans('skinlib.upload.lack-score'),
]);
// Success
option(['reporter_score_modification' => 5]);
$this->postJson('/skinlib/report', ['tid' => $texture->tid, 'reason' => 'reason'])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.report.success'),
'code' => 0,
'message' => trans('skinlib.report.success'),
]);
$user->refresh();
$this->assertEquals(5, $user->score);
@ -57,8 +57,8 @@ class ReportControllerTest extends TestCase
// Prevent duplication
$this->postJson('/skinlib/report', ['tid' => $texture->tid, 'reason' => 'reason'])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.report.duplicate'),
'code' => 1,
'message' => trans('skinlib.report.duplicate'),
]);
}
@ -147,8 +147,8 @@ class ReportControllerTest extends TestCase
// Only process pending report
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'reject'])
->assertJson([
'errno' => 1,
'msg' => trans('admin.report-reviewed'),
'code' => 1,
'message' => trans('admin.report-reviewed'),
]);
// Reject
@ -157,8 +157,8 @@ class ReportControllerTest extends TestCase
$score = $reporter->score;
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'reject'])
->assertJson([
'errno' => 0,
'msg' => trans('general.op-success'),
'code' => 0,
'message' => trans('general.op-success'),
'status' => Report::REJECTED,
]);
$report->refresh();
@ -172,7 +172,7 @@ class ReportControllerTest extends TestCase
option(['reporter_score_modification' => 5]);
$score = $reporter->score;
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'reject'])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$reporter->refresh();
$this->assertEquals($score - 5, $reporter->score);
@ -184,8 +184,8 @@ class ReportControllerTest extends TestCase
$score = $reporter->score;
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'delete'])
->assertJson([
'errno' => 0,
'msg' => trans('general.op-success'),
'code' => 0,
'message' => trans('general.op-success'),
'status' => Report::RESOLVED,
]);
$report->refresh();
@ -205,8 +205,8 @@ class ReportControllerTest extends TestCase
$score = $reporter->score;
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'ban'])
->assertJson([
'errno' => 0,
'msg' => trans('general.op-success'),
'code' => 0,
'message' => trans('general.op-success'),
'status' => Report::RESOLVED,
]);
$reporter->refresh();
@ -222,8 +222,8 @@ class ReportControllerTest extends TestCase
$uploader->save();
$this->postJson('/admin/reports', ['id' => $report->id, 'action' => 'ban'])
->assertJson([
'errno' => 1,
'msg' => trans('admin.users.operations.no-permission'),
'code' => 1,
'message' => trans('admin.users.operations.no-permission'),
]);
$report->refresh();
$this->assertEquals(Report::PENDING, $report->status);

View File

@ -382,8 +382,8 @@ class SkinlibControllerTest extends TestCase
'/skinlib/upload',
['file' => $upload]
)->assertJson([
'errno' => UPLOAD_ERR_NO_TMP_DIR,
'msg' => \App\Http\Controllers\SkinlibController::$phpFileUploadErrors[UPLOAD_ERR_NO_TMP_DIR],
'code' => UPLOAD_ERR_NO_TMP_DIR,
'message' => \App\Http\Controllers\SkinlibController::$phpFileUploadErrors[UPLOAD_ERR_NO_TMP_DIR],
]);
// Without `name` field
@ -429,8 +429,8 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->create('fake', 5),
]
)->assertJson([
'errno' => 1,
'msg' => trans('skinlib.upload.type-error'),
'code' => 1,
'message' => trans('skinlib.upload.type-error'),
]);
// No texture type is specified
@ -442,8 +442,8 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->image('texture.png', 64, 32),
]
)->assertJson([
'errno' => 1,
'msg' => trans('general.illegal-parameters'),
'code' => 1,
'message' => trans('general.illegal-parameters'),
]);
// Invalid skin size
@ -456,8 +456,8 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->image('texture.png', 64, 30),
]
)->assertJson([
'errno' => 1,
'msg' => trans(
'code' => 1,
'message' => trans(
'skinlib.upload.invalid-size',
[
'type' => trans('general.skin'),
@ -475,8 +475,8 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->image('texture.png', 100, 50),
]
)->assertJson([
'errno' => 1,
'msg' => trans(
'code' => 1,
'message' => trans(
'skinlib.upload.invalid-hd-skin',
[
'type' => trans('general.skin'),
@ -494,8 +494,8 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->image('texture.png', 64, 30),
]
)->assertJson([
'errno' => 1,
'msg' => trans(
'code' => 1,
'message' => trans(
'skinlib.upload.invalid-size',
[
'type' => trans('general.cape'),
@ -520,8 +520,8 @@ class SkinlibControllerTest extends TestCase
]
)
->assertJson([
'errno' => 7,
'msg' => trans('skinlib.upload.lack-score'),
'code' => 7,
'message' => trans('skinlib.upload.lack-score'),
]);
$user = factory(User::class)->create([
@ -536,8 +536,8 @@ class SkinlibControllerTest extends TestCase
'file' => $upload,
]
)->assertJson([
'errno' => 7,
'msg' => trans('skinlib.upload.lack-score'),
'code' => 7,
'message' => trans('skinlib.upload.lack-score'),
]);
// Success
@ -553,8 +553,8 @@ class SkinlibControllerTest extends TestCase
);
$t = Texture::where('name', 'texture')->first();
$response->assertJson([
'errno' => 0,
'msg' => trans('skinlib.upload.success', ['name' => 'texture']),
'code' => 0,
'message' => trans('skinlib.upload.success', ['name' => 'texture']),
'tid' => $t->tid,
]);
Storage::disk('textures')->assertExists($t->hash);
@ -579,8 +579,8 @@ class SkinlibControllerTest extends TestCase
'file' => $upload,
]
)->assertJson([
'errno' => 0,
'msg' => trans('skinlib.upload.repeated'),
'code' => 0,
'message' => trans('skinlib.upload.repeated'),
'tid' => $t->tid,
]);
@ -598,24 +598,24 @@ class SkinlibControllerTest extends TestCase
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => -1])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.non-existent'),
'code' => 1,
'message' => trans('skinlib.non-existent'),
]);
// Other user should not be able to delete
$this->actingAs($other)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.no-permission'),
'code' => 1,
'message' => trans('skinlib.no-permission'),
]);
// Administrators can delete it
$this->actAs('admin')
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.delete.success'),
'code' => 0,
'message' => trans('skinlib.delete.success'),
]);
$this->assertNull(Texture::find($texture->tid));
@ -626,8 +626,8 @@ class SkinlibControllerTest extends TestCase
// When file is occupied, the file should not be deleted
$this->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.delete.success'),
'code' => 0,
'message' => trans('skinlib.delete.success'),
]);
$this->assertNull(Texture::find($texture->tid));
$this->assertTrue(Storage::disk('textures')->exists($texture->hash));
@ -636,8 +636,8 @@ class SkinlibControllerTest extends TestCase
factory(Texture::class)->create(['hash' => $texture->hash]);
$this->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.delete.success'),
'code' => 0,
'message' => trans('skinlib.delete.success'),
]);
$this->assertNull(Texture::find($texture->tid));
$this->assertFalse(Storage::disk('textures')->exists($texture->hash));
@ -648,8 +648,8 @@ class SkinlibControllerTest extends TestCase
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.delete.success'),
'code' => 0,
'message' => trans('skinlib.delete.success'),
]);
$this->assertEquals(
$uploader->score + $texture->size * option('score_per_storage'),
@ -664,8 +664,8 @@ class SkinlibControllerTest extends TestCase
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.delete.success'),
'code' => 0,
'message' => trans('skinlib.delete.success'),
]);
$this->assertEquals(
$uploader->score + $texture->size * option('private_score_per_storage'),
@ -680,7 +680,7 @@ class SkinlibControllerTest extends TestCase
$uploader->refresh();
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertEquals($uploader->score - 5, User::find($uploader->uid)->score);
// Option disabled
option(['take_back_scores_after_deletion' => false]);
@ -688,7 +688,7 @@ class SkinlibControllerTest extends TestCase
$uploader->refresh();
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertEquals($uploader->score, User::find($uploader->uid)->score);
// Private texture
$texture = factory(Texture::class)->create([
@ -698,7 +698,7 @@ class SkinlibControllerTest extends TestCase
$uploader->refresh();
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertEquals($uploader->score, User::find($uploader->uid)->score);
// Remove from closet
@ -709,7 +709,7 @@ class SkinlibControllerTest extends TestCase
$other->save();
$this->actingAs($uploader)
->postJson('/skinlib/delete', ['tid' => $texture->tid])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$other->refresh();
$this->assertEquals(option('score_per_closet_item'), $other->score);
}
@ -724,16 +724,16 @@ class SkinlibControllerTest extends TestCase
$this->actingAs($uploader)
->postJson('/skinlib/privacy', ['tid' => -1])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.non-existent'),
'code' => 1,
'message' => trans('skinlib.non-existent'),
]);
// Other user should not be able to set privacy
$this->actingAs($other)
->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.no-permission'),
'code' => 1,
'message' => trans('skinlib.no-permission'),
]);
// Administrators can change it
@ -742,8 +742,8 @@ class SkinlibControllerTest extends TestCase
$this->actAs('admin')
->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]);
$this->assertEquals(0, Texture::find($texture->tid)->public);
@ -755,8 +755,8 @@ class SkinlibControllerTest extends TestCase
$this->actingAs($uploader)
->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.upload.lack-score'),
'code' => 1,
'message' => trans('skinlib.upload.lack-score'),
]);
$this->assertEquals(1, Texture::find($texture->tid)->public);
@ -767,8 +767,8 @@ class SkinlibControllerTest extends TestCase
$uploader->save();
$this->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]);
$this->assertEquals(0, User::find($uploader->uid)->score);
@ -783,8 +783,8 @@ class SkinlibControllerTest extends TestCase
$other->closet()->attach($texture->tid, ['item_name' => 'a']);
$this->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]);
$this->assertEquals(0, Player::find($player->pid)->tid_skin);
@ -803,7 +803,7 @@ class SkinlibControllerTest extends TestCase
$uploader->score += option('score_award_per_texture');
$uploader->save();
$this->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertEquals(0, User::find($uploader->uid)->score);
// Without returning score
@ -813,7 +813,7 @@ class SkinlibControllerTest extends TestCase
$other->closet()->attach($texture->tid, ['item_name' => 'a']);
$this->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([
'errno' => 0,
'code' => 0,
'public' => false,
]);
$this->assertEquals($other->score, User::find($other->uid)->score);
@ -855,8 +855,8 @@ class SkinlibControllerTest extends TestCase
'new_name' => 'name',
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.non-existent'),
'code' => 1,
'message' => trans('skinlib.non-existent'),
]);
// Other user should not be able to rename
@ -866,8 +866,8 @@ class SkinlibControllerTest extends TestCase
'new_name' => 'name',
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.no-permission'),
'code' => 1,
'message' => trans('skinlib.no-permission'),
]);
// Administrators should be able to rename
@ -877,8 +877,8 @@ class SkinlibControllerTest extends TestCase
'new_name' => 'name',
])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.rename.success', ['name' => 'name']),
'code' => 0,
'message' => trans('skinlib.rename.success', ['name' => 'name']),
]);
$this->assertEquals('name', Texture::find($texture->tid)->name);
@ -889,8 +889,8 @@ class SkinlibControllerTest extends TestCase
'new_name' => 'new_name',
])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.rename.success', ['name' => 'new_name']),
'code' => 0,
'message' => trans('skinlib.rename.success', ['name' => 'new_name']),
]);
$this->assertEquals('new_name', Texture::find($texture->tid)->name);
}
@ -908,8 +908,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'alex',
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.non-existent'),
'code' => 1,
'message' => trans('skinlib.non-existent'),
]);
// Other user should not be able to change model
@ -919,8 +919,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'alex',
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.no-permission'),
'code' => 1,
'message' => trans('skinlib.no-permission'),
]);
// Administrators should be able to change model
@ -930,8 +930,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'alex',
])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.model.success', ['model' => 'alex']),
'code' => 0,
'message' => trans('skinlib.model.success', ['model' => 'alex']),
]);
$this->assertEquals('alex', Texture::find($texture->tid)->type);
@ -942,8 +942,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'steve',
])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.model.success', ['model' => 'steve']),
'code' => 0,
'message' => trans('skinlib.model.success', ['model' => 'steve']),
]);
$this->assertEquals('steve', Texture::find($texture->tid)->type);
@ -959,8 +959,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'alex',
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.model.duplicate', ['name' => $duplicate->name]),
'code' => 1,
'message' => trans('skinlib.model.duplicate', ['name' => $duplicate->name]),
]);
// Allow private texture
@ -972,8 +972,8 @@ class SkinlibControllerTest extends TestCase
'model' => 'alex',
])
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.model.success', ['model' => 'alex']),
'code' => 0,
'message' => trans('skinlib.model.success', ['model' => 'alex']),
]);
}
}

View File

@ -73,10 +73,10 @@ class UpdateControllerTest extends TestCase
]);
app()->instance(PackageManager::class, new Concerns\FakePackageManager(null, true));
$this->getJson('/admin/update/download?action=download')
->assertJson(['errno' => 1]);
->assertJson(['code' => 1]);
app()->bind(PackageManager::class, Concerns\FakePackageManager::class);
$this->getJson('/admin/update/download?action=download')
->assertJson(['errno' => 0, 'msg' => trans('admin.update.complete')]);
->assertJson(['code' => 0, 'message' => trans('admin.update.complete')]);
// Get download progress
$this->getJson('/admin/update/download?action=progress')
@ -86,8 +86,8 @@ class UpdateControllerTest extends TestCase
$this->appendToGuzzleQueue(200, [], $this->mockFakeUpdateInfo('8.9.3'));
$this->getJson('/admin/update/download?action=no')
->assertJson([
'errno' => 1,
'msg' => trans('general.illegal-parameters'),
'code' => 1,
'message' => trans('general.illegal-parameters'),
]);
}

View File

@ -69,8 +69,8 @@ class UserControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/sign')
->assertJson([
'errno' => 0,
'msg' => trans('user.sign-success', ['score' => 50]),
'code' => 0,
'message' => trans('user.sign-success', ['score' => 50]),
'score' => option('user_initial_score') + 50,
'storage' => [
'percentage' => 0,
@ -86,8 +86,8 @@ class UserControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/sign')
->assertJson([
'errno' => 1,
'msg' => trans(
'code' => 1,
'message' => trans(
'user.cant-sign-until',
[
'time' => 2,
@ -110,8 +110,8 @@ class UserControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/sign')
->assertJson([
'errno' => 1,
'msg' => trans(
'code' => 1,
'message' => trans(
'user.cant-sign-until',
[
'time' => $diff,
@ -125,7 +125,7 @@ class UserControllerTest extends TestCase
]);
$this->actingAs($user)->postJson('/user/sign')
->assertJson([
'errno' => 0,
'code' => 0,
]);
}
@ -141,8 +141,8 @@ class UserControllerTest extends TestCase
$this->actingAs($unverified)
->postJson('/user/email-verification')
->assertJson([
'errno' => 1,
'msg' => trans('user.verification.disabled'),
'code' => 1,
'message' => trans('user.verification.disabled'),
]);
option(['require_verification' => true]);
@ -153,8 +153,8 @@ class UserControllerTest extends TestCase
])
->postJson('/user/email-verification')
->assertJson([
'errno' => 1,
'msg' => trans('user.verification.frequent-mail'),
'code' => 1,
'message' => trans('user.verification.frequent-mail'),
]);
$this->flushSession();
@ -162,15 +162,15 @@ class UserControllerTest extends TestCase
$this->actingAs($verified)
->postJson('/user/email-verification')
->assertJson([
'errno' => 1,
'msg' => trans('user.verification.verified'),
'code' => 1,
'message' => trans('user.verification.verified'),
]);
$this->actingAs($unverified)
->postJson('/user/email-verification')
->assertJson([
'errno' => 0,
'msg' => trans('user.verification.success'),
'code' => 0,
'message' => trans('user.verification.success'),
]);
Mail::assertSent(EmailVerification::class, function ($mail) use ($unverified) {
return $mail->hasTo($unverified->email);
@ -184,8 +184,8 @@ class UserControllerTest extends TestCase
$this->actingAs($unverified)
->postJson('/user/email-verification')
->assertJson([
'errno' => 2,
'msg' => trans('user.verification.failed', ['msg' => 'A fake exception.']),
'code' => 2,
'message' => trans('user.verification.failed', ['msg' => 'A fake exception.']),
]);
// Addition: Mailable test
@ -211,8 +211,8 @@ class UserControllerTest extends TestCase
$this->actingAs($user)
->postJson('/user/profile')
->assertJson([
'errno' => 1,
'msg' => trans('general.illegal-parameters'),
'code' => 1,
'message' => trans('general.illegal-parameters'),
]);
// Change nickname without `new_nickname` field
@ -235,7 +235,7 @@ class UserControllerTest extends TestCase
option(['single_player' => true]);
factory(\App\Models\Player::class)->create(['uid' => $user->uid]);
$this->postJson('/user/profile', ['action' => 'nickname'])
->assertJson(['errno' => 1, 'msg' => trans('user.profile.nickname.single')]);
->assertJson(['code' => 1, 'message' => trans('user.profile.nickname.single')]);
option(['single_player' => false]);
// Change nickname successfully
@ -244,8 +244,8 @@ class UserControllerTest extends TestCase
'action' => 'nickname',
'new_nickname' => 'nickname',
])->assertJson([
'errno' => 0,
'msg' => trans('user.profile.nickname.success', ['nickname' => 'nickname']),
'code' => 0,
'message' => trans('user.profile.nickname.success', ['nickname' => 'nickname']),
]);
$this->assertEquals('nickname', User::find($user->uid)->nickname);
@ -287,8 +287,8 @@ class UserControllerTest extends TestCase
'current_password' => '1234567',
'new_password' => '87654321',
])->assertJson([
'errno' => 1,
'msg' => trans('user.profile.password.wrong-password'),
'code' => 1,
'message' => trans('user.profile.password.wrong-password'),
]);
// Change password successfully
@ -298,8 +298,8 @@ class UserControllerTest extends TestCase
'current_password' => '12345678',
'new_password' => '87654321',
])->assertJson([
'errno' => 0,
'msg' => trans('user.profile.password.success'),
'code' => 0,
'message' => trans('user.profile.password.success'),
]);
$this->assertTrue(User::find($user->uid)->verifyPassword('87654321'));
// After changed password, user should re-login.
@ -340,8 +340,8 @@ class UserControllerTest extends TestCase
'new_email' => $user->email,
'password' => '87654321',
])->assertJson([
'errno' => 1,
'msg' => trans('user.profile.email.existed'),
'code' => 1,
'message' => trans('user.profile.email.existed'),
]);
// Wrong password
@ -350,8 +350,8 @@ class UserControllerTest extends TestCase
'new_email' => 'a@b.c',
'password' => '7654321',
])->assertJson([
'errno' => 1,
'msg' => trans('user.profile.email.wrong-password'),
'code' => 1,
'message' => trans('user.profile.email.wrong-password'),
]);
// Change email successfully
@ -360,8 +360,8 @@ class UserControllerTest extends TestCase
'new_email' => 'a@b.c',
'password' => '87654321',
])->assertJson([
'errno' => 0,
'msg' => trans('user.profile.email.success'),
'code' => 0,
'message' => trans('user.profile.email.success'),
]);
$this->assertEquals('a@b.c', User::find($user->uid)->email);
$this->assertEquals(0, User::find($user->uid)->verified);
@ -396,8 +396,8 @@ class UserControllerTest extends TestCase
'action' => 'delete',
'password' => '7654321',
])->assertJson([
'errno' => 1,
'msg' => trans('user.profile.delete.wrong-password'),
'code' => 1,
'message' => trans('user.profile.delete.wrong-password'),
]);
// Delete account successfully
@ -405,8 +405,8 @@ class UserControllerTest extends TestCase
'action' => 'delete',
'password' => '87654321',
])->assertJson([
'errno' => 0,
'msg' => trans('user.profile.delete.success'),
'code' => 0,
'message' => trans('user.profile.delete.success'),
]);
$this->assertNull(User::find($user->uid));
@ -416,8 +416,8 @@ class UserControllerTest extends TestCase
'action' => 'delete',
'password' => '87654321',
])->assertJson([
'errno' => 1,
'msg' => trans('user.profile.delete.admin'),
'code' => 1,
'message' => trans('user.profile.delete.admin'),
]);
}
@ -443,8 +443,8 @@ class UserControllerTest extends TestCase
'tid' => -1,
])
->assertJson([
'errno' => 1,
'msg' => trans('skinlib.non-existent'),
'code' => 1,
'message' => trans('skinlib.non-existent'),
]);
// Use cape
@ -453,8 +453,8 @@ class UserControllerTest extends TestCase
'tid' => $cape->tid,
])
->assertJson([
'errno' => 1,
'msg' => trans('user.profile.avatar.wrong-type'),
'code' => 1,
'message' => trans('user.profile.avatar.wrong-type'),
]);
// Success
@ -463,14 +463,14 @@ class UserControllerTest extends TestCase
'tid' => $steve->tid,
])
->assertJson([
'errno' => 0,
'msg' => trans('user.profile.avatar.success'),
'code' => 0,
'message' => trans('user.profile.avatar.success'),
]);
$this->assertEquals($steve->tid, User::find($user->uid)->avatar);
// Reset avatar
$this->postJson('/user/profile/avatar', ['tid' => 0])
->assertJson(['errno' => 0]);
->assertJson(['code' => 0]);
$this->assertEquals(0, User::find($user->uid)->avatar);
}
}

View File

@ -23,6 +23,7 @@
},
"exclude": [
"node_modules",
"plugins",
"vendor"
]
}