测试:抽卡测试

This commit is contained in:
luying
2021-04-30 19:29:20 +08:00
parent 524ed6d05e
commit f5654c402f
4 changed files with 199 additions and 1 deletions

View File

@@ -275,6 +275,7 @@ export class GachaHandler {
return resResult(STATUS.SUCCESS, {
gachaId,
activityId,
heroes,
pickHero: userGacha.pickHero
});

View File

@@ -14,4 +14,41 @@ export function checkDisplayItems(items) {
expect(item.id).to.be.a('number');
expect(item.count).to.be.a('number');
})
}
export function checkHero(heroes) {
expect(heroes).to.be.an('array');
heroes.forEach(hero => {
expect(hero.seqId).to.be.a('number');
expect(hero.hid).to.be.a('number');
expect(hero.hName).to.be.a('string');
expect(hero.lv).to.be.a('number');
expect(hero.exp).to.be.a('number');
expect(hero.star).to.be.a('number');
expect(hero.starStage).to.be.a('number');
expect(hero.colorStar).to.be.a('number');
expect(hero.colorStarStage).to.be.a('number');
expect(hero.quality).to.be.a('number');
expect(hero.job).to.be.a('number');
expect(hero.jobStage).to.be.a('number');
expect(hero.connections).to.be.an('array');
hero.connections.forEach(connection => {
expect(connection.shipId).to.be.a('number');
expect(connection.level).to.be.a('number');
});
expect(hero.favour).to.be.a('number');
expect(hero.favourLv).to.be.a('number');
expect(hero.connections).to.be.an('array');
hero.skins.forEach(skin => {
expect(skin.id).to.be.a('number');
expect(skin.enable).to.be.a('boolean');
});
})
}
export function addItem(pinusClient, id, count, cb) {
pinusClient.request('role.heroHandler.addItem', { id, count }, res => {
checkSuccessResponse(res);
cb(res);
});
}

View File

@@ -0,0 +1,160 @@
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);
});
}

View File

@@ -88,7 +88,7 @@ export class GachaListReturn {
floor: Floor[] = []; // 整体保底
hope: Hope[] = []; // 心愿单
point: number = 0; // 积分
turntable: Turntable[]; // 转盘记录
turntable: Turntable[] = []; // 转盘记录
pickHero: number = 0; // 玩家选择的武将
constructor(dicGacha: DicGacha, userGacha: UserGachaType) {