blessing-skin-server/resources/assets/tests/scripts/cli/ClosetCommand.test.ts
2020-03-22 12:21:17 +08:00

62 lines
1.7 KiB
TypeScript

import * as fetch from '@/scripts/net'
import runCommand from '@/scripts/cli/ClosetCommand'
import { Stdio } from './stdio'
jest.mock('@/scripts/net')
describe('add texture', () => {
it('succeeded', async () => {
fetch.post.mockResolvedValue({
code: 0,
data: { user: { nickname: 'kumiko' }, texture: { name: 'eupho' } },
})
const stdio = new Stdio()
await runCommand(stdio, ['add', '1', '2'])
const stdout = stdio.getStdout()
expect(stdout).toInclude('kumiko')
expect(stdout).toInclude('eupho')
expect(fetch.post).toBeCalledWith('/admin/closet/1', { tid: '2' })
})
it('failed', async () => {
fetch.post.mockResolvedValue({ code: 1 })
const stdio = new Stdio()
await runCommand(stdio, ['add', '1', '2'])
const stdout = stdio.getStdout()
expect(stdout).toInclude('Error occurred.')
expect(fetch.post).toBeCalledWith('/admin/closet/1', { tid: '2' })
})
})
describe('remove texture', () => {
it('succeeded', async () => {
fetch.del.mockResolvedValue({
code: 0,
data: { user: { nickname: 'kumiko' }, texture: { name: 'eupho' } },
})
const stdio = new Stdio()
await runCommand(stdio, ['remove', '1', '2'])
const stdout = stdio.getStdout()
expect(stdout).toInclude('kumiko')
expect(stdout).toInclude('eupho')
expect(fetch.del).toBeCalledWith('/admin/closet/1', { tid: '2' })
})
it('failed', async () => {
fetch.del.mockResolvedValue({ code: 1 })
const stdio = new Stdio()
await runCommand(stdio, ['remove', '1', '2'])
const stdout = stdio.getStdout()
expect(stdout).toInclude('Error occurred.')
expect(fetch.del).toBeCalledWith('/admin/closet/1', { tid: '2' })
})
})