Skip to content

Commit

Permalink
test: syncing blob variants (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn authored Nov 5, 2024
1 parent 398bfb9 commit 5efcdfc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"math-random-seed": "^2.0.0",
"nanobench": "^3.0.0",
"npm-run-all": "^4.1.5",
"p-props": "^6.0.0",
"prettier": "^2.8.8",
"random-access-file": "^4.0.7",
"random-access-memory": "^6.2.1",
Expand Down
42 changes: 27 additions & 15 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
import * as fs from 'node:fs/promises'
import { isDeepStrictEqual } from 'node:util'
import { pEvent } from 'p-event'
import pProps from 'p-props'
import { setTimeout as delay } from 'timers/promises'
import { request } from 'undici'
import FakeTimers from '@sinonjs/fake-timers'
Expand All @@ -28,6 +29,7 @@ import { BLOCKED_ROLE_ID, COORDINATOR_ROLE_ID } from '../src/roles.js'
import { kSyncState } from '../src/sync/sync-api.js'
import { blobMetadata } from '../test/helpers/blob-store.js'
/** @import { State } from '../src/sync/sync-api.js' */
/** @import { BlobId } from '../src/types.js' */

const SCHEMAS_INITIAL_SYNC = ['preset', 'field']

Expand Down Expand Up @@ -137,13 +139,15 @@ test('syncing blobs', async (t) => {
])
const [invitorProject, inviteeProject] = projects

const fixturePath = new URL(
'../test/fixtures/images/02-digidem-logo.jpg',
import.meta.url
).pathname
const fixturesPath = new URL('../test/fixtures/images/', import.meta.url)
const fixturePaths = {
original: new URL('02-digidem-logo.jpg', fixturesPath).pathname,
preview: new URL('02-digidem-logo-preview.jpg', fixturesPath).pathname,
thumbnail: new URL('02-digidem-logo-thumb.jpg', fixturesPath).pathname,
}

const blob = await invitorProject.$blobs.create(
{ original: fixturePath },
fixturePaths,
blobMetadata({ mimeType: 'image/jpeg' })
)

Expand All @@ -155,17 +159,25 @@ test('syncing blobs', async (t) => {

await waitForSync(projects, 'full')

const blobUrl = await inviteeProject.$blobs.getUrl({
...blob,
variant: 'original',
await pProps(fixturePaths, async (path, variant) => {
const expectedBytesPromise = fs.readFile(path)

// We have to tell TypeScript that the blob's type is "photo", which it
// isn't smart enough to figure out.
assert.equal(blob.type, 'photo', 'blob should be a photo type')
const blobUrl = await inviteeProject.$blobs.getUrl({
...blob,
type: 'photo',
variant,
})
const response = await request(blobUrl, { reset: true })
assert.equal(response.statusCode, 200)
assert.deepEqual(
Buffer.from(await response.body.arrayBuffer()),
await expectedBytesPromise,
'blob makes it to the other side'
)
})
const response = await request(blobUrl, { reset: true })
assert.equal(response.statusCode, 200)
assert.deepEqual(
Buffer.from(await response.body.arrayBuffer()),
await fs.readFile(fixturePath),
'blob makes it to the other side'
)
})

test('start and stop sync', async function (t) {
Expand Down
Binary file added test/fixtures/images/02-digidem-logo-preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/images/02-digidem-logo-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5efcdfc

Please sign in to comment.