tools/scripts/check_server/testcase.js
aozhiwei be1dc9dc2d 1
2022-04-28 12:13:52 +08:00

159 lines
3.5 KiB
JavaScript

const axios = require('axios').default;
const ClientNet = require('./clientnet');
function httpGet(url, params) {
return new Promise((resolve) => {
const ret = {
err: null,
response: null,
};
axios({
method: 'get',
url: url,
timeout: 1000 * 10,
params: params,
responseType: 'text'
}).then((response) => {
ret.response = response.data;
resolve(ret);
}).catch((error) => {
ret.err = error;
resolve(ret);
});
});
}
class TestCase {
constructor(urls) {
this.urls = urls;
this.loginData = '';
this.relationWs = new ClientNet(
this.urls['relation'],
'proto/friend/cs_proto.proto',
'proto/friend/cs_msgid.proto'
);
console.log(this.urls['game2006']);
this.battleWs = new ClientNet(
this.urls['game2006'],
'proto/battle/cs_proto.proto',
'proto/battle/cs_msgid.proto'
);
}
async init() {
await this.step1();
await this.step2();
await this.step3();
await this.step4();
await this.step5();
await this.step6();
await this.step7();
await this.step8();
}
async step1() {
const {err, response} = await httpGet(
this.urls['login'] + '/webapp/index.php',
{
'c': 'Login',
'a': 'auth',
'gameid': 2006,
'channel': 6513,
'account': '123456',
'openid': '123456'
});
this.loginData = response;
console.log('login auth@Login');
console.log(response);
}
async step2() {
const {err, response} = await httpGet(
this.urls['cloud'] + '/webapp/index.php',
{
'c': 'Ops',
'a': 'selfChecking',
});
console.log('cloud selfChecking@Ops');
console.log(response);
}
async step3() {
const {err, response} = await httpGet(
this.urls['service'] + '/webapp/index.php',
{
'c': 'Ops',
'a': 'selfChecking',
});
console.log('service selfChecking@Ops');
console.log(response);
}
async step4() {
const {err, response} = await httpGet(
this.urls['gamelog'] + '/webapp/index.php',
{
'c': 'Ops',
'a': 'selfChecking',
});
console.log('gamelog selfChecking@Ops');
console.log(response);
}
async step5() {
const {err, response} = await httpGet(
this.urls['mail'] + '/webapp/index.php',
{
'c': 'Ops',
'a': 'selfChecking',
});
console.log('mail selfChecking@Ops');
console.log(response);
}
async step6() {
const {err, response} = await httpGet(
this.urls['game2006api'] + '/webapp/index.php',
{
'c': 'Ops',
'a': 'selfChecking',
});
console.log('game2006api selfChecking@Ops');
console.log(response);
}
async step7() {
await this.relationWs.init();
await this.relationWs.connect();
this.relationWs.on('connect', () => {
console.log('relation onConnect');
this.relationWs.registerMsgHandle('SMLogin', (msg) => {
});
this.relationWs.sendMsg('CMLogin', {
accountId: this.loginData['account_id'],
sessionId: this.loginData['session_id'],
});
});
}
async step8() {
await this.battleWs.init();
await this.battleWs.connect();
this.battleWs.on('connect', () => {
console.log('battle onConnect');
this.battleWs.registerMsgHandle('SMJoinedNotify', (msg) => {
});
this.battleWs.sendMsg('CMJoin', {
accountId: this.loginData['account_id'],
sessionId: this.loginData['session_id'],
});
});
}
}
module.exports = TestCase;