Files
ZYZ/game-server/test/auction.test.ts
2021-03-19 08:33:02 +08:00

282 lines
9.7 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, CURRENCY_BY_TYPE, CURRENCY_TYPE, AUCTION_STAGE, DIVIDEND_STATUS } from '../app/consts';
import { LOT_STATUS } from '../../shared/consts';
const GOOD_ID_TIEJIAN = 1;
const GOOD_ID_GANGJIAN = 2;
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');
}
function checkLots(lots) {
for (let lot of lots) {
checkLot(lot);
}
}
function checkDividend(dividend) {
expect(dividend.sourceType).to.be.a('number');
expect(dividend.sourceCode).to.be.a('string');
expect(dividend.serverId).to.be.a('number');
expect(dividend.guildCode).to.be.a('string');
expect(dividend.code).to.be.a('string');
expect(dividend.status).to.be.a('number');
expect(dividend.totalPrice).to.be.a('number');
expect(dividend.lots).to.be.an('array');
expect(dividend.dividends).to.be.an('array');
expect(Date.parse(dividend.begin)).to.be.a('number');
}
function checkDividends(dividends) {
for (let dividend of dividends) {
checkDividend(dividend);
}
}
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: GOOD_ID_TIEJIAN, count: 1 }, { id: GOOD_ID_GANGJIAN, 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);
expect(res.data.lots).to.be.an('array');
checkLots(res.data.lots);
expect(res.data.dividends).to.be.an('array');
checkDividends(res.data.dividends);
done();
});
});
it('出价,竞价和一口价', function(done) {
let gid = null;
pinusClient.on('onEquipAdd', (res) => {
checkSuccessResponse(res);
expect(res.data.equipInfos).to.be.an('array');
for (let info of res.data.equipInfos) {
expect(info.id).to.be.equal(gid);
}
});
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res);
expect(res.data.lots).to.be.an('array');
checkLots(res.data.lots);
expect(res.data.dividends).to.be.an('array');
checkDividends(res.data.dividends);
if (res.data.lots.length === 0) {
console.warn('没有拍品');
done();
return;
}
let unsoldLots = res.data.lots.filter(lot => {return lot.status !== LOT_STATUS.SOLD && lot.curBuyer !== roleInfo.roleId});
if (unsoldLots.length === 0) {
console.warn('没有可出价的拍品');
done();
return;
}
pinusClient.request('battle.auctionHandler.offer', { code: unsoldLots[0].code, max: false }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
checkDividend(res.data.dividend);
expect(res.data.lot.curBuyer).to.be.equal(roleInfo.roleId);
done();
});
unsoldLots.shift();
if (unsoldLots.length === 0) {
console.warn('没有测试一口价的情况');
done();
return;
}
gid = unsoldLots[0].gid;
pinusClient.request('battle.auctionHandler.offer', { code: unsoldLots[0].code, max: true }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
checkDividend(res.data.dividend);
expect(res.data.lot.curBuyer).to.be.equal(roleInfo.roleId);
setTimeout(() => {
done();
}, 100);
});
});
});
it('关注后取关', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res);
expect(res.data.lots).to.be.an('array');
checkLots(res.data.lots);
expect(res.data.dividends).to.be.an('array');
checkDividends(res.data.dividends);
if (res.data.lots.length === 0) {
console.warn('没有可关注的拍品');
done();
return;
}
const code = res.data.lots[0].code;
pinusClient.request('battle.auctionHandler.watchLot', { code }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
expect(res.data.lot.watchingRoles.indexOf(roleInfo.roleId)).to.be.above(-1);
pinusClient.request('battle.auctionHandler.unWatchLot', { code }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
expect(res.data.lot.watchingRoles.indexOf(roleInfo.roleId)).to.be.equal(-1);
done();
});
});
});
});
it('查看分红', function(done) {
pinusClient.request('battle.auctionHandler.checkDividend', {}, (res) => {
checkSuccessResponse(res);
checkDividends(res.data.dividends);
done();
});
});
it('领取分红', function(done) {
pinusClient.on('onItemUpdate', (res) => {
checkSuccessResponse(res);
expect(res.data.goods).to.be.an('array');
for (let info of res.data.goods) {
expect(info.id).to.be.equal(CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD));
}
});
pinusClient.request('battle.auctionHandler.debugSetDividendStatus', { magicWord: DEBUG_MAGIC_WORD, sourceType: AUCTION_SOURCE.GATE, status: DIVIDEND_STATUS.ING }, (res) => {
checkSuccessResponse(res);
checkDividend(res.data.dividend);
pinusClient.request('battle.auctionHandler.getDividend', { sourceType: AUCTION_SOURCE.GATE }, (res) => {
checkSuccessResponse(res);
expect(res.data.dividend).to.be.an('object');
expect(res.data.dividend.roleId).to.be.a('string');
expect(res.data.dividend.baseNum).to.be.a('number');
expect(res.data.dividend.posNum).to.be.a('number');
expect(res.data.dividend.weekendNum).to.be.a('number');
expect(res.data.dividend.total).to.be.a('number');
expect(res.data.dividend.status).to.be.a('number');
setTimeout(() => {
done();
}, 100);
});
});
});
it('查看我的关注', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res);
expect(res.data.lots).to.be.an('array');
checkLots(res.data.lots);
expect(res.data.dividends).to.be.an('array');
checkDividends(res.data.dividends);
if (res.data.lots.length === 0) {
console.warn('没有可关注的拍品');
done();
return;
}
const code = res.data.lots[0].code;
pinusClient.request('battle.auctionHandler.watchLot', { code }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
expect(res.data.lot.watchingRoles.indexOf(roleInfo.roleId)).to.be.above(-1);
pinusClient.request('battle.auctionHandler.myWatching', {}, (res) => {
checkSuccessResponse(res);
checkLots(res.data.lots);
done();
});
});
});
});
it('更新拍品阶段的测试接口', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res);
expect(res.data.lots).to.be.an('array');
checkLots(res.data.lots);
expect(res.data.dividends).to.be.an('array');
checkDividends(res.data.dividends);
if (res.data.lots.length === 0) {
console.warn('没有可更新阶段的拍品');
done();
return;
}
const code = res.data.lots[0].code;
pinusClient.request('battle.auctionHandler.debugSetLotStage', { code, magicWord: DEBUG_MAGIC_WORD, auctionStage: AUCTION_STAGE.GUILD }, (res) => {
checkSuccessResponse(res);
checkLot(res.data.lot);
done();
});
});
});
it('查看我的拍卖纪录', function(done) {
pinusClient.request('battle.auctionHandler.offerRecs', { count: 10 }, (res) => {
checkSuccessResponse(res);
expect(res.data.bidRecs).to.be.an('array');
for (let bidRec of res.data.bidRecs) {
expect(bidRec.roleId).to.be.a('string');
expect(bidRec.price).to.be.a('number');
expect(Date.parse(bidRec.time)).to.be.a('number');
expect(bidRec.status).to.be.a('number');
expect(bidRec.gid).to.be.a('number');
}
done();
});
});
});