Skip to content
Source
Sign inSign up
samwillis/neon-durable-streams
Open History to see the last commit

etag.test.ts

18 lines999 Bytes

1import { expect, test } from 'vitest'
2import { replayEtag, matchesEtag } from '../../src/etag.js'
3​
4const identity = { generationId: 'stream', servingEpoch: 'epoch', start: 'start', end: 'end', contentType: 'application/json', closed: false }
5test('replay validators change with byte identity, serving epoch, encoding and closure', () => {
6 const etag = replayEtag(identity)
7 expect(replayEtag({ ...identity })).toBe(etag)
8 for (const patch of [{ generationId: 'other' }, { servingEpoch: 'restored' }, { start: 'later' }, { end: 'later' }, { contentType: 'text/plain' }, { closed: true }]) {
9 expect(replayEtag({ ...identity, ...patch })).not.toBe(etag)
10 }
11})
12test('conditional GET recognizes weak validators, lists and wildcard', () => {
13 const etag = replayEtag(identity)
14 expect(matchesEtag(`"different", W/${etag}`, etag)).toBe(true)
15 expect(matchesEtag('*', etag)).toBe(true)
16 expect(matchesEtag('"different"', etag)).toBe(false)
17 expect(matchesEtag(undefined, etag)).toBe(false)
18})