fix - ASS-OLD
This commit is contained in:
@@ -121,6 +121,16 @@ test('current and archived inventory are selected separately', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('borrow and return history includes requests linked to archived assets', async () => {
|
||||
const oldBorrow = { BorrowId: 21, AssetId: 17, RequestType: 'borrow', IsArchived: true };
|
||||
const oldReturn = { BorrowId: 22, AssetId: 17, RequestType: 'return', IsArchived: true };
|
||||
const fixture = createFixture(() => ({ recordset: [oldBorrow, oldReturn] }));
|
||||
const response = await fixture.invoke('get', '/api/asset-borrows');
|
||||
assert.deepEqual(Array.from(response.body.data, row => row.BorrowId), [21, 22]);
|
||||
assert.match(fixture.queries[0].query, /FROM AssetBorrowRequests br\s+LEFT JOIN AssetInventory ai ON ai.AssetId = br.AssetId/);
|
||||
assert.doesNotMatch(fixture.queries[0].query, /WHERE\s+(?:br\.|ai\.)?IsArchived\s*=\s*0/i);
|
||||
});
|
||||
|
||||
test('new borrow requests cannot target an archived asset', async () => {
|
||||
const fixture = createFixture(() => ({ recordset: [{
|
||||
AssetId: 17, IsArchived: true, Quantity: 10, EndingBalance: 7,
|
||||
|
||||
@@ -11,13 +11,19 @@ function fixture({ allowed = true, confirmed = true, responseSuccess = true } =
|
||||
const refreshed = [];
|
||||
const notifications = [];
|
||||
const button = { disabled: false };
|
||||
const archiveTableBody = { innerHTML: '' };
|
||||
const archiveCount = { textContent: '' };
|
||||
const fetch = async (url, options) => {
|
||||
requests.push({ url, options });
|
||||
return { ok: responseSuccess, json: async () => ({ success: responseSuccess, data: { archivedCount: 2 } }) };
|
||||
};
|
||||
const document = {
|
||||
addEventListener() {},
|
||||
getElementById: id => id === 'archiveAllAssetsBtn' ? button : null
|
||||
getElementById: id => ({
|
||||
archiveAllAssetsBtn: button,
|
||||
archivedAssetBorrowsTableBody: archiveTableBody,
|
||||
archivedAssetBorrowsCount: archiveCount
|
||||
})[id] || null
|
||||
};
|
||||
const context = vm.createContext({ document, window: { fetch }, fetch, console });
|
||||
vm.runInContext(`${source}\napp = Object.create(AccountManager.prototype); globalThis.manager = app;`, context);
|
||||
@@ -41,7 +47,7 @@ function fixture({ allowed = true, confirmed = true, responseSuccess = true } =
|
||||
notifyFailure: message => notifications.push(message),
|
||||
notifyWarning: message => notifications.push(message)
|
||||
});
|
||||
return { manager, requests, refreshed, notifications, button };
|
||||
return { manager, requests, refreshed, notifications, button, archiveTableBody, archiveCount };
|
||||
}
|
||||
|
||||
function borrow(BorrowId, overrides = {}) {
|
||||
@@ -58,10 +64,14 @@ test('all history retains completed loans and partial loans with related returns
|
||||
manager.assetBorrows = [
|
||||
borrow(1),
|
||||
borrow(2, { RelatedReturnCount: 1, ReturnedQuantity: 2, RemainingQuantity: 3 }),
|
||||
borrow(3, { RequestStatus: 'returned', ReturnedQuantity: 5, RemainingQuantity: 0 }),
|
||||
borrow(4, { RequestType: 'return' })
|
||||
borrow(3, { RequestStatus: 'returned', ReturnedQuantity: 5, RemainingQuantity: 0, IsArchived: true }),
|
||||
borrow(4, { RequestType: 'return', IsArchived: true })
|
||||
];
|
||||
assert.deepEqual(Array.from(manager.getFilteredAssetBorrows(), row => row.BorrowId), [1, 2, 3, 4]);
|
||||
manager.assetBorrowCatalogFilter = 'archived';
|
||||
assert.deepEqual(Array.from(manager.getFilteredAssetBorrows(), row => row.BorrowId), [3, 4]);
|
||||
manager.assetBorrowSearchTerm = 'tài sản cũ';
|
||||
assert.deepEqual(Array.from(manager.getFilteredAssetBorrows(), row => row.BorrowId), [3, 4]);
|
||||
});
|
||||
|
||||
test('outstanding loans include archived, partial, and pending-return loans, excluding other statuses', () => {
|
||||
@@ -110,6 +120,23 @@ test('legacy borrower summaries remain visible without any borrow requests or cu
|
||||
assert.deepEqual(Array.from(manager.getCurrentUserBorrowedAssets(), row => [row.AssetId, row.BorrowedQuantityByCurrentUser]), [[1, 2]]);
|
||||
});
|
||||
|
||||
test('old asset list includes every archived record, including assets with no outstanding borrower', () => {
|
||||
const { manager, archiveTableBody, archiveCount } = fixture();
|
||||
manager.archivedAssets = [
|
||||
{ AssetId: 1, AssetCode: 'BORROWED', AssetName: 'Máy đang mượn', Borrower: [{ name: 'An', quantity: 2 }], ExportInPeriod: 2, IsArchived: true },
|
||||
{ AssetId: 2, AssetCode: 'IN-STOCK', AssetName: 'Máy trong kho', Borrower: '', ExportInPeriod: 0, IsArchived: true },
|
||||
{ AssetId: 3, AssetCode: 'RETURNED', AssetName: 'Máy đã trả', Borrower: '', ExportInPeriod: 0, IsArchived: true }
|
||||
];
|
||||
assert.deepEqual(Array.from(manager.getFilteredArchivedAssets(), row => row.AssetId), [1, 2, 3]);
|
||||
manager.renderArchivedAssetBorrowsTable();
|
||||
assert.match(archiveTableBody.innerHTML, /BORROWED/);
|
||||
assert.match(archiveTableBody.innerHTML, /IN-STOCK/);
|
||||
assert.match(archiveTableBody.innerHTML, /RETURNED/);
|
||||
assert.match(archiveCount.textContent, /3/);
|
||||
manager.archivedAssetSearchTerm = 'trong kho';
|
||||
assert.deepEqual(Array.from(manager.getFilteredArchivedAssets(), row => row.AssetId), [2]);
|
||||
});
|
||||
|
||||
test('same-code current and archived assets remain separate in my borrowed assets', () => {
|
||||
const { manager } = fixture();
|
||||
manager.getCurrentUserBorrowerNameKeys = () => ['an'];
|
||||
|
||||
Reference in New Issue
Block a user