feat: add public inventory catalog boundary
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { buildApp } from '../../src/app/build-app.js';
|
||||
|
||||
function createTestApp() {
|
||||
return buildApp({
|
||||
publicInventoryService: {
|
||||
async list() {
|
||||
return {
|
||||
items: [{
|
||||
id: 'inventory-1',
|
||||
productId: 'product-1',
|
||||
productName: 'Pikachu Plush',
|
||||
productSlug: 'pikachu-plush',
|
||||
categoryId: 'category-1',
|
||||
conditionId: 'condition-1',
|
||||
askingPriceMinor: 2499,
|
||||
listingStatus: 'PENDING',
|
||||
listingNotes: 'Available soon.',
|
||||
}],
|
||||
pagination: { page: 1, limit: 20, total: 1, totalPages: 1 },
|
||||
};
|
||||
},
|
||||
async getById(id) {
|
||||
if (id !== 'inventory-1') {
|
||||
const error = new Error('Inventory item was not found.');
|
||||
error.code = 'INVENTORY_NOT_FOUND';
|
||||
error.statusCode = 404;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
productId: 'product-1',
|
||||
productName: 'Pikachu Plush',
|
||||
productSlug: 'pikachu-plush',
|
||||
categoryId: 'category-1',
|
||||
conditionId: 'condition-1',
|
||||
askingPriceMinor: 2499,
|
||||
listingStatus: 'PENDING',
|
||||
listingNotes: 'Available soon.',
|
||||
notes: 'PRIVATE ITEM NOTE',
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
test('returns public inventory collection data without private item notes', async (testContext) => {
|
||||
const app = createTestApp();
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/public/inventory?page=1&limit=20',
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(response.json().data.items[0].productSlug, 'pikachu-plush');
|
||||
assert.equal('notes' in response.json().data.items[0], false);
|
||||
assert.equal(response.json().data.pagination.total, 1);
|
||||
});
|
||||
|
||||
test('returns public inventory detail or not found', async (testContext) => {
|
||||
const app = createTestApp();
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const detailResponse = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/public/inventory/inventory-1',
|
||||
});
|
||||
const missingResponse = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/public/inventory/hidden-inventory',
|
||||
});
|
||||
|
||||
assert.equal(detailResponse.statusCode, 200);
|
||||
assert.equal('notes' in detailResponse.json().data, false);
|
||||
assert.equal(missingResponse.statusCode, 404);
|
||||
assert.equal(missingResponse.json().error.code, 'INVENTORY_NOT_FOUND');
|
||||
});
|
||||
Reference in New Issue
Block a user