聊天:军团修改公告的推送和测试
This commit is contained in:
@@ -21,6 +21,7 @@ import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
import { unlockTrain } from '../../../services/guildTrainService';
|
||||
import { removeBossRank } from '../../../services/guildBossService';
|
||||
import { removeTrainRank } from '../../../services/guildTrainService';
|
||||
import { pushGuildNoticeUpdateMsg } from '../../../services/chatService';
|
||||
export default function (app: Application) {
|
||||
return new GuildHandler(app);
|
||||
}
|
||||
@@ -118,6 +119,7 @@ export class GuildHandler {
|
||||
async setGuildInfo(msg: { code: string, name: string, notice: string, introduce: string, ceLimit: number, isAuto: boolean }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const { code, name, notice, introduce, ceLimit, isAuto } = msg;
|
||||
if(!name) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
@@ -129,9 +131,11 @@ export class GuildHandler {
|
||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { name, notice, introduce, ceLimit, isAuto });
|
||||
|
||||
await redisUserInfoUpdate(REDIS_KEY.GUILD_INFO, code, [{ field: 'name', value: name }]);
|
||||
if (notice) {
|
||||
pushGuildNoticeUpdateMsg(roleId, roleName, guild);
|
||||
}
|
||||
// 返回
|
||||
return resResult(STATUS.SUCCESS, { ...guild });
|
||||
|
||||
}
|
||||
|
||||
// 游客查看军团详细信息
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isString } from 'underscore';
|
||||
import { cloneDeep, pick } from 'lodash';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { GroupMessageModel } from './../db/GroupMessage';
|
||||
@@ -11,6 +12,7 @@ import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_GROU
|
||||
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
||||
import { crc32 } from 'crc';
|
||||
import { HeroType } from '../db/Hero';
|
||||
import { GuildType } from '../db/Guild';
|
||||
|
||||
/**
|
||||
* @description 生成私聊房间号
|
||||
@@ -203,7 +205,7 @@ export function wrapRichText(type: string, jumpTo: string, content: string, parm
|
||||
});
|
||||
}
|
||||
|
||||
export async function pushNormalHeroInfoBySource(roleId: string, roleName: string, serverId: number | string, source: number, heroInfo: Partial<HeroType>) {
|
||||
async function pushNormalHeroInfoBySource(roleId: string, roleName: string, serverId: number | string, source: number, heroInfo: Partial<HeroType>) {
|
||||
const hero = pick(heroInfo, ['hName', 'hid', 'seqId', 'quality', 'star', 'starStage', 'colorStar', 'colorStarStage']);
|
||||
const content = JSON.stringify({ roleId, roleName, hero });
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
||||
@@ -230,3 +232,12 @@ export async function pushComBtlTeamMsg(teamCode: string, roleId: string, roleNa
|
||||
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, msgData));
|
||||
return msgData;
|
||||
}
|
||||
|
||||
export async function pushGuildNoticeUpdateMsg(roleId: string, roleName: string, guildInfo: Partial<GuildType>) {
|
||||
const { code, notice } = guildInfo;
|
||||
if (!code || !isString(notice)) return null;
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GUILD, code, MSG_TYPE.TEXT, MSG_SOURCE.GUILD_NOTICE, notice, null, null);
|
||||
if (!msgData) return null;
|
||||
await pushGroupMsgToRoom(groupRoomId(CHANNEL_PREFIX.GUILD, code), msgData);
|
||||
return msgData;
|
||||
}
|
||||
|
||||
@@ -216,18 +216,18 @@ describe('聊天测试', function() {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: 升品推送测试
|
||||
it('测试系统频道升品消息', function(done) {
|
||||
let msgReceiveCnt = 0;
|
||||
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
function checkHeroInfoRes(res) {
|
||||
checkSuccessResponse(res);
|
||||
checkHeroInfoStr(res.data.content);
|
||||
msgReceiveCnt += 1;
|
||||
}
|
||||
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkHeroInfoRes(res);
|
||||
});
|
||||
pinusClient.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkHeroInfoStr(res.data.content);
|
||||
msgReceiveCnt += 1;
|
||||
checkHeroInfoRes(res);
|
||||
});
|
||||
pinusClient.request('role.heroHandler.testCleanUp', { magicWord: DEBUG_MAGIC_WORD, hid: XIAHOUQINGYI_HID }, (cleanUpRes) => {
|
||||
if (cleanUpRes.code !== STATUS.HERO_NOT_FIND.code) {
|
||||
@@ -270,4 +270,41 @@ describe('聊天测试', function() {
|
||||
it('测试军团频道消息', function(done) {
|
||||
testGroupMsg(pinusClient, roleInfo, pinusClientT, CHANNEL_PREFIX.GUILD, roleInfo.guildCode, done);
|
||||
});
|
||||
|
||||
it('测试军团通知修改推送', function(done) {
|
||||
const newNotice = new Date().toLocaleDateString();
|
||||
let msgReceiveCnt = 0;
|
||||
function checkNoticeRes(res) {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.content).to.be.equal(newNotice);
|
||||
msgReceiveCnt += 1;
|
||||
}
|
||||
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkNoticeRes(res);
|
||||
});
|
||||
pinusClient.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkNoticeRes(res);
|
||||
});
|
||||
pinusClient.request('battle.guildHandler.getMyGuildInfo', { }, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data).to.have.deep.property('hasGuild').that.is.an('boolean');
|
||||
if(res.data.hasGuild) {
|
||||
expect(res.data).to.have.deep.property('code').that.is.an('string');
|
||||
expect(res.data).to.have.deep.property('name').that.is.an('string');
|
||||
expect(res.data).to.have.deep.property('notice').that.is.an('string');
|
||||
expect(res.data).to.have.deep.property('introduce').that.is.an('string');
|
||||
expect(res.data).to.have.deep.property('ceLimit').that.is.an('number');
|
||||
expect(res.data).to.have.deep.property('isAuto').that.is.an('boolean');
|
||||
const { code, name, notice, introduce, ceLimit, isAuto } = res.data;
|
||||
pinusClient.request('battle.guildHandler.setGuildInfo', { code, name, notice: newNotice, introduce, ceLimit, isAuto }, (setRes) => {
|
||||
checkSuccessResponse(setRes);
|
||||
expect(setRes.data.notice).to.be.equal(newNotice);
|
||||
setTimeout(() => {
|
||||
expect(msgReceiveCnt).to.be.equal(2);
|
||||
done();
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ export const MSG_SOURCE = {
|
||||
HERO_QUALITY_UP: 3,
|
||||
COMPOSE_ORANGE_HERO: 4,
|
||||
HERO_STAR_MAX: 5,
|
||||
GUILD_NOTICE: 6,
|
||||
}
|
||||
|
||||
export const ON_MSG_ROUTE = 'onMessage';
|
||||
|
||||
Reference in New Issue
Block a user