blessing-skin-server/resources/assets/tests/scripts/cli/ClosetCommand.test.ts
2025-01-19 14:16:55 +08:00

62 lines
1.6 KiB
TypeScript

import runCommand from '@/scripts/cli/ClosetCommand';
import * as fetch from '@/scripts/net';
import {Stdio} from './stdio';
vi.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'});
});
});