feat: nový stav "Doručeno" pro objednávky
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 42s
CI / Playwright E2E tests (push) Successful in 1m43s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 1s

This commit is contained in:
mates committed 2026-09-07 11:30:40 +02:00
1 parent ecc28ee82d
commit b6834cb7aa
6 files changed
+162 -25

No files matched your search

+74 -2
View File
@@ -1,6 +1,6 @@
import { resetMemoryStorage } from '../storage/memory';
import { getStores, addStore } from '../stores';
import { createGroup, deleteGroup, addGroupMember, removeGroupMember, updateGroupMember, setGroupState, setGroupTracking, markGroupMemberPaid } from '../groups';
import { createGroup, deleteGroup, addGroupMember, removeGroupMember, updateGroupMember, setGroupState, setGroupTracking, markGroupMemberPaid, markGroupQrGenerated } from '../groups';
import { GroupState } from '../../../types/gen/types.gen';
const CREATOR = 'tomas';
@@ -219,12 +219,48 @@ describe('setGroupState', () => {
await expect(setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY)).rejects.toThrow('Nelze přejít');
});
test('ordered je terminální stav', async () => {
test('ordered → open není povoleno', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await expect(setGroupState(CREATOR, groupId, GroupState.OPEN, TODAY)).rejects.toThrow('Nelze přejít');
});
test('ordered → delivered', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
const d = await setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY);
expect(d.groups![0].state).toBe(GroupState.DELIVERED);
});
test('delivered → ordered (vrácení)', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY);
const d = await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
expect(d.groups![0].state).toBe(GroupState.ORDERED);
});
test('locked → delivered není povoleno', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await expect(setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY)).rejects.toThrow('Nelze přejít');
});
test('delivered → locked není povoleno', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY);
await expect(setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY)).rejects.toThrow('Nelze přejít');
});
test('skupinu ve stavu delivered nelze upravovat', async () => {
await addGroupMember(CREATOR, groupId, USER, TODAY);
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY);
await expect(updateGroupMember(CREATOR, groupId, USER, { amount: 100 }, TODAY)).rejects.toThrow('doručeno');
await expect(addGroupMember(CREATOR, groupId, 'dalsi', TODAY)).rejects.toThrow('doručeno');
});
test('nečlen nemůže měnit stav', async () => {
await expect(setGroupState(USER, groupId, GroupState.LOCKED, TODAY)).rejects.toThrow('zakladatel');
});
@@ -240,6 +276,42 @@ describe('setGroupState', () => {
});
});
describe('markGroupQrGenerated', () => {
let groupId: string;
beforeEach(async () => {
const d = await createGroup(CREATOR, STORE, TODAY);
groupId = d.groups![0].id;
});
test('ze stavu ordered přepne skupinu na delivered', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
const d = await markGroupQrGenerated(CREATOR, groupId, TODAY);
expect(d.groups![0].state).toBe(GroupState.DELIVERED);
expect(d.groups![0].qrGenerated).toBe(true);
});
test('funguje i ve stavu delivered', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.DELIVERED, TODAY);
const d = await markGroupQrGenerated(CREATOR, groupId, TODAY);
expect(d.groups![0].state).toBe(GroupState.DELIVERED);
});
test('ve stavu locked selže', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await expect(markGroupQrGenerated(CREATOR, groupId, TODAY)).rejects.toThrow('objednáno');
});
test('QR může generovat pouze zakladatel', async () => {
await setGroupState(CREATOR, groupId, GroupState.LOCKED, TODAY);
await setGroupState(CREATOR, groupId, GroupState.ORDERED, TODAY);
await expect(markGroupQrGenerated(USER, groupId, TODAY)).rejects.toThrow('zakladatel');
});
});
describe('markGroupMemberPaid', () => {
test('označí člena jako zaplaceného pro daný den', async () => {
const d = await createGroup(CREATOR, STORE, TODAY);