44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import type { IdentityApp } from './identity-app';
|
|
import { addressInput, secondActor, seedStock } from './commerce';
|
|
|
|
export async function checkoutFixture(ctx: IdentityApp, stock = 10) {
|
|
const item = await seedStock(ctx, stock);
|
|
const actor = await secondActor(ctx);
|
|
const address = await ctx
|
|
.api()
|
|
.post('/api/v1/addresses')
|
|
.auth(actor.token, { type: 'bearer' })
|
|
.send(addressInput)
|
|
.expect(201);
|
|
await ctx
|
|
.api()
|
|
.put('/api/v1/cart/lines/' + item.variant.id)
|
|
.auth(actor.token, { type: 'bearer' })
|
|
.send({ quantity: 2, version: 0 })
|
|
.expect(200);
|
|
return {
|
|
...item,
|
|
actor,
|
|
address: address.body,
|
|
input: {
|
|
cartVersion: 1,
|
|
addressId: address.body.id,
|
|
idempotencyKey: randomUUID(),
|
|
},
|
|
};
|
|
}
|
|
export function couponInput() {
|
|
return {
|
|
code: 'SAVE-' + randomUUID().slice(0, 8),
|
|
kind: 'PERCENT',
|
|
percentBps: 1000,
|
|
currency: 'INR',
|
|
minimumSubtotal: '100.00',
|
|
maxUses: 10,
|
|
perUserLimit: 1,
|
|
startsAt: new Date(Date.now() - 60000).toISOString(),
|
|
endsAt: new Date(Date.now() + 3600000).toISOString(),
|
|
};
|
|
}
|