Files
pokemon-inventory/apps/api/tests/application/public-image-service.test.js
T
fragginwagon b00bd388a9
Quality / test (push) Canceled after 0s
feat: add public image read boundary
2026-09-08 21:58:30 -04:00

45 lines
1.4 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createPublicImageService } from '../../src/modules/inventory/services/public-image-service.js';
test('returns public image URLs without exposing storage keys', async () => {
const service = createPublicImageService({
inventoryImageRepository: {
async listPublicByInventoryItemId(id) {
assert.equal(id, 'inventory-1');
return [{ id: 'image-1', altText: 'Front of card', sortOrder: 0 }];
},
},
imageStorage: { async get() { return Buffer.from('unused'); } },
});
assert.deepEqual(await service.listForInventoryItem('inventory-1'), [{
id: 'image-1',
altText: 'Front of card',
sortOrder: 0,
url: '/api/v1/public/images/image-1',
}]);
});
test('loads only repository-approved public image content', async () => {
const service = createPublicImageService({
inventoryImageRepository: {
async findPublicById(id) {
assert.equal(id, 'image-1');
return { id, storageKey: 'inventory/image.webp', mimeType: 'image/webp' };
},
},
imageStorage: {
async get(key) {
assert.equal(key, 'inventory/image.webp');
return Buffer.from('image-bytes');
},
},
});
const result = await service.getContent('image-1');
assert.deepEqual(result.data, Buffer.from('image-bytes'));
assert.equal(result.storageKey, 'inventory/image.webp');
});