feat: podpora simulace objednávek z Bolt Food ve vývoji
This commit is contained in:
@@ -4,6 +4,7 @@ import getStorage from '../storage';
|
||||
import { addStore } from '../stores';
|
||||
import { createGroup, setGroupState, setGroupBoltTracking } from '../groups';
|
||||
import { extractBoltToken, computeDeliveryHHMM, checkBoltTracking } from '../boltTracking';
|
||||
import { startBoltSimulation, advanceBoltSimulation, setBoltSimulationStep, stopBoltSimulationByGroup } from '../boltSimulator';
|
||||
import { ClientData, GroupState } from '../../../types/gen/types.gen';
|
||||
import { formatDate } from '../utils';
|
||||
|
||||
@@ -263,3 +264,60 @@ describe('checkBoltTracking', () => {
|
||||
expect(mockedAxios.post).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('DEV simulace (boltSimulator + checkBoltTracking)', () => {
|
||||
const extraKey = () => `${formatDate(new Date())}_extra`;
|
||||
let groupId: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
const d = await createGroup(CREATOR, STORE);
|
||||
groupId = d.groups![0].id;
|
||||
await setGroupState(CREATOR, groupId, GroupState.LOCKED);
|
||||
await setGroupState(CREATOR, groupId, GroupState.ORDERED);
|
||||
// Simulátor vygeneruje validní 64-hex token a přiřadíme ho skupině jako reálný dev endpoint
|
||||
const token = startBoltSimulation(groupId);
|
||||
await setGroupBoltTracking(CREATOR, groupId, `https://food.bolt.eu/sharedActiveOrder/${token}`);
|
||||
});
|
||||
|
||||
afterEach(() => stopBoltSimulationByGroup(groupId));
|
||||
|
||||
async function getGroup() {
|
||||
const data = await storage.getData<ClientData>(extraKey());
|
||||
return data!.groups!.find(g => g.id === groupId)!;
|
||||
}
|
||||
|
||||
test('simulovaný token nevolá reálné Bolt API', async () => {
|
||||
await checkBoltTracking();
|
||||
expect(mockedAxios.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('první poll nastaví stav accepted a ETA', async () => {
|
||||
await checkBoltTracking();
|
||||
const g = await getGroup();
|
||||
expect(g.boltOrderState).toBe('accepted');
|
||||
expect(g.deliveryAt).toBe(computeDeliveryHHMM(1800));
|
||||
});
|
||||
|
||||
test('advance posune sekvenci na preparing', async () => {
|
||||
await checkBoltTracking();
|
||||
advanceBoltSimulation(groupId);
|
||||
await checkBoltTracking();
|
||||
expect((await getGroup()).boltOrderState).toBe('preparing');
|
||||
});
|
||||
|
||||
test('ruční nastavení stavu (override) se projeví při pollu', async () => {
|
||||
setBoltSimulationStep(groupId, { order_state: 'in_delivery', courier_state: 'heading_to_client', etaSeconds: 300 });
|
||||
await checkBoltTracking();
|
||||
const g = await getGroup();
|
||||
expect(g.boltOrderState).toBe('in_delivery');
|
||||
expect(g.boltCourierState).toBe('heading_to_client');
|
||||
});
|
||||
|
||||
test('terminální stav delivered ukončí sledování (smaže token)', async () => {
|
||||
setBoltSimulationStep(groupId, { order_state: 'delivered' });
|
||||
await checkBoltTracking();
|
||||
const g = await getGroup();
|
||||
expect(g.boltOrderState).toBe('delivered');
|
||||
expect(g.boltTrackingToken).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user