|
| 1 | +import uuid from 'uuid'; |
| 2 | +import moment from 'moment'; |
| 3 | +import Permissions from '../../../../support/dictionary/permissions'; |
| 4 | +import { LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS } from '../../../../support/constants/query-builder/lostItemsRequiringActualCostFields'; |
| 5 | +import QueryModal, { QUERY_OPERATIONS } from '../../../../support/fragments/bulk-edit/query-modal'; |
| 6 | +import { Lists } from '../../../../support/fragments/lists/lists'; |
| 7 | +import TopMenu from '../../../../support/fragments/topMenu'; |
| 8 | +import Users from '../../../../support/fragments/users/users'; |
| 9 | +import InventoryInstances from '../../../../support/fragments/inventory/inventoryInstances'; |
| 10 | +import { Locations, ServicePoints } from '../../../../support/fragments/settings/tenant'; |
| 11 | +import UserEdit from '../../../../support/fragments/users/userEdit'; |
| 12 | +import Checkout from '../../../../support/fragments/checkout/checkout'; |
| 13 | +import UserLoans from '../../../../support/fragments/users/loans/userLoans'; |
| 14 | +import UsersOwners from '../../../../support/fragments/settings/users/usersOwners'; |
| 15 | +import LostItemFeePolicy from '../../../../support/fragments/circulation/lost-item-fee-policy'; |
| 16 | +import CirculationRules from '../../../../support/fragments/circulation/circulation-rules'; |
| 17 | +import getRandomPostfix from '../../../../support/utils/stringTools'; |
| 18 | + |
| 19 | +let user; |
| 20 | +const listName = `AT_C1282801_List_${getRandomPostfix()}`; |
| 21 | +const instanceName = `AT_C1282801_FolioInstance_${getRandomPostfix()}`; |
| 22 | +const itemBarcode = `barcode-${getRandomPostfix()}`; |
| 23 | + |
| 24 | +const testData = { |
| 25 | + userServicePoint: ServicePoints.getDefaultServicePointWithPickUpLocation(), |
| 26 | +}; |
| 27 | + |
| 28 | +const ownerBody = { |
| 29 | + owner: 'AutotestOwner' + getRandomPostfix(), |
| 30 | + servicePointOwner: [ |
| 31 | + { |
| 32 | + value: testData.userServicePoint.id, |
| 33 | + label: testData.userServicePoint.name, |
| 34 | + }, |
| 35 | + ], |
| 36 | +}; |
| 37 | + |
| 38 | +const lostItemFeePolicy = { |
| 39 | + name: `ActualCostPolicy_${getRandomPostfix()}`, |
| 40 | + chargeAmountItem: { |
| 41 | + chargeType: 'actualCost', |
| 42 | + amount: 0.0, |
| 43 | + }, |
| 44 | + lostItemProcessingFee: 0.0, |
| 45 | + chargeAmountItemPatron: true, |
| 46 | + chargeAmountItemSystem: true, |
| 47 | + returnedLostItemProcessingFee: false, |
| 48 | + replacedLostItemProcessingFee: false, |
| 49 | + replacementProcessingFee: 0.0, |
| 50 | + replacementAllowed: false, |
| 51 | + lostItemReturned: 'Charge', |
| 52 | + id: uuid(), |
| 53 | +}; |
| 54 | + |
| 55 | +describe('Lists', () => { |
| 56 | + describe('Query Builder', () => { |
| 57 | + describe('Composite Entity Types', () => { |
| 58 | + before('Create test data', () => { |
| 59 | + cy.getAdminToken(); |
| 60 | + ServicePoints.getCircDesk2ServicePointViaApi().then((servicePoint) => { |
| 61 | + testData.userServicePoint = servicePoint; |
| 62 | + |
| 63 | + Locations.getViaApiAnyDefault().then((location) => { |
| 64 | + testData.defaultLocation = location[0]; |
| 65 | + |
| 66 | + testData.instanceId = InventoryInstances.createInstanceViaApi( |
| 67 | + instanceName, |
| 68 | + itemBarcode, |
| 69 | + ); |
| 70 | + cy.getHoldings({ limit: 1, query: `"instanceId"="${testData.instanceId}"` }).then( |
| 71 | + (holdings) => { |
| 72 | + cy.updateHoldingRecord(holdings[0].id, { |
| 73 | + ...holdings[0], |
| 74 | + permanentLocationId: testData.defaultLocation.id, |
| 75 | + }); |
| 76 | + }, |
| 77 | + ); |
| 78 | + |
| 79 | + cy.getItems({ limit: 1, expandAll: true, query: `"barcode"=="${itemBarcode}"` }).then( |
| 80 | + (res) => { |
| 81 | + testData.materialTypeId = res.materialType.id; |
| 82 | + testData.itemId = res.id; |
| 83 | + |
| 84 | + LostItemFeePolicy.createViaApi(lostItemFeePolicy); |
| 85 | + CirculationRules.addRuleViaApi( |
| 86 | + { m: testData.materialTypeId }, |
| 87 | + { i: lostItemFeePolicy.id }, |
| 88 | + ).then((newRule) => { |
| 89 | + testData.addedRule = newRule; |
| 90 | + }); |
| 91 | + }, |
| 92 | + ); |
| 93 | + |
| 94 | + UsersOwners.createViaApi(ownerBody).then((ownerResponse) => { |
| 95 | + testData.ownerId = ownerResponse.id; |
| 96 | + }); |
| 97 | + |
| 98 | + cy.createTempUser([ |
| 99 | + Permissions.listsEdit.gui, |
| 100 | + Permissions.uiUsersView.gui, |
| 101 | + Permissions.uiUserLostItemRequiringActualCost.gui, |
| 102 | + ]).then((userProperties) => { |
| 103 | + user = userProperties; |
| 104 | + |
| 105 | + UserEdit.addServicePointViaApi(testData.userServicePoint.id, user.userId); |
| 106 | + Checkout.checkoutItemViaApi({ |
| 107 | + itemBarcode, |
| 108 | + userBarcode: user.barcode, |
| 109 | + servicePointId: testData.userServicePoint.id, |
| 110 | + }); |
| 111 | + UserLoans.getUserLoansIdViaApi(user.userId).then((userLoans) => { |
| 112 | + UserLoans.declareLoanLostViaApi( |
| 113 | + { |
| 114 | + servicePointId: testData.userServicePoint.id, |
| 115 | + declaredLostDateTime: moment.utc().format(), |
| 116 | + }, |
| 117 | + userLoans.loans[0].id, |
| 118 | + ); |
| 119 | + }); |
| 120 | + |
| 121 | + cy.login(user.username, user.password, { |
| 122 | + path: TopMenu.listsPath, |
| 123 | + waiter: Lists.waitLoading, |
| 124 | + }); |
| 125 | + }); |
| 126 | + }); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + after('Delete test data', () => { |
| 131 | + cy.getAdminToken(); |
| 132 | + CirculationRules.deleteRuleViaApi(testData.addedRule); |
| 133 | + InventoryInstances.deleteInstanceAndHoldingRecordAndAllItemsViaApi(itemBarcode); |
| 134 | + LostItemFeePolicy.deleteViaApi(lostItemFeePolicy.id); |
| 135 | + Users.deleteViaApi(user.userId); |
| 136 | + UsersOwners.deleteViaApi(testData.ownerId); |
| 137 | + Lists.deleteListByNameViaApi(listName); |
| 138 | + }); |
| 139 | + |
| 140 | + it( |
| 141 | + 'C1282801 Composite ET: Lost items requiring actual cost (corsair)', |
| 142 | + { tags: ['criticalPath', 'corsair', 'C1282801'] }, |
| 143 | + () => { |
| 144 | + // Step 1: Click "New" button, enter list name, select "Lost items requiring actual cost" record type |
| 145 | + Lists.openNewListPane(); |
| 146 | + Lists.setName(listName); |
| 147 | + Lists.selectRecordType(Lists.recordTypes.lostItemsRequiringActualCost); |
| 148 | + Lists.verifySaveButtonIsActive(); |
| 149 | + Lists.verifyCancelButtonIsActive(); |
| 150 | + |
| 151 | + // Step 2: Click "Build query" button |
| 152 | + Lists.buildQuery(); |
| 153 | + QueryModal.verify(); |
| 154 | + |
| 155 | + // Step 3: Click "Field" dropdown - verify field sources available |
| 156 | + QueryModal.verifyAllAvailableFieldOptions([ |
| 157 | + ...Object.values(LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.ACTUAL_COST), |
| 158 | + ...Object.values(LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.ACTUAL_COST_CREATED_BY), |
| 159 | + ...Object.values(LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.ACTUAL_COST_UPDATED_BY), |
| 160 | + ...Object.values(LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.USER), |
| 161 | + ]); |
| 162 | + |
| 163 | + // Step 4: Build a query that returns at least 1 record |
| 164 | + QueryModal.selectField(LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.USER.BARCODE); |
| 165 | + QueryModal.selectOperator(QUERY_OPERATIONS.EQUAL); |
| 166 | + QueryModal.fillInValueTextfield(user.barcode); |
| 167 | + QueryModal.testQuery(); |
| 168 | + |
| 169 | + // Verify precondition record is in results |
| 170 | + QueryModal.verifyPreviewOfRecordsMatched(); |
| 171 | + QueryModal.verifyNumberOfMatchedRecords(1); |
| 172 | + Lists.verifyResultCellContains( |
| 173 | + 0, |
| 174 | + LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.USER.BARCODE, |
| 175 | + user.barcode, |
| 176 | + ); |
| 177 | + |
| 178 | + // Step 5: Click "Run query & save" |
| 179 | + Lists.runQueryAndSave(); |
| 180 | + Lists.verifyListSavedCalloutMessage(listName); |
| 181 | + |
| 182 | + // Step 6: Wait for list refresh - verify toast and record count |
| 183 | + Lists.waitForCompilingToComplete(); |
| 184 | + Lists.verifySingleRecordNumber(); |
| 185 | + |
| 186 | + // Step 7: Verify record table displays based on query |
| 187 | + Lists.verifyResultCellContains( |
| 188 | + 0, |
| 189 | + LOST_ITEMS_REQUIRING_ACTUAL_COST_FIELDS.USER.BARCODE, |
| 190 | + user.barcode, |
| 191 | + ); |
| 192 | + }, |
| 193 | + ); |
| 194 | + }); |
| 195 | + }); |
| 196 | +}); |
0 commit comments