@@ -79,6 +79,40 @@ test('does not archive sold inventory items', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('enqueues pricing refresh jobs for owned inventory items', async () => {
|
||||
const enqueued = [];
|
||||
const service = createInventoryItemService({
|
||||
productRepository: { async findById() { return null; } },
|
||||
conditionRepository: { async findById() { return null; } },
|
||||
inventoryItemRepository: {
|
||||
async listBySellerId() {
|
||||
return [{ id: 'item-1', productId: 'product-1', conditionId: 'condition-1', status: 'ACTIVE' }];
|
||||
},
|
||||
},
|
||||
pricingService: {
|
||||
async enqueueRefresh(input) {
|
||||
enqueued.push(input);
|
||||
return { id: 'job-1', status: 'PENDING' };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const jobs = await service.refreshPricingMany({
|
||||
inventoryItemIds: ['item-1'],
|
||||
sellerId: 'seller-id',
|
||||
providerId: 'fixture-provider',
|
||||
});
|
||||
|
||||
assert.deepEqual(enqueued, [{
|
||||
sellerId: 'seller-id',
|
||||
inventoryItemId: 'item-1',
|
||||
providerId: 'fixture-provider',
|
||||
productId: 'product-1',
|
||||
conditionId: 'condition-1',
|
||||
}]);
|
||||
assert.deepEqual(jobs, [{ id: 'job-1', status: 'PENDING' }]);
|
||||
});
|
||||
|
||||
test('rejects conditions from another category', async () => {
|
||||
const service = createService({
|
||||
product: { id: 'product-id', sellerId: 'seller-id', categoryId: 'cards' },
|
||||
|
||||
@@ -5,7 +5,7 @@ import { buildApp } from '../../src/app/build-app.js';
|
||||
import { createInventoryItemService } from '../../src/modules/inventory/services/inventory-item-service.js';
|
||||
import { createProductService } from '../../src/modules/products/services/product-service.js';
|
||||
|
||||
function createTestApp({ authenticateAdmin, authorizeUnsafeRequest } = {}) {
|
||||
function createTestApp({ authenticateAdmin, authorizeUnsafeRequest, pricingService } = {}) {
|
||||
const products = [];
|
||||
const inventoryItems = [];
|
||||
const productRepository = {
|
||||
@@ -70,6 +70,7 @@ function createTestApp({ authenticateAdmin, authorizeUnsafeRequest } = {}) {
|
||||
});
|
||||
},
|
||||
},
|
||||
pricingService,
|
||||
}),
|
||||
productService: createProductService({ productRepository }),
|
||||
});
|
||||
@@ -193,6 +194,60 @@ test('archives selected inventory through the authenticated bulk route', async (
|
||||
assert.equal(response.json().data[0].status, 'ARCHIVED');
|
||||
});
|
||||
|
||||
test('enqueues selected inventory pricing refreshes through the bulk route', async (testContext) => {
|
||||
const enqueued = [];
|
||||
const app = createTestApp({
|
||||
authenticateAdmin: async () => ({ sellerId: 'b078adf4-6a91-4b3d-a263-740246c11e3f' }),
|
||||
pricingService: {
|
||||
async enqueueRefresh(input) {
|
||||
enqueued.push(input);
|
||||
return {
|
||||
id: 'job-1',
|
||||
status: 'PENDING',
|
||||
createdAt: new Date('2026-09-10T00:00:00.000Z'),
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const productResponse = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/admin/products',
|
||||
payload: {
|
||||
name: 'Pikachu Plush',
|
||||
categoryId: 'ab8150c7-96c1-4b55-8d69-7d0b77d48958',
|
||||
},
|
||||
});
|
||||
await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/admin/inventory',
|
||||
payload: {
|
||||
productId: productResponse.json().data.id,
|
||||
conditionId: '21eb218b-7a95-4f80-a9e3-e306f7ca1f2e',
|
||||
},
|
||||
});
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/admin/bulk',
|
||||
payload: {
|
||||
action: 'PRICING_REFRESH',
|
||||
inventoryItemIds: ['8a0a836a-a597-454d-8c5e-e146d27dbbf2'],
|
||||
providerId: 'fixture-provider',
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 202);
|
||||
assert.deepEqual(enqueued, [{
|
||||
sellerId: 'b078adf4-6a91-4b3d-a263-740246c11e3f',
|
||||
inventoryItemId: '8a0a836a-a597-454d-8c5e-e146d27dbbf2',
|
||||
providerId: 'fixture-provider',
|
||||
productId: productResponse.json().data.id,
|
||||
conditionId: '21eb218b-7a95-4f80-a9e3-e306f7ca1f2e',
|
||||
}]);
|
||||
assert.equal(response.json().data[0].status, 'PENDING');
|
||||
});
|
||||
|
||||
test('rejects an authenticated product write without a CSRF token', async (testContext) => {
|
||||
const app = createTestApp({
|
||||
authenticateAdmin: async () => ({ sellerId: 'b078adf4-6a91-4b3d-a263-740246c11e3f' }),
|
||||
|
||||
Reference in New Issue
Block a user