feat: add extensive test suite

This commit is contained in:
2026-08-30 11:33:53 +07:00 Unverified
parent 061cce00dc
commit 8359c7272e
131 changed files with 8717 additions and 2200 deletions
@@ -0,0 +1,35 @@
import { type OrderItem, plannedOrderUpdates } from "./order";
export interface ReorderDependencies {
adminCheck: () => Promise<unknown>;
transaction: (
callback: (repository: {
list: () => Promise<OrderItem[]>;
update: (id: string, order: number) => Promise<void>;
}) => Promise<void>,
) => Promise<void>;
afterReorder: () => Promise<void> | void;
}
export async function reorderService(
activeId: string,
ids: readonly string[],
staleMessage: string,
dependencies: ReorderDependencies,
) {
if (!(await dependencies.adminCheck())) throw "Unauthorized";
await dependencies.transaction(async (repository) => {
const updates = plannedOrderUpdates(
await repository.list(),
ids,
activeId,
staleMessage,
);
for (const update of updates) {
await repository.update(update.id, update.order);
}
});
await dependencies.afterReorder();
}