38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
||
|
|
import { freshPlayer, loadArtifact, withReadRetry } from './_setup/harness.js';
|
||
|
|
import type { SeedArtifact } from './_setup/types.js';
|
||
|
|
|
||
|
|
describe('e2e-prod: stores', () => {
|
||
|
|
let artifact: SeedArtifact;
|
||
|
|
beforeAll(() => {
|
||
|
|
artifact = loadArtifact();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('lists the seeded store with its free + paid offers', async () => {
|
||
|
|
const client = await freshPlayer(artifact);
|
||
|
|
const stores = await withReadRetry(
|
||
|
|
() => client.stores.reload(),
|
||
|
|
(r) => r.length > 0,
|
||
|
|
);
|
||
|
|
const store = stores.find((s) => s.name === artifact.store.name);
|
||
|
|
expect(store).toBeDefined();
|
||
|
|
|
||
|
|
const offerNames = store!.offers.map((o) => o.name);
|
||
|
|
expect(offerNames).toContain(artifact.store.freeOfferName);
|
||
|
|
expect(offerNames).toContain(artifact.store.paidOfferName);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('buys the free offer successfully', async () => {
|
||
|
|
const client = await freshPlayer(artifact);
|
||
|
|
const stores = await withReadRetry(
|
||
|
|
() => client.stores.reload(),
|
||
|
|
(s) => s.some((store) => store.name === artifact.store.name && store.offers.length > 0),
|
||
|
|
);
|
||
|
|
const store = stores.find((s) => s.name === artifact.store.name)!;
|
||
|
|
const free = store.offers.find((o) => o.name === artifact.store.freeOfferName)!;
|
||
|
|
const res = await free.buy();
|
||
|
|
expect(res.success).toBe(true);
|
||
|
|
expect(res.purchaseId).toBeTruthy();
|
||
|
|
});
|
||
|
|
});
|