MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / scenarioNonScreenViewFirst

Function scenarioNonScreenViewFirst

apps/api/e2e/session-e2e.ts:144–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142}
143
144async function scenarioNonScreenViewFirst() {
145 scenario('session opened by a non-screen_view event');
146 const ip = `10.${(runId >> 16) & 255}.5.${runId & 255 || 1}`;
147
148 // First (and only) event is a custom event with no __path.
149 const { deviceId, sessionId } = await track(
150 { type: 'track', payload: { name: 'purchase', properties: { __ip: ip } } },
151 ip
152 );
153 check('track returned a sessionId for a non-screen_view first event', !!sessionId);
154
155 const starts = await pollUntil(async () =>
156 (await countByName([sessionId], 'session_start')) > 0 ? true : null
157 );
158 check('clickhouse: session_start emitted for a custom-event session', !!starts);
159
160 console.log(` …waiting ${IDLE_WAIT_MS}ms for idle window, then reaping`);
161 await sleep(IDLE_WAIT_MS);
162 await triggerReaper();
163
164 const ends = await pollUntil(async () =>
165 (await countByName([sessionId], 'session_end')) > 0 ? true : null
166 );
167 check('clickhouse: session_end emitted (closes normally)', !!ends);
168
169 const row = await pollUntil(async () => {
170 const rows = await chQuery<{
171 screen_view_count: number;
172 event_count: number;
173 is_bounce: boolean;
174 }>(
175 `SELECT screen_view_count, event_count, is_bounce FROM sessions FINAL WHERE project_id = '${PROJECT_ID}' AND id = '${sessionId}' LIMIT 1`
176 );
177 return rows[0] ?? null;
178 });
179 check('clickhouse: screen_view_count is 0', Number(row?.screen_view_count) === 0, `${row?.screen_view_count}`);
180 check('clickhouse: event_count is 1', Number(row?.event_count) === 1, `${row?.event_count}`);
181 check(
182 'clickhouse: is_bounce is true (no pageviews)',
183 row?.is_bounce === true || Number(row?.is_bounce) === 1,
184 `is_bounce=${row?.is_bounce}`
185 );
186
187 const cleaned = await pollUntil(async () =>
188 (await redis.get(sessionKey(deviceId))) === null ? true : null
189 );
190 check('redis: session cleaned up after close', !!cleaned);
191}
192
193async function scenarioReplay() {
194 scenario('replay chunk files under the echoed session id');

Callers 1

mainFunction · 0.85

Calls 10

scenarioFunction · 0.90
trackFunction · 0.90
checkFunction · 0.90
pollUntilFunction · 0.90
countByNameFunction · 0.90
sleepFunction · 0.90
triggerReaperFunction · 0.90
sessionKeyFunction · 0.90
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected