import { Client } from './Client'; import 'mocha'; import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; import { checkSuccessResponse, checkDisplayItems, checkHero, addItem } from './CheckPatten'; import { GACHA_ID } from '../../shared/consts'; describe('抽卡测试', function () { let pinusClient: PinusWSClient; let roleInfo; beforeEach(function (done) { const c = new Client(); const timer = setInterval(() => { if (c.client) { pinusClient = c.client; roleInfo = c.roleInfo; clearInterval(timer); done(); } }, 500); }); afterEach(function (done) { pinusClient.disconnect(); // disconnect 后等待 500ms,供服务器清理环境、退出频道等 setTimeout(() => { done(); }, 500); }); it('检查获取抽卡列表', function (done) { pinusClient.request('activity.gachaHandler.getGachaList', { }, (res) => { checkSuccessResponse(res); expect(res.data.list).to.be.an('array'); res.data.list.forEach(gacha => { expect(gacha.gachaId).to.be.a('number'); expect(gacha.freeCount).to.be.a('number'); expect(gacha.refFreeTime).to.be.a('number'); expect(gacha.count).to.be.a('number'); checkFloor(gacha.floor); if(gacha.gachaId == GACHA_ID.NORMAL) { checkHope(gacha.hope); expect(gacha.point).to.be.a('number'); checkTurntable(gacha.turntable); } if(gacha.gachaId == GACHA_ID.ASSIGN) { expect(gacha.pickHero).to.be.a('number'); } }); done(); }); }); it('检查元宝招募', function (done) { let gachaId = GACHA_ID.ASSIGN; let hid1 = 1, hid2 = 2; checkSetHope(pinusClient, gachaId, hid1, hid2, function(res) { addItem(pinusClient, 22001, 10, function(res) { checkPull(pinusClient, done, GACHA_ID.NORMAL, 0, 10); }); }) }); it('检查友情点招募', function (done) { addItem(pinusClient, 40003, 1000, function(res) { checkPull(pinusClient, done, GACHA_ID.FRDPOINT, 0, 10); }); }); it('检查求贤若渴招募', function (done) { let gachaId = GACHA_ID.ASSIGN; let pickHero = 1; addItem(pinusClient, 22002, 10, function(res) { checkSetPickHero(pinusClient, gachaId, 0, pickHero, (res) => { checkPull(pinusClient, done, GACHA_ID.ASSIGN, 0, 5); }) }); }); }); function checkFloor(floor) { expect(floor).to.be.an('array'); floor.forEach(f => { expect(f.id).to.be.a('number'); expect(f.count).to.be.a('number'); }) } function checkHope(hope) { expect(hope).to.be.an('array'); hope.forEach(f => { expect(f.id).to.be.a('number'); expect(f.hid).to.be.a('number'); expect(f.hasGet).to.be.a('boolean'); }) } function checkTurntable(turntable) { expect(turntable).to.be.an('array'); turntable.forEach(f => { expect(f.quality).to.be.a('number'); expect(f.hasGet).to.be.a('boolean'); }) } function checkPull(pinusClient, done, gachaId, activityId, count) { pinusClient.request('activity.gachaHandler.pull', { gachaId, activityId, count }, (res) => { checkSuccessResponse(res); expect(res.data.gachaId).to.be.a('number'); checkResult(res.data.result, count); expect(res.data.freeCount).to.be.a('number'); expect(res.data.refFreeTime).to.be.a('number'); expect(res.data.count).to.be.a('number'); checkFloor(res.data.floor); expect(res.data.point).to.be.a('number'); checkHope(res.data.hope); checkHero(res.data.heroes); done() }); } function checkResult(result, count) { expect(result).to.be.an('array'); expect(result.length).equal(count); result.forEach(r => { expect(r.contentId).to.be.a('number'); expect(r.hid).to.be.a('number'); expect(r.isTransfer).to.be.a('boolean'); expect(r.id).to.be.a('number'); expect(r.count).to.be.a('number'); }) } function checkSetPickHero(pinusClient, gachaId, activityId, pickHero, cb) { pinusClient.request('activity.gachaHandler.setPickHero', { gachaId, activityId, pickHero }, (res) => { checkSuccessResponse(res); expect(res.data.gachaId).equal(gachaId); expect(res.data.activityId).equal(activityId); expect(res.data.heroes).to.be.an('array'); res.data.heroes.forEach(hid => { expect(hid).to.be.a('number'); }); expect(res.data.pickHero).equal(pickHero); cb(res); }); } function checkSetHope(pinusClient, gachaId, hid1, hid2, cb) { pinusClient.request('activity.gachaHandler.setHope', { gachaId, hope: [{id: 1, hid: hid1}, {id:2, hid: hid2}] }, (res) => { checkSuccessResponse(res); expect(res.data.gachaId).equal(gachaId); checkHope(res.data.hope) cb(res); }); }