Compare commits
2
Commits
release/66
...
a896342429
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a896342429 | ||
|
|
7b636ee793 |
No files matched your search
@@ -0,0 +1,116 @@
|
|||||||
|
import { ConnectionService } from '../global/database/connection.service';
|
||||||
|
import { NatsService } from '../global/nats/nats.service';
|
||||||
|
import { DakaoOutboxService } from './dakao-outbox.service';
|
||||||
|
import { DakaoResultSubjects } from './dakao.types';
|
||||||
|
|
||||||
|
function execResult<T>(value: T) {
|
||||||
|
return { exec: jest.fn().mockResolvedValue(value) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeService(outboxModel: Record<string, unknown>) {
|
||||||
|
const connectionService = {
|
||||||
|
getModel: jest.fn().mockResolvedValue(outboxModel),
|
||||||
|
} as unknown as ConnectionService;
|
||||||
|
const natsService = {
|
||||||
|
publishJetStream: jest.fn().mockResolvedValue(undefined),
|
||||||
|
} as unknown as NatsService;
|
||||||
|
|
||||||
|
return {
|
||||||
|
service: new DakaoOutboxService(connectionService, natsService),
|
||||||
|
connectionService,
|
||||||
|
natsService,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DakaoOutboxService', () => {
|
||||||
|
it('persists result subjects when enqueuing send-message commands', async () => {
|
||||||
|
const outboxModel = {
|
||||||
|
findOneAndUpdate: jest.fn().mockReturnValue(execResult({})),
|
||||||
|
updateOne: jest.fn().mockReturnValue(execResult({})),
|
||||||
|
};
|
||||||
|
const { service, natsService } = makeService(outboxModel);
|
||||||
|
const resultSubjects: DakaoResultSubjects = {
|
||||||
|
succeeded: 'staging.lolympus.dakao.chat.send-message.succeeded.v1',
|
||||||
|
failed: 'staging.lolympus.dakao.chat.send-message.failed.v1',
|
||||||
|
};
|
||||||
|
|
||||||
|
await service.enqueueAndPublish({
|
||||||
|
subject: 'staging.dakao.chat.send-message.v1',
|
||||||
|
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||||
|
envelope: {
|
||||||
|
schema: 'dakao.command.v1',
|
||||||
|
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||||
|
type: 'chat.send-message',
|
||||||
|
eventSource: 'lolympus',
|
||||||
|
correlationId: 'chat-log-1',
|
||||||
|
resultSubjects,
|
||||||
|
payload: {
|
||||||
|
chatroomId: '18474390111480678',
|
||||||
|
segments: [{ kind: 'text', text: 'done' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(outboxModel.findOneAndUpdate).toHaveBeenCalledWith(
|
||||||
|
{ eventId: 'lolympus:chat.send-message:chat-log-1' },
|
||||||
|
expect.objectContaining({
|
||||||
|
$setOnInsert: expect.objectContaining({ resultSubjects }),
|
||||||
|
}),
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
|
expect(natsService.publishJetStream).toHaveBeenCalledWith(
|
||||||
|
'staging.dakao.chat.send-message.v1',
|
||||||
|
expect.objectContaining({ resultSubjects }),
|
||||||
|
{ messageId: 'lolympus:chat.send-message:chat-log-1' },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('restores send-message result subjects when sweeping legacy stale rows', async () => {
|
||||||
|
const previousNodeEnv = process.env.NODE_ENV;
|
||||||
|
process.env.NODE_ENV = 'staging';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const exec = jest.fn().mockResolvedValue([
|
||||||
|
{
|
||||||
|
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||||
|
type: 'chat.send-message',
|
||||||
|
eventSource: 'lolympus',
|
||||||
|
subject: 'staging.dakao.chat.send-message.v1',
|
||||||
|
correlationId: 'chat-log-1',
|
||||||
|
payload: {
|
||||||
|
chatroomId: '18474390111480678',
|
||||||
|
segments: [{ kind: 'text', text: 'done' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const lean = jest.fn().mockReturnValue({ exec });
|
||||||
|
const limit = jest.fn().mockReturnValue({ lean });
|
||||||
|
const sort = jest.fn().mockReturnValue({ limit });
|
||||||
|
const outboxModel = {
|
||||||
|
find: jest.fn().mockReturnValue({ sort }),
|
||||||
|
};
|
||||||
|
const { service } = makeService(outboxModel);
|
||||||
|
const enqueue = jest
|
||||||
|
.spyOn(service, 'enqueueAndPublish')
|
||||||
|
.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await expect(service.sweepStale({ staleMs: 1, limit: 1 })).resolves.toBe(
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(enqueue).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
envelope: expect.objectContaining({
|
||||||
|
resultSubjects: {
|
||||||
|
succeeded:
|
||||||
|
'staging.lolympus.dakao.chat.send-message.succeeded.v1',
|
||||||
|
failed: 'staging.lolympus.dakao.chat.send-message.failed.v1',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
process.env.NODE_ENV = previousNodeEnv;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConnectionService } from '../global/database/connection.service';
|
import { ConnectionService } from '../global/database/connection.service';
|
||||||
import { NatsService } from '../global/nats/nats.service';
|
import { NatsService } from '../global/nats/nats.service';
|
||||||
import { DakaoCommandEnvelope, DakaoResultEnvelope } from './dakao.types';
|
import { resolveDakaoNatsNames } from './dakao.nats-names';
|
||||||
|
import {
|
||||||
|
DakaoCommandEnvelope,
|
||||||
|
DakaoResultEnvelope,
|
||||||
|
DakaoResultSubjects,
|
||||||
|
} from './dakao.types';
|
||||||
|
|
||||||
|
const CHAT_SEND_MESSAGE_TYPE = 'chat.send-message';
|
||||||
const TERMINAL_STATES = ['sent', 'failed'] as const;
|
const TERMINAL_STATES = ['sent', 'failed'] as const;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DakaoOutboxService {
|
export class DakaoOutboxService {
|
||||||
private readonly logger = new Logger(DakaoOutboxService.name);
|
private readonly logger = new Logger(DakaoOutboxService.name);
|
||||||
|
private readonly chatSendMessageResultSubjects = {
|
||||||
|
succeeded: resolveDakaoNatsNames().subjects.chatSendMessageSucceeded,
|
||||||
|
failed: resolveDakaoNatsNames().subjects.chatSendMessageFailed,
|
||||||
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly connectionService: ConnectionService,
|
private readonly connectionService: ConnectionService,
|
||||||
@@ -30,6 +40,7 @@ export class DakaoOutboxService {
|
|||||||
type: params.envelope.type,
|
type: params.envelope.type,
|
||||||
subject: params.subject,
|
subject: params.subject,
|
||||||
correlationId: params.envelope.correlationId,
|
correlationId: params.envelope.correlationId,
|
||||||
|
resultSubjects: params.envelope.resultSubjects,
|
||||||
payload: params.envelope.payload as Record<string, unknown>,
|
payload: params.envelope.payload as Record<string, unknown>,
|
||||||
state: 'pending',
|
state: 'pending',
|
||||||
publishAttempts: 0,
|
publishAttempts: 0,
|
||||||
@@ -161,6 +172,8 @@ export class DakaoOutboxService {
|
|||||||
type: row.type,
|
type: row.type,
|
||||||
eventSource: row.eventSource,
|
eventSource: row.eventSource,
|
||||||
correlationId: row.correlationId,
|
correlationId: row.correlationId,
|
||||||
|
resultSubjects:
|
||||||
|
row.resultSubjects ?? this.resolveDefaultResultSubjects(row.type),
|
||||||
payload: row.payload,
|
payload: row.payload,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -168,4 +181,11 @@ export class DakaoOutboxService {
|
|||||||
|
|
||||||
return rows.length;
|
return rows.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private resolveDefaultResultSubjects(
|
||||||
|
type: string,
|
||||||
|
): DakaoResultSubjects | undefined {
|
||||||
|
if (type !== CHAT_SEND_MESSAGE_TYPE) return undefined;
|
||||||
|
return this.chatSendMessageResultSubjects;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -350,6 +350,10 @@ export interface DakaoOutboxMessage extends MongooseTimestamps {
|
|||||||
type: string;
|
type: string;
|
||||||
subject: string;
|
subject: string;
|
||||||
correlationId?: string;
|
correlationId?: string;
|
||||||
|
resultSubjects?: {
|
||||||
|
succeeded: string;
|
||||||
|
failed: string;
|
||||||
|
};
|
||||||
payload: Record<string, unknown>;
|
payload: Record<string, unknown>;
|
||||||
state: DakaoOutboxMessageState;
|
state: DakaoOutboxMessageState;
|
||||||
publishAttempts: number;
|
publishAttempts: number;
|
||||||
@@ -960,6 +964,10 @@ export const DakaoOutboxMessageSchema = new Schema<DakaoOutboxMessage>(
|
|||||||
type: { type: String, required: true },
|
type: { type: String, required: true },
|
||||||
subject: { type: String, required: true },
|
subject: { type: String, required: true },
|
||||||
correlationId: { type: String },
|
correlationId: { type: String },
|
||||||
|
resultSubjects: {
|
||||||
|
succeeded: { type: String },
|
||||||
|
failed: { type: String },
|
||||||
|
},
|
||||||
payload: { type: Schema.Types.Mixed, required: true },
|
payload: { type: Schema.Types.Mixed, required: true },
|
||||||
state: {
|
state: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import { mapApiMatchToMatchDetail } from '../api/mappers';
|
|||||||
import { useMatches, useMe } from '../api/hooks';
|
import { useMatches, useMe } from '../api/hooks';
|
||||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||||
|
|
||||||
|
const UPCOMING_GRID_MATCH_LIMIT = 3;
|
||||||
|
const UPCOMING_MATCH_LIST_LIMIT = UPCOMING_GRID_MATCH_LIMIT + 1;
|
||||||
|
|
||||||
function StatusBadge({ status }: { status: string }) {
|
function StatusBadge({ status }: { status: string }) {
|
||||||
const styles: Record<string, string> = {
|
const styles: Record<string, string> = {
|
||||||
모집중: 'bg-green-500/15 text-green-500 border-green-500/20',
|
모집중: 'bg-green-500/15 text-green-500 border-green-500/20',
|
||||||
@@ -44,7 +47,10 @@ function getStatusLabel(status: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const upcomingMatchesQuery = useMatches({ limit: 20 }, DEFAULT_COMMUNITY_ID);
|
const upcomingMatchesQuery = useMatches(
|
||||||
|
{ limit: UPCOMING_MATCH_LIST_LIMIT },
|
||||||
|
DEFAULT_COMMUNITY_ID,
|
||||||
|
);
|
||||||
const finishedMatchesQuery = useMatches(
|
const finishedMatchesQuery = useMatches(
|
||||||
{ status: 'finished', limit: 10 },
|
{ status: 'finished', limit: 10 },
|
||||||
DEFAULT_COMMUNITY_ID,
|
DEFAULT_COMMUNITY_ID,
|
||||||
@@ -84,7 +90,10 @@ export default function HomePage() {
|
|||||||
const finishedMatches =
|
const finishedMatches =
|
||||||
finishedMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
|
finishedMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
|
||||||
const nextMatch = upcomingMatches[0];
|
const nextMatch = upcomingMatches[0];
|
||||||
const upcomingCards = nextMatch ? upcomingMatches.slice(1) : upcomingMatches;
|
const upcomingCards = (nextMatch
|
||||||
|
? upcomingMatches.slice(1)
|
||||||
|
: upcomingMatches
|
||||||
|
).slice(0, UPCOMING_GRID_MATCH_LIMIT);
|
||||||
const currentUser =
|
const currentUser =
|
||||||
meQuery.data?.memberships.find(
|
meQuery.data?.memberships.find(
|
||||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||||
|
|||||||
Reference in new issue
Block a user