Files
ZYZ/game-server/test/auction.test.ts
2021-03-18 01:25:34 +08:00

122 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Client } from './Client';
import 'mocha';
import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten';
import { DEBUG_MAGIC_WORD, AUCTION_SOURCE } from '../app/consts';
function checkLot(lot) {
expect(lot.auctionStage).to.be.a('number');
expect(lot.sourceType).to.be.a('number');
expect(lot.sourceCode).to.be.a('string');
expect(lot.serverId).to.be.a('number');
expect(lot.guildCode).to.be.a('string');
expect(lot.code).to.be.a('string');
expect(lot.gid).to.be.a('number');
expect(lot.count).to.be.a('number');
expect(lot.maxPrice).to.be.a('number');
expect(lot.curPrice).to.be.a('number');
expect(lot.bidRoles).to.be.a('array');
expect(Date.parse(lot.begin)).to.be.a('number');
expect(Date.parse(lot.end)).to.be.a('number');
}
describe('拍卖行测试', function() {
let pinusClient: PinusWSClient;
let pinusClientT: PinusWSClient; // 用做测试队友
let roleInfo;
let roleInfoT;
beforeEach(function(done) {
const c = new Client();
const cT = new Client('13121622738');
const timer = setInterval(() => {
if (c.client && cT.client) {
pinusClient = c.client;
roleInfo = c.roleInfo;
pinusClientT = cT.client;
roleInfoT = cT.roleInfo;
clearInterval(timer);
done();
}
}, 500);
});
afterEach(function(done) {
pinusClient.disconnect();
pinusClientT.disconnect();
// disconnect 后等待 500ms供服务器清理环境、退出频道等
setTimeout(() => {
done();
}, 500);
});
it('添加拍品', function(done) {
const sourceCode = Math.random().toString(36).slice(-8);
pinusClient.request('battle.auctionHandler.debugAddLots', { magicWord: DEBUG_MAGIC_WORD, sourceType: AUCTION_SOURCE.GATE, sourceCode, rewards: [{ id: 1, count: 1 }, { id: 2, count: 2 }] }, (res) => {
checkSuccessResponse(res);
expect(res.data.lots).to.be.an('array');
for (let lot of res.data.lots) {
checkLot(lot);
}
done();
});
});
it('获取拍卖行数据', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('出价', function(done) {
pinusClient.request('battle.auctionHandler.offer', { code: '', max: false }, (res) => {
// checkSuccessResponse(res, false);
done();
});
});
it('出一口价', function(done) {
pinusClient.request('battle.auctionHandler.offer', { code: '', max: true }, (res) => {
// checkSuccessResponse(res, false);
done();
});
});
it('关注', function(done) {
pinusClient.request('battle.auctionHandler.watchLot', { code: '' }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看分红', function(done) {
pinusClient.request('battle.auctionHandler.checkDividend', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('领取分红', function(done) {
pinusClient.request('battle.auctionHandler.getDividend', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看我的关注', function(done) {
pinusClient.request('battle.auctionHandler.myOffers', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看我的拍卖纪录', function(done) {
pinusClient.request('battle.auctionHandler.offerRecs', { count: 10 }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
});