59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
/**
|
|
* slots.json — regenerated SYNCHRONOUSLY inside admin.slots.createSlot
|
|
* (it awaits createSlotsCacheFile()), so the file can be read immediately.
|
|
*/
|
|
|
|
import {
|
|
essentialConsts,
|
|
fetchCacheJson,
|
|
slotsCacheUrl,
|
|
type EssentialConsts,
|
|
} from '../helpers/cache'
|
|
import { createFutureSlot, createStoreWithSku } from '../helpers/fixtures'
|
|
|
|
interface SlotsCache {
|
|
slots: { id: number; deliveryTime: string; freezeTime: string }[]
|
|
count: number
|
|
}
|
|
|
|
describe('slots.json cache', () => {
|
|
let skuId = 0
|
|
let consts: EssentialConsts
|
|
|
|
beforeAll(async () => {
|
|
const store = await createStoreWithSku()
|
|
skuId = store.skuId
|
|
consts = await essentialConsts()
|
|
})
|
|
|
|
it('exposes a numeric slotsVersionNum', () => {
|
|
expect(typeof consts.slotsVersionNum).toBe('number')
|
|
expect(consts.slotsVersionNum).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('contains a newly created slot', async () => {
|
|
const slot = await createFutureSlot([skuId])
|
|
const current = await essentialConsts()
|
|
|
|
const cache = await fetchCacheJson<SlotsCache>(
|
|
slotsCacheUrl(current, current.slotsVersionNum)
|
|
)
|
|
|
|
const found = cache.slots.find((s) => s.id === slot.slotId)
|
|
expect(found).toBeDefined()
|
|
expect(new Date(found!.deliveryTime).toISOString()).toBe(slot.deliveryTime)
|
|
})
|
|
|
|
it('bumps the version and rewrites the file for a second slot', async () => {
|
|
const before = await essentialConsts()
|
|
const slot = await createFutureSlot([skuId], { deliveryInHours: 5, freezeInHours: 4 })
|
|
const after = await essentialConsts()
|
|
|
|
expect(after.slotsVersionNum).toBeGreaterThan(before.slotsVersionNum)
|
|
|
|
const cache = await fetchCacheJson<SlotsCache>(
|
|
slotsCacheUrl(after, after.slotsVersionNum)
|
|
)
|
|
expect(cache.slots.some((s) => s.id === slot.slotId)).toBe(true)
|
|
})
|
|
})
|