29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { identityApp, type IdentityApp } from './helpers/identity-app';
|
|
import { checkoutFixture } from './helpers/checkout';
|
|
import { DeliveryStore } from '../src/events/delivery.store';
|
|
const native = process.env.TEST_DATABASE_URL ? describe : describe.skip;
|
|
native('native PostgreSQL event claims', () => {
|
|
let ctx: IdentityApp;
|
|
beforeAll(async () => {
|
|
ctx = await identityApp();
|
|
}, 60000);
|
|
afterAll(async () => {
|
|
await ctx.close();
|
|
});
|
|
it('assigns distinct events to simultaneous workers', async () => {
|
|
for (let index = 0; index < 2; index++) {
|
|
const f = await checkoutFixture(ctx);
|
|
await ctx
|
|
.api()
|
|
.post('/api/v1/checkout')
|
|
.auth(f.actor.token, { type: 'bearer' })
|
|
.send(f.input)
|
|
.expect(201);
|
|
}
|
|
const store = ctx.app.get(DeliveryStore);
|
|
const claims = await Promise.all([store.claim(), store.claim()]);
|
|
expect(claims.every(Boolean)).toBe(true);
|
|
expect(new Set(claims.map((claim) => claim!.eventId)).size).toBe(2);
|
|
});
|
|
});
|