@@ -19,7 +19,7 @@ export const BulkArchiveSelection = {
|
||||
docs: {
|
||||
description: {
|
||||
story:
|
||||
"The physical inventory section supports selecting active copies and archiving them in one authenticated operation.",
|
||||
"The physical inventory section supports selecting active copies for archive or asynchronous pricing refresh operations.",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
listAdminConditions,
|
||||
listAdminInventory,
|
||||
listAdminProducts,
|
||||
refreshAdminInventoryPricing,
|
||||
} from "@/services/admin-catalog-service.js";
|
||||
import {
|
||||
createAdminListing,
|
||||
@@ -213,6 +214,24 @@ async function archiveSelectedInventory() {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSelectedPricing() {
|
||||
if (!selectedInventoryIds.value.length) return;
|
||||
isSaving.value = true;
|
||||
try {
|
||||
const jobs = await refreshAdminInventoryPricing(
|
||||
selectedInventoryIds.value,
|
||||
pricingProvider.value,
|
||||
csrfToken(),
|
||||
);
|
||||
pricingJobs.value = [...jobs, ...pricingJobs.value];
|
||||
selectedInventoryIds.value = [];
|
||||
} catch (requestError) {
|
||||
error.value = requestError;
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createListing() {
|
||||
const item = inventory.value.find(
|
||||
(candidate) => candidate.id === listingInventoryId.value,
|
||||
@@ -956,6 +975,14 @@ onMounted(load);
|
||||
>
|
||||
Archive selected
|
||||
</button>
|
||||
<button
|
||||
class="button button--secondary"
|
||||
type="button"
|
||||
:disabled="isSaving || !selectedInventoryIds.length"
|
||||
@click="refreshSelectedPricing"
|
||||
>
|
||||
Refresh pricing
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="!inventory.length && !isLoading" class="state state--empty">
|
||||
No physical copies yet.
|
||||
|
||||
@@ -30,4 +30,12 @@ export function archiveAdminInventory(inventoryItemIds, csrfToken) {
|
||||
headers: { 'x-csrf-token': csrfToken },
|
||||
body: JSON.stringify({ action: 'ARCHIVE', inventoryItemIds }),
|
||||
});
|
||||
}
|
||||
|
||||
export function refreshAdminInventoryPricing(inventoryItemIds, providerId, csrfToken) {
|
||||
return request('/admin/bulk', {
|
||||
method: 'POST',
|
||||
headers: { 'x-csrf-token': csrfToken },
|
||||
body: JSON.stringify({ action: 'PRICING_REFRESH', inventoryItemIds, providerId }),
|
||||
});
|
||||
}
|
||||
@@ -68,4 +68,28 @@ test('archives selected admin inventory items through the bulk API', async () =>
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('enqueues selected admin inventory pricing refreshes through the bulk API', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options) => {
|
||||
assert.equal(url, '/api/v1/admin/bulk');
|
||||
assert.equal(options.method, 'POST');
|
||||
assert.equal(options.headers['x-csrf-token'], 'csrf-token');
|
||||
assert.deepEqual(JSON.parse(options.body), {
|
||||
action: 'PRICING_REFRESH',
|
||||
inventoryItemIds: ['item-1'],
|
||||
providerId: 'fixture-provider',
|
||||
});
|
||||
return { ok: true, async json() { return { data: [{ id: 'job-1', status: 'PENDING' }] }; } };
|
||||
};
|
||||
|
||||
try {
|
||||
const { refreshAdminInventoryPricing } = await import('../src/services/admin-catalog-service.js');
|
||||
assert.deepEqual(await refreshAdminInventoryPricing(['item-1'], 'fixture-provider', 'csrf-token'), [
|
||||
{ id: 'job-1', status: 'PENDING' },
|
||||
]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user