import { Client } from './Client';
import 'mocha';
import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten';
/*
describe('pvp测试', function() {
  let pinusClient: PinusWSClient;
  let detailRoleId;

  beforeEach(function(done) {
    const c = new Client();
    const timer = setInterval(() => {
      if (c.client) {
        pinusClient = c.client;
        clearInterval(timer);
        done();
      }
    }, 500);
  });

  afterEach(function(done) {
    pinusClient.disconnect();
    // disconnect 后等待 500ms，供服务器清理环境、退出频道等
    setTimeout(() => {
      done();
    }, 500);
  });

  it('获得主界面信息', function(done) {
    getData(pinusClient, false, function(data) {
        detailRoleId = data.oppPlayers[0].roleId;
        done();
    }); // 先不结算赛季
  });

  it('获取对手详细信息', function(done) {
    pinusClient.request('battle.pvpHandler.getPlayerDetail', { roleId: detailRoleId }, (res) => {
        checkSuccessResponse(res);
        expect(res.data.roleId).to.be.a('string');
        expect(res.data.roleName).to.be.a('string');
        expect(res.data.lv).to.be.a('number');
        expect(res.data.title).to.be.a('number');
        expect(res.data.head).to.be.a('number');
        expect(res.data.frame).to.be.a('number');
        expect(res.data.spine).to.be.a('number');
        expect(res.data.defCe).to.be.a('number');
        expect(res.data.score).to.be.a('number');
        expect(res.data.rank).to.be.a('number');
        expect(res.data.pLv).to.be.a('number');
        expect(res.data.heroes).to.be.a('array');
        res.data.heroes.forEach(hero => {
            expect(hero.actorId).to.be.a('number');
            expect(hero.lv).to.be.a('number');
            expect(hero.star).to.be.a('number');
            expect(hero.colorStar).to.be.a('number');
            expect(hero.quality).to.be.a('number');
            expect(hero.score).to.be.a('number');
        });
        done();
    });
  });

  it('刷新对手', function(done) {
    pinusClient.request('battle.pvpHandler.debugAddChallengeCnt', { challengeCnt: 1 }, cb => {

      pinusClient.request('battle.pvpHandler.refreshOppPlayer', { }, (res) => {
        checkSuccessResponse(res);
        checkOppPlayers(res.data.oppPlayers);
        expect(res.data.refOppCnt).to.be.a('number');
        done();
    });
    })
  });

  it('获得排行榜', function(done) {
    pinusClient.request('battle.pvpHandler.getRank', { }, (res) => {
        checkSuccessResponse(res);
        expect(res.data.ranks).to.be.a('array');
        res.data.ranks.forEach(rank => {
            checkRank(rank);
        });
        checkRank(res.data.myRank);
        done();
    });
  });

});

function checkRank(rank) {
    expect(rank.rank).to.be.a('number');
    expect(rank.roleId).to.be.a('string');
    expect(rank.roleName).to.be.a('string');
    expect(rank.head).to.be.a('number');
    expect(rank.frame).to.be.a('number');
    expect(rank.spine).to.be.a('number');
    expect(rank.num).to.be.a('number');
    expect(rank.title).to.be.a('number');
    expect(rank.lv).to.be.a('number');
}

function getData(pinusClient, seasonEnd: boolean, cb) {

    pinusClient.request('battle.pvpHandler.getData', {}, (res) => {
        checkSuccessResponse(res);
        expect(res.data.warId).to.be.a('number');
        expect(res.data.seasonNum).to.be.a('number');
        expect(res.data.seasonEndTime).to.be.a('number');
        expect(res.data.myRank).to.be.a('number');
        checkOppPlayers(res.data.oppPlayers);
        expect(res.data.heroes).to.be.a('array');
        res.data.heroes.forEach(hero => {
          expect(hero.actorId).to.be.a('number');
          expect(hero.dataId).to.be.a('number');
          expect(hero.order).to.be.a('number');
        });
        expect(res.data.score).to.be.a('number');
        expect(res.data.pLv).to.be.a('number');
        expect(res.data.winStreakNum).to.be.a('number');
        expect(res.data.challengeCnt).to.be.a('number');
        expect(res.data.challengeRefTime).to.be.a('number');
        expect(res.data.receivedBox).to.be.a('array');
        res.data.receivedBox.forEach(box => {
          expect(box).to.be.a('number');
        });
        expect(res.data.hisScore).to.be.a('number');
        expect(res.data.heroScores).to.be.a('array');
        res.data.heroScores.forEach(heroScore => {
            expect(heroScore.hid).to.be.a('number');
            expect(heroScore.score).to.be.a('number');
        });
        expect(res.data.isFirstEntry).to.be.a('boolean');
        expect(res.data.isDefaultHero).to.be.a('boolean');
        expect(res.data.refOppCnt).to.be.a('number');
        if(seasonEnd) {
            checkSeasonResult(res.data.seasonResult);
        }
        cb(res.data);
      });
}

function checkOppPlayers(oppPlayers) {
    expect(oppPlayers).to.be.a('array');
    oppPlayers.forEach(player => {
      expect(player.pos).to.be.a('number');
      expect(player.defCe).to.be.a('number');
      expect(player.frame).to.be.a('number');
      expect(player.head).to.be.a('number');
      expect(player.lv).to.be.a('number');
      expect(player.oppRoleId).to.be.a('string');
      expect(player.pLv).to.be.a('number');
      expect(player.rankLv).to.be.a('number');
      expect(player.roleName).to.be.a('string');
      expect(player.spine).to.be.a('number');
      expect(player.title).to.be.a('number');
      expect(player.roleId).to.be.a('string');
      expect(player.addScore).to.be.a('number');
      expect(player.plusScore).to.be.a('number');
    });
}

function checkSeasonResult(resultRecord) {
    expect(resultRecord).to.be.a('object');
}
*/