test(unit): add lightweight vitest coverage for auth duration and seq pagination utils
This commit is contained in:
@@ -17,6 +17,7 @@ import { Channel } from '../entities/channel.entity';
|
||||
import { Message } from '../entities/message.entity';
|
||||
import { IdempotencyRecord } from '../entities/idempotency-record.entity';
|
||||
import { EventsService } from '../events/events.service';
|
||||
import { clampLimit, computeNextExpectedSeq } from './pagination.util';
|
||||
|
||||
const EDIT_WINDOW_MS = 15 * 60 * 1000;
|
||||
const DEFAULT_PAGE_LIMIT = 50;
|
||||
@@ -214,11 +215,7 @@ export class MessagingController {
|
||||
) {
|
||||
const from = seqFrom ? Number(seqFrom) : 1;
|
||||
const to = seqTo ? Number(seqTo) : Number.MAX_SAFE_INTEGER;
|
||||
const requestedLimit = limit ? Number(limit) : DEFAULT_PAGE_LIMIT;
|
||||
const safeLimit =
|
||||
Number.isFinite(requestedLimit) && requestedLimit > 0
|
||||
? Math.min(requestedLimit, MAX_PAGE_LIMIT)
|
||||
: DEFAULT_PAGE_LIMIT;
|
||||
const safeLimit = clampLimit(limit, DEFAULT_PAGE_LIMIT, MAX_PAGE_LIMIT);
|
||||
|
||||
if (from > to) {
|
||||
return {
|
||||
@@ -251,15 +248,10 @@ export class MessagingController {
|
||||
const rows = await qb.limit(safeLimit).getMany();
|
||||
const items = rows.map((m) => this.toView(m));
|
||||
|
||||
let nextExpectedSeq = from;
|
||||
for (const row of rows) {
|
||||
if (row.seq > nextExpectedSeq) {
|
||||
break;
|
||||
}
|
||||
if (row.seq === nextExpectedSeq) {
|
||||
nextExpectedSeq += 1;
|
||||
}
|
||||
}
|
||||
const nextExpectedSeq = computeNextExpectedSeq(
|
||||
from,
|
||||
rows.map((row) => row.seq),
|
||||
);
|
||||
|
||||
return {
|
||||
items,
|
||||
|
||||
Reference in New Issue
Block a user