Nomalize JSON response structure

This commit is contained in:
Pig Fang 2019-04-23 19:14:41 +08:00
parent fd541e7365
commit 6d03e47526
40 changed files with 349 additions and 331 deletions

View File

@ -154,10 +154,7 @@ class AuthController extends Controller
Auth::login($user); Auth::login($user);
return json([ return json(trans('auth.register.success'), 0);
'code' => 0,
'message' => trans('auth.register.success'),
]);
} }
public function forgot() public function forgot()
@ -190,11 +187,7 @@ class AuthController extends Controller
// Rate limit // Rate limit
if ($remain > 0) { if ($remain > 0) {
return json([ return json(trans('auth.forgot.frequent-mail'), 2);
'code' => 2,
'message' => trans('auth.forgot.frequent-mail'),
'remain' => $remain,
]);
} }
$user = User::where('email', $request->email)->first(); $user = User::where('email', $request->email)->first();

View File

@ -58,9 +58,9 @@ class ClosetController extends Controller
}); });
$totalPages = ceil($items->count() / $perPage); $totalPages = ceil($items->count() / $perPage);
return response()->json([ return json('', 0, [
'category' => $category, 'category' => $category,
'items' => $items, 'items' => $items,
'total_pages' => $totalPages, 'total_pages' => $totalPages,
]); ]);
} }

View File

@ -64,10 +64,15 @@ class PlayerController extends Controller
public function listAll() public function listAll()
{ {
return Auth::user() return json(
->players() '',
->select('pid', 'name', 'tid_skin', 'tid_cape') 0,
->get(); Auth::user()
->players()
->select('pid', 'name', 'tid_skin', 'tid_cape')
->get()
->toArray()
);
} }
public function add(Request $request) public function add(Request $request)
@ -129,11 +134,6 @@ class PlayerController extends Controller
return json(trans('user.player.delete.success', ['name' => $playerName]), 0); return json(trans('user.player.delete.success', ['name' => $playerName]), 0);
} }
public function show()
{
return response()->json($this->player->toArray());
}
public function rename(Request $request) public function rename(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [

View File

@ -42,11 +42,7 @@ class PluginController extends Controller
} }
} }
return json([ return json(trans('admin.plugins.operations.unsatisfied.notice'), 1, compact('reason'));
'code' => 1,
'message' => trans('admin.plugins.operations.unsatisfied.notice'),
'reason' => $reason,
]);
} }
$plugins->enable($name); $plugins->enable($name);

View File

@ -119,8 +119,8 @@ class SkinlibController extends Controller
} }
} }
return response()->json([ return json('', 0, [
'items' => $textures, 'items' => $textures,
'current_uid' => $user ? $user->uid : 0, 'current_uid' => $user ? $user->uid : 0,
'total_pages' => $totalPages, 'total_pages' => $totalPages,
]); ]);
@ -165,9 +165,9 @@ class SkinlibController extends Controller
public function info($tid) public function info($tid)
{ {
if ($t = Texture::find($tid)) { if ($t = Texture::find($tid)) {
return json($t->toArray()); return json('', 0, $t->toArray());
} else { } else {
return json([]); return abort(404);
} }
} }
@ -228,9 +228,7 @@ class SkinlibController extends Controller
// if the texture already uploaded was set to private, // if the texture already uploaded was set to private,
// then allow to re-upload it. // then allow to re-upload it.
if ($result->type == $t->type && $result->public) { if ($result->type == $t->type && $result->public) {
return json(trans('skinlib.upload.repeated'), 0, [ return json(trans('skinlib.upload.repeated'), 0, ['tid' => $result->tid]);
'tid' => $result->tid,
]);
} }
} }
} }
@ -340,11 +338,10 @@ class SkinlibController extends Controller
$t->public = ! $t->public; $t->public = ! $t->public;
$t->save(); $t->save();
return json([ return json(
'code' => 0, trans('skinlib.privacy.success', ['privacy' => (! $t->public ? trans('general.private') : trans('general.public'))]),
'message' => trans('skinlib.privacy.success', ['privacy' => (! $t->public ? trans('general.private') : trans('general.public'))]), 0
'public' => $t->public, );
]);
} }
// @codeCoverageIgnore // @codeCoverageIgnore

View File

@ -45,7 +45,7 @@ class UserController extends Controller
{ {
$user = Auth::user(); $user = Auth::user();
return [ return json('', 0, [
'user' => [ 'user' => [
'score' => $user->score, 'score' => $user->score,
'lastSignAt' => $user->last_sign_at, 'lastSignAt' => $user->last_sign_at,
@ -56,7 +56,7 @@ class UserController extends Controller
], ],
'signAfterZero' => option('sign_after_zero'), 'signAfterZero' => option('sign_after_zero'),
'signGapTime' => option('sign_gap_time'), 'signGapTime' => option('sign_gap_time'),
]; ]);
} }
/** /**
@ -94,11 +94,9 @@ class UserController extends Controller
$acquiredScore = $user->sign(); $acquiredScore = $user->sign();
$gap = option('sign_gap_time'); $gap = option('sign_gap_time');
return json([ return json(trans('user.sign-success', ['score' => $acquiredScore]), 0, [
'code' => 0, 'score' => $user->score,
'message' => trans('user.sign-success', ['score' => $acquiredScore]), 'storage' => $this->calculatePercentageUsed($user->getStorageUsed(), option('score_per_storage')),
'score' => $user->score,
'storage' => $this->calculatePercentageUsed($user->getStorageUsed(), option('score_per_storage')),
'remaining_time' => $gap > 1 ? round($gap) : $gap, 'remaining_time' => $gap > 1 ? round($gap) : $gap,
]); ]);
} else { } else {
@ -130,7 +128,7 @@ class UserController extends Controller
$remain = 60 + session('last_mail_time', 0) - time(); $remain = 60 + session('last_mail_time', 0) - time();
if ($remain > 0) { if ($remain > 0) {
return json(trans('user.verification.frequent-mail')); return json(trans('user.verification.frequent-mail'), 1);
} }
$user = Auth::user(); $user = Auth::user();
@ -250,11 +248,7 @@ class UserController extends Controller
if ($user->delete()) { if ($user->delete()) {
session()->flush(); session()->flush();
return response() return json(trans('user.profile.delete.success'), 0);
->json([
'code' => 0,
'message' => trans('user.profile.delete.success'),
]);
} }
break; // @codeCoverageIgnore break; // @codeCoverageIgnore

View File

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

View File

@ -20,10 +20,7 @@ class CheckPlayerOwner
$player = Player::find($pid); $player = Player::find($pid);
if ($player->uid != auth()->id()) { if ($player->uid != auth()->id()) {
return response()->json([ return json(trans('admin.players.no-permission'), 1);
'code' => 1,
'message' => trans('admin.players.no-permission'),
]);
} }
} }

View File

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

View File

@ -71,7 +71,7 @@ export default {
}, },
methods: { methods: {
async fetchList() { async fetchList() {
this.players = await this.$http.get('/user/player/list') this.players = (await this.$http.get('/user/player/list')).data
}, },
async submit() { async submit() {
if (!this.selected) { if (!this.selected) {

View File

@ -22,11 +22,11 @@ export default Vue.extend({
} }
const { const {
code, message, reason, code, message, data: { reason } = { reason: [] },
} = await this.$http.post( } = await this.$http.post(
'/admin/plugins/manage', '/admin/plugins/manage',
{ action: 'enable', name } { action: 'enable', name }
) as { code: number, message: string, reason: string[] } ) as { code: number, message: string, data: { reason: string[] } }
if (code === 0) { if (code === 0) {
this.$message.success(message) this.$message.success(message)
this.$set(this.plugins[originalIndex], 'enabled', true) this.$set(this.plugins[originalIndex], 'enabled', true)

View File

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

View File

@ -99,7 +99,7 @@ export default {
this.pending = true this.pending = true
const { const {
code, message, login_fails: loginFails, code, message, data: { login_fails: loginFails } = { login_fails: 0 },
} = await this.$http.post( } = await this.$http.post(
'/auth/login', '/auth/login',
{ {

View File

@ -176,7 +176,9 @@ export default {
async fetchData() { async fetchData() {
this.pending = true this.pending = true
const { const {
items, total_pages: totalPages, current_uid: currentUid, data: {
items, total_pages: totalPages, current_uid: currentUid,
},
} = await this.$http.get( } = await this.$http.get(
'/skinlib/data', '/skinlib/data',
{ {

View File

@ -220,7 +220,7 @@ export default {
}, },
methods: { methods: {
async fetchData() { async fetchData() {
const data = await this.$http.get(`/skinlib/info/${this.tid}`) const { data = {} } = await this.$http.get(`/skinlib/info/${this.tid}`)
this.name = data.name this.name = data.name
this.type = data.type this.type = data.type
this.likes = data.likes this.likes = data.likes

View File

@ -160,7 +160,7 @@ export default {
this.uploading = true this.uploading = true
const { const {
code, message, tid, code, message, data: { tid } = { tid: 0 },
} = await this.$http.post('/skinlib/upload', data) } = await this.$http.post('/skinlib/upload', data)
if (code === 0) { if (code === 0) {
this.$message.success(message) this.$message.success(message)

View File

@ -49,7 +49,7 @@ export default {
}, },
methods: { methods: {
async fetchPlayers() { async fetchPlayers() {
const players = await this.$http.get('/user/player/list') const players = (await this.$http.get('/user/player/list')).data
this.players = players.map(player => player.name) this.players = players.map(player => player.name)
;[this.selected] = this.players ;[this.selected] = this.players
}, },

View File

@ -200,7 +200,9 @@ export default {
search() {}, // eslint-disable-line no-empty-function search() {}, // eslint-disable-line no-empty-function
async loadCloset(page = 1) { async loadCloset(page = 1) {
const { const {
items, category, total_pages: totalPages, data: {
items, category, total_pages: totalPages,
},
} = await this.$http.get( } = await this.$http.get(
'/user/closet-data', '/user/closet-data',
{ {
@ -226,7 +228,7 @@ export default {
this.loadCloset(page) this.loadCloset(page)
}, },
async selectTexture(tid) { async selectTexture(tid) {
const { type, hash } = await this.$http.get(`/skinlib/info/${tid}`) const { data: { type, hash } } = await this.$http.get(`/skinlib/info/${tid}`)
if (type === 'cape') { if (type === 'cape') {
this.capeUrl = `/textures/${hash}` this.capeUrl = `/textures/${hash}`
this.selectedCape = tid this.selectedCape = tid

View File

@ -176,7 +176,7 @@ export default {
}, },
methods: { methods: {
async fetchScoreInfo() { async fetchScoreInfo() {
const data = await this.$http.get('/user/score-info') const { data } = await this.$http.get('/user/score-info')
this.lastSignAt = new Date(data.user.lastSignAt) this.lastSignAt = new Date(data.user.lastSignAt)
this.signAfterZero = data.signAfterZero this.signAfterZero = data.signAfterZero
this.signGap = data.signGapTime * 3600 * 1000 this.signGap = data.signGapTime * 3600 * 1000
@ -187,16 +187,18 @@ export default {
this.score = data.user.score this.score = data.user.score
}, },
async sign() { async sign() {
const result = await this.$http.post('/user/sign') const {
code, message, data,
} = await this.$http.post('/user/sign')
if (result.code === 0) { if (code === 0) {
this.$message.success(result.message) this.$message.success(message)
this.score = result.score this.score = data.score
this.lastSignAt = new Date() this.lastSignAt = new Date()
this.storageUsed = result.storage.used this.storageUsed = data.storage.used
this.storageTotal = result.storage.total this.storageTotal = data.storage.total
} else { } else {
this.$message.warning(result.message) this.$message.warning(message)
} }
}, },
}, },

View File

@ -195,7 +195,7 @@ export default {
}, },
methods: { methods: {
async fetchPlayers() { async fetchPlayers() {
this.players = await this.$http.get('/user/player/list') this.players = (await this.$http.get('/user/player/list')).data
}, },
togglePreviewer() { togglePreviewer() {
this.using3dPreviewer = !this.using3dPreviewer this.using3dPreviewer = !this.using3dPreviewer
@ -207,13 +207,13 @@ export default {
this.preview2d.cape = player.tid_cape this.preview2d.cape = player.tid_cape
if (player.tid_skin) { if (player.tid_skin) {
const skin = await this.$http.get(`/skinlib/info/${player.tid_skin}`) const { data: skin } = await this.$http.get(`/skinlib/info/${player.tid_skin}`)
this.skinUrl = `${this.baseUrl}/textures/${skin.hash}` this.skinUrl = `${this.baseUrl}/textures/${skin.hash}`
} else { } else {
this.skinUrl = '' this.skinUrl = ''
} }
if (player.tid_cape) { if (player.tid_cape) {
const cape = await this.$http.get(`/skinlib/info/${player.tid_cape}`) const { data: cape } = await this.$http.get(`/skinlib/info/${player.tid_cape}`)
this.capeUrl = `${this.baseUrl}/textures/${cape.hash}` this.capeUrl = `${this.baseUrl}/textures/${cape.hash}`
} else { } else {
this.capeUrl = '' this.capeUrl = ''

View File

@ -4,7 +4,7 @@ import ApplyToPlayerDialog from '@/components/ApplyToPlayerDialog.vue'
test('submit applying texture', async () => { test('submit applying texture', async () => {
window.$ = jest.fn(() => ({ modal() {} })) window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValue([{ pid: 1 }]) Vue.prototype.$http.get.mockResolvedValue({ data: [{ pid: 1 }] })
Vue.prototype.$http.post.mockResolvedValueOnce({ code: 1 }) Vue.prototype.$http.post.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0, message: 'ok' }) .mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(ApplyToPlayerDialog) const wrapper = mount(ApplyToPlayerDialog)
@ -46,7 +46,7 @@ test('submit applying texture', async () => {
}) })
test('compute avatar URL', () => { test('compute avatar URL', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
const wrapper = mount<Vue & { avatarUrl(player: { tid_skin: number }): string }>(ApplyToPlayerDialog) const wrapper = mount<Vue & { avatarUrl(player: { tid_skin: number }): string }>(ApplyToPlayerDialog)
const { avatarUrl } = wrapper.vm const { avatarUrl } = wrapper.vm

View File

@ -57,7 +57,7 @@ test('enable plugin', async () => {
]) ])
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ .mockResolvedValueOnce({
code: 1, message: '1', reason: ['`a<div></div>`b'], code: 1, message: '1', data: { reason: ['`a<div></div>`b'] },
}) })
.mockResolvedValue({ code: 0, message: '0' }) .mockResolvedValue({ code: 0, message: '0' })
Vue.prototype.$confirm Vue.prototype.$confirm

View File

@ -38,7 +38,7 @@ test('delete texture', async () => {
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: 'fail' }) .mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({ .mockResolvedValue({
code: 0, message: 'ok', status: 1, code: 0, message: 'ok', data: { status: 1 },
}) })
const wrapper = mount(Reports) const wrapper = mount(Reports)
await wrapper.vm.$nextTick() 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.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValue({ .mockResolvedValue({
code: 0, message: 'ok', status: 1, code: 0, message: 'ok', data: { status: 1 },
}) })
const wrapper = mount(Reports) const wrapper = mount(Reports)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -82,7 +82,7 @@ test('reject', async () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] }) Vue.prototype.$http.get.mockResolvedValue({ data: [{ id: 1, status: 0 }] })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValue({ .mockResolvedValue({
code: 0, message: 'ok', status: 2, code: 0, message: 'ok', data: { status: 2 },
}) })
const wrapper = mount(Reports) const wrapper = mount(Reports)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()

View File

@ -22,9 +22,9 @@ test('login', async () => {
window.blessing.extra = { tooManyFails: false } window.blessing.extra = { tooManyFails: false }
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: 'fail' }) .mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 1, login_fails: 4 }) .mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 1, login_fails: 4 }) .mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 1, login_fails: 4 }) .mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 0, message: 'ok' }) .mockResolvedValueOnce({ code: 0, message: 'ok' })
const wrapper = mount(Login, { stubs: { Captcha } }) const wrapper = mount(Login, { stubs: { Captcha } })
const form = wrapper.find('form') const form = wrapper.find('form')

View File

@ -45,7 +45,9 @@ jest.mock('element-ui/lib/option', () => ({
test('fetch data before mounting', () => { test('fetch data before mounting', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
mount(List) mount(List)
expect(Vue.prototype.$http.get).toBeCalledWith( expect(Vue.prototype.$http.get).toBeCalledWith(
@ -58,7 +60,9 @@ test('fetch data before mounting', () => {
test('empty skin library', () => { test('empty skin library', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
expect(wrapper.text()).toContain('general.noResult') expect(wrapper.text()).toContain('general.noResult')
@ -66,7 +70,9 @@ test('empty skin library', () => {
test('toggle texture type', () => { test('toggle texture type', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
const select = wrapper.find({ name: 'ElSelect' }) const select = wrapper.find({ name: 'ElSelect' })
@ -104,7 +110,9 @@ test('toggle texture type', () => {
test('check specified uploader', async () => { test('check specified uploader', async () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 1, data: {
items: [], total_pages: 0, current_uid: 1,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -127,7 +135,9 @@ test('check specified uploader', async () => {
test('sort items', () => { test('sort items', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
const buttons = wrapper.find('.advanced-filter').findAll(Button) const buttons = wrapper.find('.advanced-filter').findAll(Button)
@ -155,7 +165,9 @@ test('sort items', () => {
test('search by keyword', () => { test('search by keyword', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
@ -180,7 +192,9 @@ test('search by keyword', () => {
test('reset all filters', () => { test('reset all filters', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount(List) const wrapper = mount(List)
wrapper.findAll('option').at(3) wrapper.findAll('option').at(3)
@ -196,7 +210,9 @@ test('reset all filters', () => {
test('is anonymous', () => { test('is anonymous', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount<Vue & { anonymous: boolean }>(List) const wrapper = mount<Vue & { anonymous: boolean }>(List)
expect(wrapper.vm.anonymous).toBeTrue() expect(wrapper.vm.anonymous).toBeTrue()
@ -204,7 +220,9 @@ test('is anonymous', () => {
test('on page changed', () => { test('on page changed', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], total_pages: 0, current_uid: 0, data: {
items: [], total_pages: 0, current_uid: 0,
},
}) })
const wrapper = mount<Vue & { pageChanged(page: number): void }>(List) const wrapper = mount<Vue & { pageChanged(page: number): void }>(List)
wrapper.vm.pageChanged(2) wrapper.vm.pageChanged(2)
@ -218,11 +236,13 @@ test('on page changed', () => {
test('on like toggled', async () => { test('on like toggled', async () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [{ data: {
tid: 1, liked: false, likes: 0, items: [{
}], tid: 1, liked: false, likes: 0,
total_pages: 1, }],
current_uid: 0, total_pages: 1,
current_uid: 0,
},
}) })
const wrapper = mount<Vue & { const wrapper = mount<Vue & {
onLikeToggled(tid: number, like: boolean): void, onLikeToggled(tid: number, like: boolean): void,

View File

@ -28,7 +28,7 @@ const previewer = Vue.extend({
}) })
test('button for adding to closet should be disabled if not auth', () => { test('button for adding to closet should be disabled if not auth', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -39,7 +39,7 @@ test('button for adding to closet should be disabled if not auth', () => {
}) })
test('button for adding to closet should be disabled if auth', () => { test('button for adding to closet should be disabled if auth', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
Object.assign(window.blessing.extra, { inCloset: true, currentUid: 1 }) Object.assign(window.blessing.extra, { inCloset: true, currentUid: 1 })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
@ -51,7 +51,7 @@ test('button for adding to closet should be disabled if auth', () => {
}) })
test('likes count indicator', async () => { test('likes count indicator', async () => {
Vue.prototype.$http.get.mockResolvedValue({ likes: 2 }) Vue.prototype.$http.get.mockResolvedValue({ data: { likes: 2 } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -65,11 +65,13 @@ test('likes count indicator', async () => {
test('render basic information', async () => { test('render basic information', async () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
name: 'my-texture', data: {
type: 'alex', name: 'my-texture',
hash: '123', type: 'alex',
size: 2, hash: '123',
upload_at: '2018', size: 2,
upload_at: '2018',
},
}) })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
@ -88,7 +90,7 @@ test('render basic information', async () => {
test('render action text of editing texture name', async () => { test('render action text of editing texture name', async () => {
Object.assign(window.blessing.extra, { admin: true }) Object.assign(window.blessing.extra, { admin: true })
Vue.prototype.$http.get.mockResolvedValue({ uploader: 1, name: 'name' }) Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1, name: 'name' } })
let wrapper = mount(Show, { let wrapper = mount(Show, {
mocks: { mocks: {
@ -110,7 +112,7 @@ test('render action text of editing texture name', async () => {
test('render nickname of uploader', () => { test('render nickname of uploader', () => {
Object.assign(window.blessing.extra, { nickname: null }) Object.assign(window.blessing.extra, { nickname: null })
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -121,7 +123,7 @@ test('render nickname of uploader', () => {
test('operation panel should not be rendered if not auth', () => { test('operation panel should not be rendered if not auth', () => {
Object.assign(window.blessing.extra, { currentUid: 0 }) Object.assign(window.blessing.extra, { currentUid: 0 })
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -132,7 +134,7 @@ test('operation panel should not be rendered if not auth', () => {
test('download texture', async () => { test('download texture', async () => {
Object.assign(window.blessing.extra, { currentUid: 1 }) Object.assign(window.blessing.extra, { currentUid: 1 })
Vue.prototype.$http.get.mockResolvedValue({ tid: 1, name: 'abc' }) Vue.prototype.$http.get.mockResolvedValue({ data: { tid: 1, name: 'abc' } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -144,7 +146,7 @@ test('download texture', async () => {
test('link to downloading texture', async () => { test('link to downloading texture', async () => {
Object.assign(window.blessing.extra, { download: false }) Object.assign(window.blessing.extra, { download: false })
Vue.prototype.$http.get.mockResolvedValue({ hash: '123' }) Vue.prototype.$http.get.mockResolvedValue({ data: { hash: '123' } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -157,7 +159,7 @@ test('link to downloading texture', async () => {
test('set as avatar', async () => { test('set as avatar', async () => {
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true }) Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
Vue.prototype.$http.get.mockResolvedValueOnce({ type: 'steve' }) Vue.prototype.$http.get.mockResolvedValueOnce({ data: { type: 'steve' } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -170,7 +172,7 @@ test('set as avatar', async () => {
}) })
test('hide "set avatar" button when texture is cape', async () => { test('hide "set avatar" button when texture is cape', async () => {
Vue.prototype.$http.get.mockResolvedValueOnce({ type: 'cape' }) Vue.prototype.$http.get.mockResolvedValueOnce({ data: { type: 'cape' } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
@ -183,7 +185,7 @@ test('hide "set avatar" button when texture is cape', async () => {
test('add to closet', async () => { test('add to closet', async () => {
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false }) Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false })
Vue.prototype.$http.get.mockResolvedValue({ name: 'wow', likes: 2 }) Vue.prototype.$http.get.mockResolvedValue({ data: { name: 'wow', likes: 2 } })
Vue.prototype.$http.post.mockResolvedValue({ code: 0, message: '' }) Vue.prototype.$http.post.mockResolvedValue({ code: 0, message: '' })
Vue.prototype.$prompt.mockResolvedValue({ value: 'a' } as MessageBoxData) Vue.prototype.$prompt.mockResolvedValue({ value: 'a' } as MessageBoxData)
const wrapper = mount<Component>(Show, { const wrapper = mount<Component>(Show, {
@ -200,7 +202,7 @@ test('add to closet', async () => {
test('remove from closet', async () => { test('remove from closet', async () => {
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true }) Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
Vue.prototype.$http.get.mockResolvedValue({ likes: 2 }) Vue.prototype.$http.get.mockResolvedValue({ data: { likes: 2 } })
Vue.prototype.$http.post.mockResolvedValue({ code: 0 }) Vue.prototype.$http.post.mockResolvedValue({ code: 0 })
const wrapper = mount<Component>(Show, { const wrapper = mount<Component>(Show, {
mocks: { mocks: {
@ -216,7 +218,7 @@ test('remove from closet', async () => {
test('change texture name', async () => { test('change texture name', async () => {
Object.assign(window.blessing.extra, { admin: true }) Object.assign(window.blessing.extra, { admin: true })
Vue.prototype.$http.get.mockResolvedValue({ name: 'old-name' }) Vue.prototype.$http.get.mockResolvedValue({ data: { name: 'old-name' } })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' }) .mockResolvedValue({ code: 0, message: '0' })
@ -254,7 +256,7 @@ test('change texture name', async () => {
}) })
test('change texture model', async () => { test('change texture model', async () => {
Vue.prototype.$http.get.mockResolvedValue({ type: 'steve' }) Vue.prototype.$http.get.mockResolvedValue({ data: { type: 'steve' } })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' }) .mockResolvedValue({ code: 0, message: '0' })
@ -297,7 +299,7 @@ test('change texture model', async () => {
}) })
test('toggle privacy', async () => { test('toggle privacy', async () => {
Vue.prototype.$http.get.mockResolvedValue({ public: true }) Vue.prototype.$http.get.mockResolvedValue({ data: { public: true } })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' }) .mockResolvedValue({ code: 0, message: '0' })
@ -336,7 +338,7 @@ test('toggle privacy', async () => {
}) })
test('delete texture', async () => { test('delete texture', async () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' }) .mockResolvedValue({ code: 0, message: '0' })
@ -372,7 +374,7 @@ test('delete texture', async () => {
}) })
test('report texture', async () => { test('report texture', async () => {
Vue.prototype.$http.get.mockResolvedValue({ report: 0 }) Vue.prototype.$http.get.mockResolvedValue({ data: { report: 0 } })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: 'duplicated' }) .mockResolvedValueOnce({ code: 1, message: 'duplicated' })
.mockResolvedValue({ code: 0, message: 'success' }) .mockResolvedValue({ code: 0, message: 'success' })
@ -422,7 +424,7 @@ test('report texture', async () => {
test('apply texture to player', () => { test('apply texture to player', () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValue({}) .mockResolvedValue({ data: {} })
.mockResolvedValue([]) .mockResolvedValue([])
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {

View File

@ -116,7 +116,7 @@ test('upload file', async () => {
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ .mockResolvedValueOnce({
code: 0, message: '0', tid: 1, code: 0, message: '0', data: { tid: 1 },
}) })
const wrapper = mount(Upload, { const wrapper = mount(Upload, {

View File

@ -4,7 +4,7 @@ import Bind from '@/views/user/Bind.vue'
test('list existed players', async () => { test('list existed players', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValue([{ name: 'a' }, { name: 'b' }]) .mockResolvedValue({ data: [{ name: 'a' }, { name: 'b' }] })
const wrapper = mount(Bind) const wrapper = mount(Bind)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
const options = wrapper.findAll('option') const options = wrapper.findAll('option')
@ -12,7 +12,7 @@ test('list existed players', async () => {
}) })
test('show input box', async () => { test('show input box', async () => {
Vue.prototype.$http.get.mockResolvedValue([]) Vue.prototype.$http.get.mockResolvedValue({ data: [] })
const wrapper = mount(Bind) const wrapper = mount(Bind)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
const input = wrapper.find('input') const input = wrapper.find('input')
@ -20,7 +20,7 @@ test('show input box', async () => {
}) })
test('submit', async () => { test('submit', async () => {
Vue.prototype.$http.get.mockResolvedValue([]) Vue.prototype.$http.get.mockResolvedValue({ data: [] })
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: 'fail' }) .mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValueOnce({ code: 0, message: 'ok' }) .mockResolvedValueOnce({ code: 0, message: 'ok' })

View File

@ -7,7 +7,7 @@ import Previewer from '@/components/Previewer.vue'
window.blessing.extra = { unverified: false } window.blessing.extra = { unverified: false }
test('fetch closet data before mount', () => { test('fetch closet data before mount', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
mount(Closet) mount(Closet)
jest.runAllTicks() jest.runAllTicks()
expect(Vue.prototype.$http.get).toBeCalledWith( expect(Vue.prototype.$http.get).toBeCalledWith(
@ -22,13 +22,17 @@ test('fetch closet data before mount', () => {
test('switch tabs', () => { test('switch tabs', () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [], data: {
category: 'skin', items: [],
total_pages: 1, category: 'skin',
total_pages: 1,
},
}).mockResolvedValueOnce({ }).mockResolvedValueOnce({
items: [], data: {
category: 'cape', items: [],
total_pages: 1, category: 'cape',
total_pages: 1,
},
}) })
const wrapper = mount(Closet) const wrapper = mount(Closet)
@ -58,7 +62,7 @@ test('switch tabs', () => {
}) })
test('different categories', () => { test('different categories', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Closet) const wrapper = mount(Closet)
expect(wrapper.findAll('.nav-tabs > li').at(0) expect(wrapper.findAll('.nav-tabs > li').at(0)
@ -72,7 +76,7 @@ test('different categories', () => {
}) })
test('search textures', () => { test('search textures', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Closet) const wrapper = mount(Closet)
const input = wrapper.find('input') const input = wrapper.find('input')
@ -91,7 +95,7 @@ test('search textures', () => {
}) })
test('empty closet', () => { test('empty closet', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Closet) const wrapper = mount(Closet)
expect(wrapper.find('#skin-category').text()).toContain('user.emptyClosetMsg') expect(wrapper.find('#skin-category').text()).toContain('user.emptyClosetMsg')
wrapper.setData({ category: 'cape' }) wrapper.setData({ category: 'cape' })
@ -99,7 +103,7 @@ test('empty closet', () => {
}) })
test('no matched search result', () => { test('no matched search result', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Closet) const wrapper = mount(Closet)
wrapper.setData({ query: 'q' }) wrapper.setData({ query: 'q' })
expect(wrapper.find('#skin-category').text()).toContain('general.noResult') expect(wrapper.find('#skin-category').text()).toContain('general.noResult')
@ -109,12 +113,14 @@ test('no matched search result', () => {
test('render items', async () => { test('render items', async () => {
Vue.prototype.$http.get.mockResolvedValue({ Vue.prototype.$http.get.mockResolvedValue({
items: [ data: {
{ tid: 1 }, items: [
{ tid: 2 }, { tid: 1 },
], { tid: 2 },
category: 'skin', ],
total_pages: 1, category: 'skin',
total_pages: 1,
},
}) })
const wrapper = mount(Closet) const wrapper = mount(Closet)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -122,7 +128,7 @@ test('render items', async () => {
}) })
test('reload closet when page changed', () => { test('reload closet when page changed', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount<Vue & { pageChanged(): void }>(Closet) const wrapper = mount<Vue & { pageChanged(): void }>(Closet)
wrapper.vm.pageChanged() wrapper.vm.pageChanged()
jest.runAllTicks() jest.runAllTicks()
@ -130,7 +136,7 @@ test('reload closet when page changed', () => {
}) })
test('remove skin item', () => { test('remove skin item', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount<Vue & { removeSkinItem(tid: number): void }>(Closet) const wrapper = mount<Vue & { removeSkinItem(tid: number): void }>(Closet)
wrapper.setData({ skinItems: [{ tid: 1 }] }) wrapper.setData({ skinItems: [{ tid: 1 }] })
wrapper.vm.removeSkinItem(0) wrapper.vm.removeSkinItem(0)
@ -138,7 +144,7 @@ test('remove skin item', () => {
}) })
test('remove cape item', () => { test('remove cape item', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount<Vue & { removeCapeItem(tid: number): void }>(Closet) const wrapper = mount<Vue & { removeCapeItem(tid: number): void }>(Closet)
wrapper.setData({ capeItems: [{ tid: 1 }], category: 'cape' }) wrapper.setData({ capeItems: [{ tid: 1 }], category: 'cape' })
wrapper.vm.removeCapeItem(0) wrapper.vm.removeCapeItem(0)
@ -147,9 +153,9 @@ test('remove cape item', () => {
test('select texture', async () => { test('select texture', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce({}) .mockResolvedValueOnce({ data: {} })
.mockResolvedValueOnce({ type: 'steve', hash: 'a' }) .mockResolvedValueOnce({ data: { type: 'steve', hash: 'a' } })
.mockResolvedValueOnce({ type: 'cape', hash: 'b' }) .mockResolvedValueOnce({ data: { type: 'cape', hash: 'b' } })
const wrapper = mount<Vue & { skinUrl: string, capeUrl: string }>(Closet) const wrapper = mount<Vue & { skinUrl: string, capeUrl: string }>(Closet)
wrapper.setData({ skinItems: [{ tid: 1 }] }) wrapper.setData({ skinItems: [{ tid: 1 }] })
@ -169,13 +175,15 @@ test('select texture', async () => {
test('apply texture', async () => { test('apply texture', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce({}) .mockResolvedValueOnce({ data: {} })
.mockResolvedValueOnce([]) .mockResolvedValueOnce({ data: [] })
.mockResolvedValueOnce([ .mockResolvedValueOnce({
{ data: [
pid: 1, name: 'name', tid_skin: 10, {
}, pid: 1, name: 'name', tid_skin: 10,
]) },
],
})
const wrapper = mount(Closet) const wrapper = mount(Closet)
const button = wrapper.find(Previewer).findAll('button') const button = wrapper.find(Previewer).findAll('button')
@ -193,7 +201,7 @@ test('apply texture', async () => {
}) })
test('reset selected texture', () => { test('reset selected texture', () => {
Vue.prototype.$http.get.mockResolvedValue({}) Vue.prototype.$http.get.mockResolvedValue({ data: {} })
const wrapper = mount(Closet) const wrapper = mount(Closet)
wrapper.setData({ wrapper.setData({
selectedSkin: 1, selectedSkin: 1,
@ -217,11 +225,13 @@ test('select specified texture initially', async () => {
})) }))
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce({ .mockResolvedValueOnce({
items: [], data: {
category: 'skin', items: [],
total_pages: 1, category: 'skin',
total_pages: 1,
},
}) })
.mockResolvedValueOnce({ type: 'cape', hash: '' }) .mockResolvedValueOnce({ data: { type: 'cape', hash: '' } })
.mockResolvedValueOnce([]) .mockResolvedValueOnce([])
const wrapper = mount(Closet) const wrapper = mount(Closet)
jest.runAllTimers() jest.runAllTimers()

View File

@ -26,18 +26,20 @@ window.blessing.extra = { unverified: false }
function scoreInfo(data = {}) { function scoreInfo(data = {}) {
return { return {
user: { score: 835, lastSignAt: '2018-08-07 16:06:49' }, data: {
stats: { user: { score: 835, lastSignAt: '2018-08-07 16:06:49' },
players: { stats: {
used: 3, total: 15, percentage: 20, players: {
}, used: 3, total: 15, percentage: 20,
storage: { },
used: 5, total: 20, percentage: 25, storage: {
used: 5, total: 20, percentage: 25,
},
}, },
signAfterZero: false,
signGapTime: '24',
...data,
}, },
signAfterZero: false,
signGapTime: '24',
...data,
} }
} }
@ -140,11 +142,15 @@ test('sign', async () => {
user: { lastSignAt: Date.now() - 30 * 3600 * 1000 }, user: { lastSignAt: Date.now() - 30 * 3600 * 1000 },
})) }))
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' }) .mockResolvedValueOnce({
code: 1, message: '1', data: {},
})
.mockResolvedValueOnce({ .mockResolvedValueOnce({
code: 0, code: 0,
score: 233, data: {
storage: { used: 3, total: 4 }, score: 233,
storage: { used: 3, total: 4 },
},
}) })
const wrapper = mount(Dashboard) const wrapper = mount(Dashboard)
const button = wrapper.find(Button) const button = wrapper.find(Button)

View File

@ -11,6 +11,7 @@ window.blessing.extra = {
} }
test('display player name constraints', () => { test('display player name constraints', () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [] })
const wrapper = mount(Players) const wrapper = mount(Players)
const text = wrapper.text() const text = wrapper.text()
expect(text).toContain('rule') expect(text).toContain('rule')
@ -18,31 +19,33 @@ test('display player name constraints', () => {
}) })
test('fetch players data before mount', () => { test('fetch players data before mount', () => {
Vue.prototype.$http.get.mockResolvedValue([]) Vue.prototype.$http.get.mockResolvedValue({ data: [] })
mount(Players) mount(Players)
expect(Vue.prototype.$http.get).toBeCalledWith('/user/player/list') expect(Vue.prototype.$http.get).toBeCalledWith('/user/player/list')
}) })
test('click to preview player', async () => { test('click to preview player', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce([ .mockResolvedValueOnce({
{ data: [
pid: 1, tid_skin: 1, tid_cape: 3, {
}, pid: 1, tid_skin: 1, tid_cape: 3,
{ },
pid: 2, tid_skin: 0, tid_cape: 0, {
}, pid: 2, tid_skin: 0, tid_cape: 0,
{ },
pid: 3, tid_skin: 2, tid_cape: 0, {
}, pid: 3, tid_skin: 2, tid_cape: 0,
{ },
pid: 4, tid_skin: 0, tid_cape: 5, {
}, pid: 4, tid_skin: 0, tid_cape: 5,
]) },
.mockResolvedValueOnce({ hash: 'a' }) ],
.mockResolvedValueOnce({ hash: 'b' }) })
.mockResolvedValueOnce({ hash: 'c' }) .mockResolvedValueOnce({ data: { hash: 'a' } })
.mockResolvedValueOnce({ hash: 'd' }) .mockResolvedValueOnce({ data: { hash: 'b' } })
.mockResolvedValueOnce({ data: { hash: 'c' } })
.mockResolvedValueOnce({ data: { hash: 'd' } })
const wrapper = mount(Players) const wrapper = mount(Players)
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -69,9 +72,11 @@ test('click to preview player', async () => {
test('change player name', async () => { test('change player name', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce([ .mockResolvedValue({
{ pid: 1, name: 'old' }, data: [
]) { pid: 1, name: 'old' },
],
})
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1 }) .mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0 }) .mockResolvedValue({ code: 0 })
@ -103,9 +108,11 @@ test('change player name', async () => {
test('delete player', async () => { test('delete player', async () => {
Vue.prototype.$http.get Vue.prototype.$http.get
.mockResolvedValueOnce([ .mockResolvedValueOnce({
{ pid: 1, name: 'to-be-deleted' }, data: [
]) { pid: 1, name: 'to-be-deleted' },
],
})
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1 }) .mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0 }) .mockResolvedValue({ code: 0 })
@ -128,7 +135,7 @@ test('delete player', async () => {
}) })
test('toggle preview mode', () => { test('toggle preview mode', () => {
Vue.prototype.$http.get.mockResolvedValueOnce([]) Vue.prototype.$http.get.mockResolvedValueOnce({ data: [] })
const wrapper = mount(Players) const wrapper = mount(Players)
wrapper.find('[data-test="to2d"]').trigger('click') wrapper.find('[data-test="to2d"]').trigger('click')
expect(wrapper.text()).toContain('user.player.texture-empty') expect(wrapper.text()).toContain('user.player.texture-empty')
@ -136,7 +143,7 @@ test('toggle preview mode', () => {
test('add player', async () => { test('add player', async () => {
window.$ = jest.fn(() => ({ modal() {} })) window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValueOnce([]) Vue.prototype.$http.get.mockResolvedValueOnce({ data: [] })
Vue.prototype.$http.post.mockResolvedValue({ code: 0 }) Vue.prototype.$http.post.mockResolvedValue({ code: 0 })
const wrapper = mount(Players) const wrapper = mount(Players)
const button = wrapper.find('[data-test=addPlayer]') const button = wrapper.find('[data-test=addPlayer]')
@ -149,11 +156,13 @@ test('add player', async () => {
test('clear texture', async () => { test('clear texture', async () => {
window.$ = jest.fn(() => ({ modal() {} })) window.$ = jest.fn(() => ({ modal() {} }))
Vue.prototype.$http.get.mockResolvedValueOnce([ Vue.prototype.$http.get.mockResolvedValueOnce({
{ data: [
pid: 1, tid_skin: 1, tid_cape: 0, {
}, pid: 1, tid_skin: 1, tid_cape: 0,
]) },
],
})
Vue.prototype.$http.post Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1 }) .mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0, message: 'ok' }) .mockResolvedValue({ code: 0, message: 'ok' })

View File

@ -65,7 +65,6 @@ Route::group([
Route::any('', 'PlayerController@index'); Route::any('', 'PlayerController@index');
Route::get('/list', 'PlayerController@listAll'); Route::get('/list', 'PlayerController@listAll');
Route::post('/add', 'PlayerController@add'); Route::post('/add', 'PlayerController@add');
Route::any('/show', 'PlayerController@show');
Route::post('/set', 'PlayerController@setTexture'); Route::post('/set', 'PlayerController@setTexture');
Route::post('/texture/clear', 'PlayerController@clearTexture'); Route::post('/texture/clear', 'PlayerController@clearTexture');
Route::post('/rename', 'PlayerController@rename'); Route::post('/rename', 'PlayerController@rename');

View File

@ -688,6 +688,7 @@ class AdminControllerTest extends BrowserKitTestCase
$this->postJson('/admin/players', [ $this->postJson('/admin/players', [
'pid' => $player->pid, 'pid' => $player->pid,
'action' => 'name', 'action' => 'name',
'name' => 'abc',
])->seeJson(['code' => 0]); ])->seeJson(['code' => 0]);
$player->refresh(); $player->refresh();
$this->assertEquals('abc', $player->user->nickname); $this->assertEquals('abc', $player->user->nickname);

View File

@ -81,7 +81,7 @@ class AuthControllerTest extends TestCase
[ [
'code' => 1, 'code' => 1,
'message' => trans('auth.validation.password'), 'message' => trans('auth.validation.password'),
'login_fails' => 1, 'data' => ['login_fails' => 1],
] ]
); );
$this->assertTrue(Cache::has($loginFailsCacheKey)); $this->assertTrue(Cache::has($loginFailsCacheKey));

View File

@ -37,24 +37,26 @@ class ClosetControllerTest extends TestCase
// Use default query parameters // Use default query parameters
$this->getJson('/user/closet-data') $this->getJson('/user/closet-data')
->assertJsonStructure([ ->assertJsonStructure([
'category', 'data' => [
'total_pages', 'category',
'items' => [['tid', 'name', 'type']], 'total_pages',
'items' => [['tid', 'name', 'type']],
]
]); ]);
// Responsive // Responsive
$result = $this->json('get', '/user/closet-data?perPage=0')->json(); $result = $this->json('get', '/user/closet-data?perPage=0')->json()['data'];
$this->assertCount(6, $result['items']); $this->assertCount(6, $result['items']);
$result = $this->json('get', '/user/closet-data?perPage=8')->json(); $result = $this->json('get', '/user/closet-data?perPage=8')->json()['data'];
$this->assertCount(8, $result['items']); $this->assertCount(8, $result['items']);
$result = $this->json('get', '/user/closet-data?perPage=8&page=2')->json(); $result = $this->json('get', '/user/closet-data?perPage=8&page=2')->json()['data'];
$this->assertCount(2, $result['items']); $this->assertCount(2, $result['items']);
// Get capes // Get capes
$cape = factory(Texture::class, 'cape')->create(); $cape = factory(Texture::class, 'cape')->create();
$this->user->closet()->attach($cape->tid, ['item_name' => 'custom_name']); $this->user->closet()->attach($cape->tid, ['item_name' => 'custom_name']);
$this->getJson('/user/closet-data?category=cape') $this->getJson('/user/closet-data?category=cape')
->assertJson([ ->assertJson(['data' => [
'category' => 'cape', 'category' => 'cape',
'total_pages' => 1, 'total_pages' => 1,
'items' => [[ 'items' => [[
@ -62,12 +64,12 @@ class ClosetControllerTest extends TestCase
'name' => 'custom_name', 'name' => 'custom_name',
'type' => 'cape', 'type' => 'cape',
]], ]],
]); ]]);
// Search by keyword // Search by keyword
$random = $textures->random(); $random = $textures->random();
$this->getJson('/user/closet-data?q='.$random->name) $this->getJson('/user/closet-data?q='.$random->name)
->assertJson([ ->assertJson(['data' => [
'category' => 'skin', 'category' => 'skin',
'total_pages' => 1, 'total_pages' => 1,
'items' => [[ 'items' => [[
@ -75,7 +77,7 @@ class ClosetControllerTest extends TestCase
'name' => $random->name, 'name' => $random->name,
'type' => $random->type, 'type' => $random->type,
]], ]],
]); ]]);
} }
public function testAdd() public function testAdd()

View File

@ -30,12 +30,12 @@ class PlayerControllerTest extends TestCase
$player = factory(Player::class)->create(['uid' => $user->uid]); $player = factory(Player::class)->create(['uid' => $user->uid]);
$this->actingAs($user) $this->actingAs($user)
->get('/user/player/list') ->get('/user/player/list')
->assertJson([ ->assertJson(['data' => [
[ [
'pid' => $player->pid, 'pid' => $player->pid,
'name' => $player->name, 'name' => $player->name,
], ],
]); ]]);
} }
public function testAdd() public function testAdd()
@ -153,13 +153,6 @@ class PlayerControllerTest extends TestCase
$this->assertNotNull(Player::find($player->pid)); $this->assertNotNull(Player::find($player->pid));
} }
public function testShow()
{
$player = factory(Player::class)->create(['last_modified' => '2017-11-11 22:51:00']);
$this->get('/user/player/show?pid='.$player->pid)
->assertJson($player->toArray());
}
public function testRename() public function testRename()
{ {
Event::fake(); Event::fake();

View File

@ -74,15 +74,17 @@ class PluginControllerTest extends TestCase
])->assertJson([ ])->assertJson([
'code' => 1, 'code' => 1,
'message' => trans('admin.plugins.operations.unsatisfied.notice'), 'message' => trans('admin.plugins.operations.unsatisfied.notice'),
'reason' => [ 'data' => [
trans('admin.plugins.operations.unsatisfied.version', [ 'reason' => [
'name' => 'fake-plugin-with-config-view', trans('admin.plugins.operations.unsatisfied.version', [
'constraint' => '^6.6.6', 'name' => 'fake-plugin-with-config-view',
]), 'constraint' => '^6.6.6',
trans('admin.plugins.operations.unsatisfied.disabled', [ ]),
'name' => 'whatever', trans('admin.plugins.operations.unsatisfied.disabled', [
]), 'name' => 'whatever',
], ]),
],
]
]); ]);
// Enable a plugin // Enable a plugin

View File

@ -159,7 +159,7 @@ class ReportControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('general.op-success'), 'message' => trans('general.op-success'),
'status' => Report::REJECTED, 'data' => ['status' => Report::REJECTED],
]); ]);
$report->refresh(); $report->refresh();
$reporter->refresh(); $reporter->refresh();
@ -186,7 +186,7 @@ class ReportControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('general.op-success'), 'message' => trans('general.op-success'),
'status' => Report::RESOLVED, 'data' => ['status' => Report::RESOLVED],
]); ]);
$report->refresh(); $report->refresh();
$reporter->refresh(); $reporter->refresh();
@ -207,7 +207,7 @@ class ReportControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('general.op-success'), 'message' => trans('general.op-success'),
'status' => Report::RESOLVED, 'data' => ['status' => Report::RESOLVED],
]); ]);
$reporter->refresh(); $reporter->refresh();
$this->assertEquals(User::BANNED, $uploader->permission); $this->assertEquals(User::BANNED, $uploader->permission);

View File

@ -22,11 +22,11 @@ class SkinlibControllerTest extends TestCase
public function testGetSkinlibFiltered() public function testGetSkinlibFiltered()
{ {
$this->getJson('/skinlib/data') $this->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'items' => [], 'items' => [],
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 0, 'total_pages' => 0,
]); ]]);
$steves = factory(Texture::class)->times(5)->create(); $steves = factory(Texture::class)->times(5)->create();
$alexs = factory(Texture::class, 'alex')->times(5)->create(); $alexs = factory(Texture::class, 'alex')->times(5)->create();
@ -35,11 +35,11 @@ class SkinlibControllerTest extends TestCase
// Default arguments // Default arguments
$items = $this->getJson('/skinlib/data') $items = $this->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(10, $items); $this->assertCount(10, $items);
$this->assertTrue(collect($items)->every(function ($item) { $this->assertTrue(collect($items)->every(function ($item) {
return $item['type'] == 'steve' || $item['type'] == 'alex'; return $item['type'] == 'steve' || $item['type'] == 'alex';
@ -47,11 +47,11 @@ class SkinlibControllerTest extends TestCase
// Only steve // Only steve
$items = $this->getJson('/skinlib/data?filter=steve') $items = $this->getJson('/skinlib/data?filter=steve')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(5, $items); $this->assertCount(5, $items);
$this->assertTrue(collect($items)->every(function ($item) { $this->assertTrue(collect($items)->every(function ($item) {
return $item['type'] == 'steve'; return $item['type'] == 'steve';
@ -59,19 +59,19 @@ class SkinlibControllerTest extends TestCase
// Invalid type // Invalid type
$this->getJson('/skinlib/data?filter=what') $this->getJson('/skinlib/data?filter=what')
->assertJson([ ->assertJson(['data' => [
'items' => [], 'items' => [],
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 0, 'total_pages' => 0,
]); ]]);
// Only capes // Only capes
$items = $this->getJson('/skinlib/data?filter=cape') $items = $this->getJson('/skinlib/data?filter=cape')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(5, $items); $this->assertCount(5, $items);
$this->assertTrue(collect($items)->every(function ($item) { $this->assertTrue(collect($items)->every(function ($item) {
return $item['type'] == 'cape'; return $item['type'] == 'cape';
@ -84,11 +84,11 @@ class SkinlibControllerTest extends TestCase
return $texture->uploader == $uid; return $texture->uploader == $uid;
}); });
$items = $this->getJson('/skinlib/data?uploader='.$uid) $items = $this->getJson('/skinlib/data?uploader='.$uid)
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount($owned->count(), $items); $this->assertCount($owned->count(), $items);
$this->assertTrue(collect($items)->every(function ($item) use ($uid) { $this->assertTrue(collect($items)->every(function ($item) use ($uid) {
return $item['uploader'] == $uid; return $item['uploader'] == $uid;
@ -99,11 +99,11 @@ class SkinlibControllerTest extends TestCase
return $skin->tid; return $skin->tid;
})->values(); })->values();
$items = $this->getJson('/skinlib/data?sort=tid') $items = $this->getJson('/skinlib/data?sort=tid')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$items = array_map(function ($item) { $items = array_map(function ($item) {
return $item['tid']; return $item['tid'];
}, $items); }, $items);
@ -113,11 +113,11 @@ class SkinlibControllerTest extends TestCase
$user = factory(User::class)->create(); $user = factory(User::class)->create();
$user->closet()->attach($skins->random()->tid, ['item_name' => 'name']); $user->closet()->attach($skins->random()->tid, ['item_name' => 'name']);
$items = $this->getJson('/skinlib/data?sort=likes') $items = $this->getJson('/skinlib/data?sort=likes')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertEquals(1, $items[0]['likes']); $this->assertEquals(1, $items[0]['likes']);
$this->assertEquals(0, $items[1]['likes']); $this->assertEquals(0, $items[1]['likes']);
@ -129,11 +129,11 @@ class SkinlibControllerTest extends TestCase
Str::contains($texture->name, strtolower($keyword)); Str::contains($texture->name, strtolower($keyword));
}); });
$items = $this->getJson('/skinlib/data?keyword='.$keyword) $items = $this->getJson('/skinlib/data?keyword='.$keyword)
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount($keyworded->count(), $items); $this->assertCount($keyworded->count(), $items);
// More than one argument // More than one argument
@ -149,11 +149,11 @@ class SkinlibControllerTest extends TestCase
}) })
->values(); ->values();
$items = $this->getJson('/skinlib/data?sort=size&keyword='.$keyword) $items = $this->getJson('/skinlib/data?sort=size&keyword='.$keyword)
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 1, 'total_pages' => 1,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$items = array_map(function ($item) { $items = array_map(function ($item) {
return $item['tid']; return $item['tid'];
}, $items); }, $items);
@ -167,47 +167,47 @@ class SkinlibControllerTest extends TestCase
->merge($steves); ->merge($steves);
$skins = $steves->merge($alexs); $skins = $steves->merge($alexs);
$items = $this->getJson('/skinlib/data') $items = $this->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(20, $items); $this->assertCount(20, $items);
$items = $this->getJson('/skinlib/data?page=-5') $items = $this->getJson('/skinlib/data?page=-5')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(20, $items); $this->assertCount(20, $items);
$page2Count = $skins->forPage(2, 20)->count(); $page2Count = $skins->forPage(2, 20)->count();
$items = $this->getJson('/skinlib/data?page=2') $items = $this->getJson('/skinlib/data?page=2')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount(5, $items); $this->assertCount(5, $items);
$this->getJson('/skinlib/data?page=8') $this->getJson('/skinlib/data?page=8')
->assertJson([ ->assertJson(['data' => [
'items' => [], 'items' => [],
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]); ]]);
$items = $this->getJson('/skinlib/data?items_per_page=-6&page=2') $items = $this->getJson('/skinlib/data?items_per_page=-6&page=2')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount($page2Count, $items); $this->assertCount($page2Count, $items);
$page3Count = $skins->forPage(3, 8)->count(); $page3Count = $skins->forPage(3, 8)->count();
$items = $this->getJson('/skinlib/data?page=3&items_per_page=8') $items = $this->getJson('/skinlib/data?page=3&items_per_page=8')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 4, 'total_pages' => 4,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertCount($page3Count, $items); $this->assertCount($page3Count, $items);
// Add some private textures // Add some private textures
@ -219,11 +219,11 @@ class SkinlibControllerTest extends TestCase
// If not logged in, private textures should not be shown // If not logged in, private textures should not be shown
$items = $this->getJson('/skinlib/data') $items = $this->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => 0, 'current_uid' => 0,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertTrue(collect($items)->every(function ($item) { $this->assertTrue(collect($items)->every(function ($item) {
return $item['public'] == true; return $item['public'] == true;
})); }));
@ -231,11 +231,11 @@ class SkinlibControllerTest extends TestCase
// Other users should not see someone's private textures // Other users should not see someone's private textures
$items = $this->actingAs($otherUser) $items = $this->actingAs($otherUser)
->getJson('/skinlib/data') ->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => $otherUser->uid, 'current_uid' => $otherUser->uid,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertTrue(collect($items)->every(function ($item) { $this->assertTrue(collect($items)->every(function ($item) {
return ! $item['liked']; return ! $item['liked'];
})); }));
@ -244,22 +244,22 @@ class SkinlibControllerTest extends TestCase
$texture = $skins->sortByDesc('upload_at')->values()->first(); $texture = $skins->sortByDesc('upload_at')->values()->first();
$otherUser->closet()->attach($texture->tid, ['item_name' => $texture->name]); $otherUser->closet()->attach($texture->tid, ['item_name' => $texture->name]);
$this->getJson('/skinlib/data') $this->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'items' => [ 'items' => [
['tid' => $texture->tid, 'liked' => true], ['tid' => $texture->tid, 'liked' => true],
], ],
'current_uid' => $otherUser->uid, 'current_uid' => $otherUser->uid,
'total_pages' => 2, 'total_pages' => 2,
]); ]]);
// Uploader can see his private textures // Uploader can see his private textures
$items = $this->actingAs($uploader) $items = $this->actingAs($uploader)
->getJson('/skinlib/data') ->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => $uploader->uid, 'current_uid' => $uploader->uid,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertTrue(collect($items)->contains(function ($item) { $this->assertTrue(collect($items)->contains(function ($item) {
return $item['public'] == false; return $item['public'] == false;
})); }));
@ -268,11 +268,11 @@ class SkinlibControllerTest extends TestCase
$admin = factory(User::class, 'admin')->create(); $admin = factory(User::class, 'admin')->create();
$items = $this->actingAs($admin) $items = $this->actingAs($admin)
->getJson('/skinlib/data') ->getJson('/skinlib/data')
->assertJson([ ->assertJson(['data' => [
'current_uid' => $admin->uid, 'current_uid' => $admin->uid,
'total_pages' => 2, 'total_pages' => 2,
]) ]])
->decodeResponseJson('items'); ->decodeResponseJson('data')['items'];
$this->assertTrue(collect($items)->contains(function ($item) { $this->assertTrue(collect($items)->contains(function ($item) {
return $item['public'] == false; return $item['public'] == false;
})); }));
@ -335,11 +335,11 @@ class SkinlibControllerTest extends TestCase
public function testInfo() public function testInfo()
{ {
// Non-existed texture // Non-existed texture
$this->get('/skinlib/info/1')->assertJson([]); $this->get('/skinlib/info/1')->assertNotFound();
$texture = factory(Texture::class)->create(); $texture = factory(Texture::class)->create();
$this->get('/skinlib/info/'.$texture->tid) $this->get('/skinlib/info/'.$texture->tid)
->assertJson([ ->assertJson(['data' => [
'tid' => $texture->tid, 'tid' => $texture->tid,
'name' => $texture->name, 'name' => $texture->name,
'type' => $texture->type, 'type' => $texture->type,
@ -349,7 +349,7 @@ class SkinlibControllerTest extends TestCase
'uploader' => $texture->uploader, 'uploader' => $texture->uploader,
'public' => $texture->public, 'public' => $texture->public,
'upload_at' => $texture->upload_at->format('Y-m-d H:i:s'), 'upload_at' => $texture->upload_at->format('Y-m-d H:i:s'),
]); ]]);
} }
public function testUpload() public function testUpload()
@ -555,7 +555,7 @@ class SkinlibControllerTest extends TestCase
$response->assertJson([ $response->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('skinlib.upload.success', ['name' => 'texture']), 'message' => trans('skinlib.upload.success', ['name' => 'texture']),
'tid' => $t->tid, 'data' => ['tid' => $t->tid],
]); ]);
Storage::disk('textures')->assertExists($t->hash); Storage::disk('textures')->assertExists($t->hash);
$user = User::find($user->uid); $user = User::find($user->uid);
@ -581,7 +581,7 @@ class SkinlibControllerTest extends TestCase
)->assertJson([ )->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('skinlib.upload.repeated'), 'message' => trans('skinlib.upload.repeated'),
'tid' => $t->tid, 'data' => ['tid' => $t->tid],
]); ]);
unlink(storage_path('framework/testing/disks/textures/'.$t->hash)); unlink(storage_path('framework/testing/disks/textures/'.$t->hash));
@ -744,7 +744,6 @@ class SkinlibControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), 'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]); ]);
$this->assertEquals(0, Texture::find($texture->tid)->public); $this->assertEquals(0, Texture::find($texture->tid)->public);
@ -769,7 +768,6 @@ class SkinlibControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), 'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]); ]);
$this->assertEquals(0, User::find($uploader->uid)->score); $this->assertEquals(0, User::find($uploader->uid)->score);
@ -785,7 +783,6 @@ class SkinlibControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]), 'message' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => false,
]); ]);
$this->assertEquals(0, Player::find($player->pid)->tid_skin); $this->assertEquals(0, Player::find($player->pid)->tid_skin);
$this->assertEquals(0, $other->closet()->count()); $this->assertEquals(0, $other->closet()->count());
@ -812,10 +809,7 @@ class SkinlibControllerTest extends TestCase
$other = factory(User::class)->create(); $other = factory(User::class)->create();
$other->closet()->attach($texture->tid, ['item_name' => 'a']); $other->closet()->attach($texture->tid, ['item_name' => 'a']);
$this->postJson('/skinlib/privacy', ['tid' => $texture->tid]) $this->postJson('/skinlib/privacy', ['tid' => $texture->tid])
->assertJson([ ->assertJson(['code' => 0]);
'code' => 0,
'public' => false,
]);
$this->assertEquals($other->score, User::find($other->uid)->score); $this->assertEquals($other->score, User::find($other->uid)->score);
} }

View File

@ -38,7 +38,7 @@ class UserControllerTest extends TestCase
$this->actingAs($user) $this->actingAs($user)
->get('/user/score-info') ->get('/user/score-info')
->assertJson([ ->assertJson(['data' => [
'user' => [ 'user' => [
'score' => $user->score, 'score' => $user->score,
'lastSignAt' => $user->last_sign_at, 'lastSignAt' => $user->last_sign_at,
@ -57,7 +57,7 @@ class UserControllerTest extends TestCase
], ],
'signAfterZero' => option('sign_after_zero'), 'signAfterZero' => option('sign_after_zero'),
'signGapTime' => option('sign_gap_time'), 'signGapTime' => option('sign_gap_time'),
]); ]]);
} }
public function testSign() public function testSign()
@ -71,13 +71,15 @@ class UserControllerTest extends TestCase
->assertJson([ ->assertJson([
'code' => 0, 'code' => 0,
'message' => trans('user.sign-success', ['score' => 50]), 'message' => trans('user.sign-success', ['score' => 50]),
'score' => option('user_initial_score') + 50, 'data' => [
'storage' => [ 'score' => option('user_initial_score') + 50,
'percentage' => 0, 'storage' => [
'total' => option('user_initial_score') + 50, 'percentage' => 0,
'used' => 0, 'total' => option('user_initial_score') + 50,
], 'used' => 0,
'remaining_time' => (int) option('sign_gap_time'), ],
'remaining_time' => (int) option('sign_gap_time'),
]
]); ]);
// Remaining time is greater than 0 // Remaining time is greater than 0
@ -123,10 +125,7 @@ class UserControllerTest extends TestCase
$user = factory(User::class)->create([ $user = factory(User::class)->create([
'last_sign_at' => \Carbon\Carbon::today()->toDateTimeString(), 'last_sign_at' => \Carbon\Carbon::today()->toDateTimeString(),
]); ]);
$this->actingAs($user)->postJson('/user/sign') $this->actingAs($user)->postJson('/user/sign')->assertJson(['code' => 0]);
->assertJson([
'code' => 0,
]);
} }
public function testSendVerificationEmail() public function testSendVerificationEmail()