@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
||||
import { loadArtifact, makeProdClient } from './_setup/harness.js';
|
||||
import type { SeedArtifact } from './_setup/types.js';
|
||||
import type { NotificationEffect, StoreOfferEffect } from '../../src/index.js';
|
||||
import { getScenarioRuntime } from '../../src/client/RudderClient.js';
|
||||
|
||||
describe('e2e-prod: scenarios', () => {
|
||||
let artifact: SeedArtifact;
|
||||
beforeAll(() => {
|
||||
artifact = loadArtifact();
|
||||
});
|
||||
|
||||
it('runs onboarding: notification -> rc override -> store -> boundary callback -> notification', async () => {
|
||||
const notifications: NotificationEffect[] = [];
|
||||
let storeOffer: StoreOfferEffect | undefined;
|
||||
let runCompleted = false;
|
||||
|
||||
const client = makeProdClient(artifact, {
|
||||
planStateStore: null,
|
||||
loginEvent: artifact.scenario.event,
|
||||
});
|
||||
|
||||
client.effects.onNotification((effect) => { notifications.push(effect); });
|
||||
client.effects.onStoreOffer((effect) => {
|
||||
storeOffer = effect;
|
||||
});
|
||||
const runtime = await getScenarioRuntime(client);
|
||||
runtime.onRunCompleted = () => {
|
||||
runCompleted = true;
|
||||
};
|
||||
await client.auth.loginWithDevice({ region: 'en', language: 'en' });
|
||||
|
||||
// First notification dispatched.
|
||||
await vi.waitFor(() => expect(notifications.length).toBe(1), { timeout: 10_000 });
|
||||
await notifications[0].done();
|
||||
|
||||
// remote_config_override applies, then the store offer surfaces.
|
||||
await vi.waitFor(() => expect(storeOffer).toBeDefined(), { timeout: 10_000 });
|
||||
expect(client.remoteConfig.get('spawn_rate', 0)).toBeCloseTo(
|
||||
artifact.remoteConfigs.spawnRateOverride,
|
||||
);
|
||||
|
||||
// Buy crosses the server boundary (POST /sdk/v1/scenarios/callback) -> second notification.
|
||||
const offer = storeOffer!.offers.find((o) => o.name === artifact.store.paidOfferName)!;
|
||||
await storeOffer!.buy(offer);
|
||||
await vi.waitFor(() => expect(notifications.length).toBe(2), { timeout: 15_000 });
|
||||
await notifications[1].done();
|
||||
|
||||
await vi.waitFor(() => expect(runtime.isRunning).toBe(false), { timeout: 10_000 });
|
||||
expect(runCompleted).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user