.
This commit is contained in:
1 parent
d1f7b0c916
commit
90a7cf6a7e
4 files changed
+150
-8
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { SecretService } from '../global/secret/secret.service';
|
||||
import { NatsService } from '../global/nats/nats.service';
|
||||
import { DakaoCommandEnvelope, DakaoSendMessagePayload } from './dakao.types';
|
||||
import { DakaoPublisher } from './dakao.publisher';
|
||||
|
||||
function makePublisher() {
|
||||
const natsService = {
|
||||
publish: jest.fn().mockResolvedValue(undefined),
|
||||
subscribe: jest.fn(),
|
||||
} as unknown as NatsService;
|
||||
const secretService = {} as SecretService;
|
||||
const publisher = new DakaoPublisher(natsService, secretService, {
|
||||
instanceId: 'test',
|
||||
});
|
||||
|
||||
return { publisher, natsService };
|
||||
}
|
||||
|
||||
function getPublishedPayload(natsService: NatsService): DakaoSendMessagePayload {
|
||||
const publish = natsService.publish as jest.Mock;
|
||||
const envelope = publish.mock.calls[0][1] as DakaoCommandEnvelope<
|
||||
DakaoSendMessagePayload
|
||||
>;
|
||||
return envelope.payload;
|
||||
}
|
||||
|
||||
describe('DakaoPublisher', () => {
|
||||
it('keeps valid mention segments intact', async () => {
|
||||
const { publisher, natsService } = makePublisher();
|
||||
|
||||
await publisher.sendMessage({
|
||||
chatroomId: '18474390111480678',
|
||||
segments: [
|
||||
{
|
||||
kind: 'mention',
|
||||
userId: '6215844374579825921',
|
||||
displayText: '날으는꼴뚜기/95/여/D',
|
||||
},
|
||||
{ kind: 'text', text: ' 신청 완료' },
|
||||
],
|
||||
});
|
||||
|
||||
expect(getPublishedPayload(natsService).segments).toEqual([
|
||||
{
|
||||
kind: 'mention',
|
||||
userId: '6215844374579825921',
|
||||
displayText: '날으는꼴뚜기/95/여/D',
|
||||
},
|
||||
{ kind: 'text', text: ' 신청 완료' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('downgrades invalid mention segments to text before publishing', async () => {
|
||||
const { publisher, natsService } = makePublisher();
|
||||
|
||||
await publisher.sendMessage({
|
||||
chatroomId: '18474390111480678',
|
||||
segments: [
|
||||
{
|
||||
kind: 'mention',
|
||||
userId: '-123',
|
||||
displayText: '소쿠리',
|
||||
},
|
||||
{ kind: 'text', text: ' 신청 완료' },
|
||||
],
|
||||
});
|
||||
|
||||
expect(getPublishedPayload(natsService).segments).toEqual([
|
||||
{ kind: 'text', text: '@소쿠리' },
|
||||
{ kind: 'text', text: ' 신청 완료' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -69,7 +69,7 @@ export class DakaoPublisher implements OnModuleInit, OnModuleDestroy {
|
||||
}): Promise<void> {
|
||||
const payload: DakaoSendMessagePayload = {
|
||||
chatroomId: params.chatroomId,
|
||||
segments: params.segments,
|
||||
segments: this.normalizeSegments(params.segments),
|
||||
};
|
||||
const envelope: DakaoCommandEnvelope<DakaoSendMessagePayload> = {
|
||||
schema: 'dakao.command.v1',
|
||||
@@ -83,6 +83,63 @@ export class DakaoPublisher implements OnModuleInit, OnModuleDestroy {
|
||||
await this.natsService.publish(this.sendMessageSubject, envelope);
|
||||
}
|
||||
|
||||
private normalizeSegments(segments: DakaoSegment[]): DakaoSegment[] {
|
||||
const normalized: DakaoSegment[] = [];
|
||||
|
||||
for (const segment of segments) {
|
||||
if (segment.kind === 'text') {
|
||||
if (segment.text.length > 0) normalized.push(segment);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (segment.kind === 'mention') {
|
||||
const userId = segment.userId.trim();
|
||||
const displayText = segment.displayText.trim();
|
||||
|
||||
if (this.isPositiveIntegerString(userId) && displayText.length > 0) {
|
||||
normalized.push({ kind: 'mention', userId, displayText });
|
||||
continue;
|
||||
}
|
||||
|
||||
const fallbackText = this.renderMentionFallback(displayText, userId);
|
||||
this.logger.warn(
|
||||
`Dakao mention downgraded to text because userId/displayText is invalid: userId="${userId || '-'}" displayText="${displayText || '-'}"`,
|
||||
);
|
||||
normalized.push({ kind: 'text', text: fallbackText });
|
||||
continue;
|
||||
}
|
||||
|
||||
const id = segment.id.trim();
|
||||
const altText = segment.altText.trim();
|
||||
if (
|
||||
id.length > 0 &&
|
||||
altText.length > 0 &&
|
||||
!/[()@]/.test(altText)
|
||||
) {
|
||||
normalized.push({ kind: 'emoticon', id, altText });
|
||||
continue;
|
||||
}
|
||||
|
||||
this.logger.warn(
|
||||
`Dakao emoticon downgraded to text because id/altText is invalid: id="${id || '-'}" altText="${altText || '-'}"`,
|
||||
);
|
||||
normalized.push({ kind: 'text', text: `(${altText || '이모티콘'})` });
|
||||
}
|
||||
|
||||
return normalized.length > 0
|
||||
? normalized
|
||||
: [{ kind: 'text', text: '명령 처리 결과를 보낼 수 없습니다.' }];
|
||||
}
|
||||
|
||||
private isPositiveIntegerString(value: string): boolean {
|
||||
return /^[1-9]\d*$/.test(value);
|
||||
}
|
||||
|
||||
private renderMentionFallback(displayText: string, userId: string): string {
|
||||
const label = displayText || userId || '사용자';
|
||||
return label.startsWith('@') ? label : `@${label}`;
|
||||
}
|
||||
|
||||
private handleReply(reply: DakaoResultEnvelope): void {
|
||||
if (reply.status === 'succeeded') {
|
||||
this.logger.log(
|
||||
|
||||
@@ -524,21 +524,33 @@ UserSchema.index(
|
||||
{ communityId: 1, identityId: 1 },
|
||||
{
|
||||
unique: true,
|
||||
partialFilterExpression: { identityId: { $exists: true } },
|
||||
partialFilterExpression: { identityId: { $type: 'objectId' } },
|
||||
},
|
||||
);
|
||||
UserSchema.index({ identityId: 1 }, { sparse: true });
|
||||
UserSchema.index(
|
||||
{ identityId: 1 },
|
||||
{ partialFilterExpression: { identityId: { $type: 'objectId' } } },
|
||||
);
|
||||
UserSchema.index(
|
||||
{ communityId: 1, kakaoTalkId: 1 },
|
||||
{ unique: true, sparse: true },
|
||||
{
|
||||
unique: true,
|
||||
partialFilterExpression: { kakaoTalkId: { $type: 'string' } },
|
||||
},
|
||||
);
|
||||
UserSchema.index(
|
||||
{ communityId: 1, discordId: 1 },
|
||||
{ unique: true, sparse: true },
|
||||
{
|
||||
unique: true,
|
||||
partialFilterExpression: { discordId: { $type: 'string' } },
|
||||
},
|
||||
);
|
||||
UserSchema.index(
|
||||
{ communityId: 1, 'riotAccounts.puuid': 1 },
|
||||
{ unique: true, sparse: true },
|
||||
{
|
||||
unique: true,
|
||||
partialFilterExpression: { 'riotAccounts.puuid': { $type: 'string' } },
|
||||
},
|
||||
);
|
||||
|
||||
export const RiotMatchSchema = new Schema<RiotMatch>(
|
||||
|
||||
@@ -19,7 +19,7 @@ function LoginButton() {
|
||||
})
|
||||
}
|
||||
>
|
||||
Microsoft로 로그인
|
||||
Entra ID 로 로그인
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export default function LoginPage() {
|
||||
<div className="max-w-md border border-base-content/10 bg-base-100 p-6 shadow-sm">
|
||||
<h1 className="text-xl font-bold tracking-tight">로그인</h1>
|
||||
<p className="mt-2 text-sm text-base-content/50">
|
||||
Microsoft Entra ID 계정으로 로그인하면 LOLYMPUS 멤버십을 불러옵니다.
|
||||
Entra ID 계정으로 LOLYMPUS 정보를 불러옵니다.
|
||||
</p>
|
||||
<div className="mt-5">
|
||||
{isMsalConfigured && msalInstance ? (
|
||||
|
||||
Reference in new issue
Block a user