feat(api): add Dakao integration

This commit is contained in:
dahyeon committed 2026-04-28 22:37:00 +09:00
1 parent 9ebdc9b61f
commit ba3894cba2
10 files changed
+1257

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: ' 신청 완료' },
]);
});
});