Plum hero with a club-card ticket, a 'Now' block with the live order timeline, new order cards and order screen, QR club card screen, new nav (Home / Orders / Chat / Card / Profile). Clients rate completed orders (1-5 stars + comment); provider rating is recalculated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
2.4 KiB
TypeScript
39 lines
2.4 KiB
TypeScript
import { afterAll, beforeEach, describe, expect, it } from 'vitest';
|
|
import { createOrder, DomainError, giveConsent, rateOrder, startClient } from '../src/index.ts';
|
|
import { db, fixtures, makeCtx, NOW, slotAt, tgUser } from './helpers.ts';
|
|
|
|
let fx: Awaited<ReturnType<typeof fixtures>>;
|
|
beforeEach(async () => {
|
|
fx = await fixtures();
|
|
});
|
|
afterAll(() => db.$disconnect());
|
|
|
|
const code = (p: Promise<unknown>) => p.then(() => null, (e: unknown) => (e instanceof DomainError ? e.code : String(e)));
|
|
|
|
describe('оценка заказа клиентом', () => {
|
|
it('только после выполнения; повторная оценка заменяет прежнюю и пересчитывает рейтинг исполнителя', async () => {
|
|
const { ctx } = makeCtx(NOW);
|
|
const s = await startClient(ctx, tgUser(901));
|
|
await giveConsent(ctx, s.clientId);
|
|
const o = await createOrder(ctx, { clientId: s.clientId, serviceCode: 'cleaning', params: { cleaningType: 'regular', rooms: 2 }, scheduledAt: slotAt(2, 11), addressText: 'Pushkin 10', districtId: fx.kentron.id });
|
|
await db.order.update({ where: { id: o.id }, data: { providerId: fx.maria.id } });
|
|
const before = await db.provider.findUniqueOrThrow({ where: { id: fx.maria.id } });
|
|
|
|
expect(await code(rateOrder(ctx, { orderId: o.id, clientId: s.clientId, score: 5 }))).toBe('TRANSITION_NOT_ALLOWED');
|
|
|
|
await db.order.update({ where: { id: o.id }, data: { status: 'DONE' } });
|
|
const other = await startClient(ctx, tgUser(902));
|
|
expect(await code(rateOrder(ctx, { orderId: o.id, clientId: other.clientId, score: 5 }))).toBe('NOT_FOUND');
|
|
expect(await code(rateOrder(ctx, { orderId: o.id, clientId: s.clientId, score: 7 }))).toBe('INVALID_PARAMS');
|
|
|
|
expect(await rateOrder(ctx, { orderId: o.id, clientId: s.clientId, score: 3, comment: ' поздно пришла ' })).toEqual({ score: 3, comment: 'поздно пришла' });
|
|
let p = await db.provider.findUniqueOrThrow({ where: { id: fx.maria.id } });
|
|
expect([p.ratingSum - before.ratingSum, p.ratingCount - before.ratingCount]).toEqual([3, 1]);
|
|
|
|
await rateOrder(ctx, { orderId: o.id, clientId: s.clientId, score: 5 });
|
|
p = await db.provider.findUniqueOrThrow({ where: { id: fx.maria.id } });
|
|
expect([p.ratingSum - before.ratingSum, p.ratingCount - before.ratingCount]).toEqual([5, 1]);
|
|
expect(await db.rating.count({ where: { orderId: o.id } })).toBe(1);
|
|
});
|
|
});
|