mirror of
https://github.com/velocitatem/PHANTOM.git
synced 2026-05-31 08:33:36 +00:00
E2e testing of pricing (#42)
* a simp0le scaffold * feature: simple npm setup * feature: testing setup and dummy scenarios * chore: dumping kafak just via backend * chore: dcleaning gitignore * features: boilerplate fixtures and stuff * test: extra tests * chore: update the test suite to be callable via makefile * chore: cleaning * chore: updating interactions setup * small cleaning * chore: cleaning shitty code
This commit is contained in:
committed by
GitHub
parent
f2271e368e
commit
221e71a503
39
tests/e2e/helpers/kafka.ts
Normal file
39
tests/e2e/helpers/kafka.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
interface InteractionEvent {
|
||||
sessionId: string;
|
||||
event: string;
|
||||
productId?: string;
|
||||
timestamp: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
const dumpKafkaTopic = async (backendUrl: string, topic: string) => {
|
||||
const resp = await fetch(`${backendUrl}/api/kafka/dump?topic=${topic}`);
|
||||
if (!resp.ok) throw new Error(`Kafka dump failed: ${resp.status}`);
|
||||
const { messages = [] } = await resp.json();
|
||||
return messages as any[];
|
||||
};
|
||||
|
||||
export const waitForInteractionEvent = async (
|
||||
backendUrl: string,
|
||||
sessionId: string,
|
||||
eventType: string,
|
||||
maxRetries = 10,
|
||||
pollInterval = 500
|
||||
): Promise<InteractionEvent | null> => {
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
const msgs = await dumpKafkaTopic(backendUrl, "user-interactions");
|
||||
const hit = msgs.find(m => m.sessionId === sessionId && m.event === eventType);
|
||||
if (hit) return hit as InteractionEvent;
|
||||
await new Promise<void>(r => setTimeout(r, pollInterval));
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const countProductViews = async (backendUrl: string, productId: string) =>
|
||||
(await dumpKafkaTopic(backendUrl, "user-interactions")).reduce(
|
||||
(n, m) => n + (m.productId === productId && m.event === "view_item_page" ? 1 : 0),
|
||||
0
|
||||
);
|
||||
|
||||
export const getSessionEvents = async (backendUrl: string, sessionId: string) =>
|
||||
(await dumpKafkaTopic(backendUrl, "user-interactions")).filter(m => m.sessionId === sessionId);
|
||||
Reference in New Issue
Block a user