测试:修改测试用例,增加注册账号逻辑
This commit is contained in:
@@ -1,12 +1,57 @@
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkSuccessResponse } from './CheckPatten';
|
||||
import { ON_ADD_CHANNEL_ROUTE } from '../app/consts';
|
||||
import { ON_ADD_CHANNEL_ROUTE, STATUS } from '../app/consts';
|
||||
import { genCode } from '../app/pubUtils/util';
|
||||
const request = require('request');
|
||||
const crypto = require('crypto');
|
||||
|
||||
export class Client {
|
||||
private _client;
|
||||
private _roleInfo;
|
||||
private ENCRYPT_IV = 'f7182j5f04e377ux';
|
||||
private ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj';
|
||||
|
||||
constructor(tel: string = '13636354764') {
|
||||
const param = {tel, deviceId: genCode(10), code: '', platform: 'ios', pkgName: 'com.bantu.zyz', serverType: 'dev'};
|
||||
const paramStr = this.aesEncrypt(JSON.stringify(param), this.ENCRYPT_KEY, this.ENCRYPT_IV);
|
||||
request.post('http://127.0.0.1:7001/user/smslogin', {
|
||||
json: {
|
||||
data: paramStr
|
||||
}
|
||||
}, (err, res, body) => {
|
||||
const loginRes = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV));
|
||||
checkSuccessResponse(loginRes);
|
||||
request.post('http://127.0.0.1:7001/user/checkrole', {
|
||||
json: {
|
||||
data: this.aesEncrypt(JSON.stringify({token: loginRes.data.token, serverId: 1}), this.ENCRYPT_KEY, this.ENCRYPT_IV)
|
||||
}
|
||||
}, (err, res, body) => {
|
||||
const checkRoleRes = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV));
|
||||
if (checkRoleRes.code === 0) {
|
||||
this.createClient(loginRes.data.token);
|
||||
} else {
|
||||
this.createRole(loginRes.data.token, () => {
|
||||
this.createClient(loginRes.data.token);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
createRole(token, sucCB) {
|
||||
request.post('http://127.0.0.1:7001/user/createrole', {
|
||||
json: {
|
||||
data: this.aesEncrypt(JSON.stringify({token, serverId: 1}), this.ENCRYPT_KEY, this.ENCRYPT_IV)
|
||||
}
|
||||
}, (err, res, body) => {
|
||||
const result = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV));
|
||||
checkSuccessResponse(result);
|
||||
sucCB();
|
||||
});
|
||||
}
|
||||
|
||||
createClient(token) {
|
||||
this._client = new PinusWSClient();
|
||||
let host = '127.0.0.1';
|
||||
let port = '3050';
|
||||
@@ -15,21 +60,22 @@ export class Client {
|
||||
port: port
|
||||
}, (data) => {
|
||||
// 连接成功执行函数
|
||||
this._client.request('connector.entryHandler.debugQueryToken', { tel, magicWord: 'zyz666server518' }, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.token).to.be.an('string');
|
||||
this._client.on(ON_ADD_CHANNEL_ROUTE, (msg) => {
|
||||
checkSuccessResponse(msg);
|
||||
expect(msg.data.roleId).to.be.a('string');
|
||||
expect(msg.data.channelName).to.be.a('string');
|
||||
});
|
||||
this._client.request('connector.entryHandler.enter', { serverId: 1, ...res.data }, (enterRes) => {
|
||||
this._client.request('connector.entryHandler.enter', { serverId: 1, token }, (enterRes) => {
|
||||
// 消息回调
|
||||
checkSuccessResponse(enterRes);
|
||||
expect(enterRes.data.role).to.be.an('object');
|
||||
this._roleInfo = enterRes.data.role;
|
||||
this._client.request('role.roleHandler.initRole', { serverId: 1, token, roleName: genCode(8) }, (initRoleRes) => {
|
||||
if (initRoleRes.code !== 0 && initRoleRes.code !== STATUS.ROLE_HAS_INIT.code) {
|
||||
console.error('initRole error', initRoleRes.code, typeof initRoleRes.code);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,4 +86,18 @@ export class Client {
|
||||
get client() {
|
||||
return this._client;
|
||||
}
|
||||
|
||||
private aesEncrypt(data, key, iv) {
|
||||
const cipher = crypto.createCipheriv('aes-192-cbc', key, iv);
|
||||
var crypted = cipher.update(data, 'utf8', 'hex');
|
||||
crypted += cipher.final('hex');
|
||||
return crypted;
|
||||
}
|
||||
|
||||
private aesDecrypt(data, key, iv) {
|
||||
const decipher = crypto.createDecipheriv('aes-192-cbc', key, iv);
|
||||
var decrypted = decipher.update(data, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user