diff --git a/src/api/inbound.js b/src/api/inbound.js index 44bde46..ca941ce 100644 --- a/src/api/inbound.js +++ b/src/api/inbound.js @@ -3,9 +3,17 @@ import { normalizeReceivingCandidate, normalizeReceivingSession, normalizeReceiv const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers' const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}` +let warehouseProfileRequest = null export const listReceivingCandidates = async () => (await overseasRequest('GET', `${RECEIVING_BASE}/candidates`)).map(normalizeReceivingCandidate) -export const getCurrentWarehouseProfile = async () => normalizeReceivingWarehouseProfile(await overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`)) +export const getCurrentWarehouseProfile = () => { + if (!warehouseProfileRequest) { + warehouseProfileRequest = overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`) + .then(normalizeReceivingWarehouseProfile) + .finally(() => { warehouseProfileRequest = null }) + } + return warehouseProfileRequest +} export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`)) export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request)) export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath) diff --git a/tests/project-contract.test.mjs b/tests/project-contract.test.mjs index f481166..4d00b14 100644 --- a/tests/project-contract.test.mjs +++ b/tests/project-contract.test.mjs @@ -147,6 +147,8 @@ test('Chinese English and Spanish locale selection is persisted from profile wit }) test('home reuses the persisted warehouse profile instead of requesting it on every show', async () => { - const home = await read('../src/pages/home/home.vue') + const [home, inbound] = await Promise.all([read('../src/pages/home/home.vue'), read('../src/api/inbound.js')]) assert.match(home, /if \(!this\.user\?\.warehouseCode \|\| !this\.user\?\.warehouseName\) this\.loadWarehouseProfile\(\)/) + assert.match(inbound, /let warehouseProfileRequest = null/) + assert.match(inbound, /if \(!warehouseProfileRequest\)[\s\S]*\.finally\(\(\) => \{ warehouseProfileRequest = null \}\)/) })