diff --git a/package-lock.json b/package-lock.json index 4cb726cdd..f03f80113 100644 --- a/package-lock.json +++ b/package-lock.json @@ -95,6 +95,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", @@ -7321,6 +7322,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-props": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/p-props/-/p-props-6.0.0.tgz", + "integrity": "sha512-vk89p9/3y/53LtD99tg1Ld2deVb4BXzw3Ekl1/0unNTvHAqbmgrf+T7eLDXv0mkVXl0mc/wmJoeO00IK7UwF7A==", + "dev": true, + "dependencies": { + "p-map": "^6.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-timeout": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.2.tgz", diff --git a/package.json b/package.json index eb3d7947c..02b3a3976 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test-e2e/sync.js b/test-e2e/sync.js index 321916b68..95fb1a43b 100644 --- a/test-e2e/sync.js +++ b/test-e2e/sync.js @@ -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' @@ -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'] @@ -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' }) ) @@ -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) { diff --git a/test/fixtures/images/02-digidem-logo-preview.jpg b/test/fixtures/images/02-digidem-logo-preview.jpg new file mode 100644 index 000000000..732124a85 Binary files /dev/null and b/test/fixtures/images/02-digidem-logo-preview.jpg differ diff --git a/test/fixtures/images/02-digidem-logo-thumb.jpg b/test/fixtures/images/02-digidem-logo-thumb.jpg new file mode 100644 index 000000000..0df3fdf78 Binary files /dev/null and b/test/fixtures/images/02-digidem-logo-thumb.jpg differ