Skip to content

Commit

Permalink
Test diff API
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmturner committed Aug 14, 2023
1 parent 1146b92 commit 75351ab
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,38 @@ test('Check hyperdrive writability', async (t) => {
t.equal(writableHeadersAllow, 'HEAD,GET,PUT,DELETE', 'Expected writable Allows header')
})

test('Diff two directories', async (t) => {
const created = await nextURL(t)

const putURL = new URL('/example.txt', created)
const uploadedResponse = await fetch(putURL, {
method: 'put',
body: SAMPLE_CONTENT
})
await checkResponse(uploadedResponse, t)

const diffURL = new URL('/$/diff/1..2/', created)
const diffResponse = await fetch(diffURL)
await checkResponse(diffResponse, t)

const [{ left, right }] = await diffResponse.json()
const { seq, key, value } = left

t.equal(seq, 1, 'Left half of diff contained correct seq number')
t.equal(key, '/example.txt', 'Left half of diff contained correct key')
t.equal(value.blob.byteLength, 11, 'Blob for left half of diff contained correct byteLength')
t.ok(value.metadata.mtime, 'Left half of diff contained metadata mtime')
t.notOk(right, 'Diff contained null "right"')

// Test out-of-range diff error handling
const outOfRangeDiffURL = new URL('/$/diff/1..3/', created)
const outOfRangeDiffResponse = await fetch(outOfRangeDiffURL)
t.notOk(outOfRangeDiffResponse.ok, 'error response for out-of-range diff')

const outOfRangeDiffResponseEtagHeader = outOfRangeDiffResponse.headers.get('ETag')
t.equal(outOfRangeDiffResponseEtagHeader, '2', 'Headers got ETag for latest version')
})

async function checkResponse (response, t, successMessage = 'Response OK') {
if (!response.ok) {
const message = await response.text()
Expand Down

0 comments on commit 75351ab

Please sign in to comment.