Skip to content

Commit

Permalink
FAT-11950-C410759 (#3212)
Browse files Browse the repository at this point in the history
FAT-11950
  • Loading branch information
zentestuken committed Feb 19, 2024
1 parent 7102333 commit f7dd86d
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
import Permissions from '../../../../support/dictionary/permissions';
import Affiliations, { tenantNames } from '../../../../support/dictionary/affiliations';
import Users from '../../../../support/fragments/users/users';
import TopMenu from '../../../../support/fragments/topMenu';
import InventoryInstances from '../../../../support/fragments/inventory/inventoryInstances';
import InventoryInstance from '../../../../support/fragments/inventory/inventoryInstance';
import ConsortiumManager from '../../../../support/fragments/settings/consortium-manager/consortium-manager';
import getRandomPostfix, {
getTestEntityValue,
getRandomLetters,
} from '../../../../support/utils/stringTools';
import InventoryHoldings from '../../../../support/fragments/inventory/holdings/inventoryHoldings';
import ServicePoints from '../../../../support/fragments/settings/tenant/servicePoints/servicePoints';
import Locations from '../../../../support/fragments/settings/tenant/location-setup/locations';
import InventorySearchAndFilter from '../../../../support/fragments/inventory/inventorySearchAndFilter';
import InventoryItems from '../../../../support/fragments/inventory/item/inventoryItems';
import BrowseCallNumber from '../../../../support/fragments/inventory/search/browseCallNumber';
import QuickMarcEditor from '../../../../support/fragments/quickMarcEditor';

describe('Inventory', () => {
describe('Call Number Browse', () => {
describe('Consortia', () => {
const instancePrefix = `C410759Auto Instance ${getRandomPostfix()}`;
const callNumberPrefix = `C410759Auto${getRandomLetters(10)}`;
const testData = {
instances: [
{
title: `${instancePrefix} 1`,
instanceTenant: Affiliations.Consortia,
isMarc: false,
holdings: {
college: {
callNumberInHoldings: true,
callNumber: `${callNumberPrefix} Inst01 Call FH`,
},
},
},
{
title: `${instancePrefix} 2`,
instanceTenant: Affiliations.Consortia,
isMarc: false,
holdings: {
college: {
callNumberInHoldings: false,
callNumber: `${callNumberPrefix} Inst02 Call FI`,
},
},
},
{
title: `${instancePrefix} 3`,
instanceTenant: Affiliations.Consortia,
isMarc: true,
holdings: {
college: {
callNumberInHoldings: true,
callNumber: `${callNumberPrefix} Inst03 Call MH`,
},
},
},
{
title: `${instancePrefix} 4`,
instanceTenant: Affiliations.Consortia,
isMarc: true,
holdings: {
college: {
callNumberInHoldings: false,
callNumber: `${callNumberPrefix} Inst04 Call MI`,
},
},
},
{
title: `${instancePrefix} 5`,
instanceTenant: Affiliations.College,
isMarc: false,
holdings: {
college: {
callNumberInHoldings: true,
callNumber: `${callNumberPrefix} Inst05 Call FH`,
},
},
},
{
title: `${instancePrefix} 6`,
instanceTenant: Affiliations.College,
isMarc: false,
holdings: {
college: {
callNumberInHoldings: false,
callNumber: `${callNumberPrefix} Inst06 Call FI`,
},
},
},
{
title: `${instancePrefix} 7`,
instanceTenant: Affiliations.College,
isMarc: true,
holdings: {
college: {
callNumberInHoldings: true,
callNumber: `${callNumberPrefix} Inst07 Call MH`,
},
},
},
{
title: `${instancePrefix} 8`,
instanceTenant: Affiliations.College,
isMarc: true,
holdings: {
college: {
callNumberInHoldings: false,
callNumber: `${callNumberPrefix} Inst08 Call MI`,
},
},
},
],
callNumberBrowseoption: 'Call numbers (all)',
};
const allVisibleCNs = [
`${callNumberPrefix} Inst01 Call FH`,
`${callNumberPrefix} Inst02 Call FI`,
`${callNumberPrefix} Inst03 Call MH`,
`${callNumberPrefix} Inst04 Call MI`,
];
const allNonVisibleCNs = [
`${callNumberPrefix} Inst05 Call FH`,
`${callNumberPrefix} Inst06 Call FI`,
`${callNumberPrefix} Inst07 Call MH`,
`${callNumberPrefix} Inst08 Call MI`,
];
const createdInstanceIds = {
consortia: [],
college: [],
};
const createdHoldingsIds = [];
const createdItemIds = [];
let location;
let loanTypeId;
let materialTypeId;

function createFolioInstance(instanceTitle, tenantId) {
const targetTenant = Object.keys(Affiliations)
.find((key) => Affiliations[key] === tenantId)
.toLowerCase();
cy.setTenant(tenantId);
InventoryInstance.createInstanceViaApi({
instanceTitle,
}).then((instanceData) => {
createdInstanceIds[targetTenant].push(instanceData.instanceData.instanceId);
testData.instances[
testData.instances.findIndex((instance) => instance.title === instanceTitle)
].instanceId = instanceData.instanceData.instanceId;
});
}

function addHoldingsRecordInCollege(instanceId) {
const instance =
testData.instances[
testData.instances.findIndex((inst) => inst.instanceId === instanceId)
];
cy.setTenant(Affiliations.College);
InventoryHoldings.createHoldingRecordViaApi({
instanceId,
permanentLocationId: location.id,
callNumber: instance.holdings.college.callNumberInHoldings
? instance.holdings.college.callNumber
: null,
}).then((holding) => {
createdHoldingsIds.push(holding.id);
instance.holdings.college.id = holding.id;
});
}

function addItemRecordInCollege(instanceId) {
const instance =
testData.instances[
testData.instances.findIndex((inst) => inst.instanceId === instanceId)
];
cy.setTenant(Affiliations.College);
InventoryItems.createItemViaApi({
holdingsRecordId: instance.holdings.college.id,
materialType: { id: materialTypeId },
permanentLoanType: { id: loanTypeId },
status: { name: 'Available' },
itemLevelCallNumber: instance.holdings.college.callNumberInHoldings
? null
: instance.holdings.college.callNumber,
}).then((item) => {
createdItemIds.push(item.id);
});
}

before('Create user, data', () => {
cy.getAdminToken();

cy.createTempUser([Permissions.uiInventoryViewInstances.gui])
.then((userProperties) => {
testData.userProperties = userProperties;

cy.setTenant(Affiliations.College);
const collegeLocationData = Locations.getDefaultLocation({
servicePointId: ServicePoints.getDefaultServicePoint().id,
}).location;
Locations.createViaApi(collegeLocationData).then((loc) => {
location = loc;
});
cy.createLoanType({
name: getTestEntityValue('type'),
}).then((loanType) => {
loanTypeId = loanType.id;
});
cy.getMaterialTypes({ limit: 1 }).then((matType) => {
materialTypeId = matType.id;
});
})
.then(() => {
testData.instances
.filter((inst) => !inst.isMarc)
.forEach((instance) => {
createFolioInstance(instance.title, instance.instanceTenant);
});
testData.instances
.filter((inst) => inst.isMarc)
.forEach((instance) => {
const targetTenant = Object.keys(Affiliations)
.find((key) => Affiliations[key] === instance.instanceTenant)
.toLowerCase();
cy.setTenant(instance.instanceTenant);
cy.createSimpleMarcBibViaAPI(instance.title);
QuickMarcEditor.getCreatedMarcBib(instance.title).then((bib) => {
createdInstanceIds[targetTenant].push(bib.id);
testData.instances[
testData.instances.findIndex((inst) => inst.title === instance.title)
].instanceId = bib.id;
});
});
});
});

before(() => {
testData.instances.forEach((instance) => {
addHoldingsRecordInCollege(instance.instanceId);
});
});

before(() => {
testData.instances.forEach((instance) => {
addItemRecordInCollege(instance.instanceId);
});
cy.login(testData.userProperties.username, testData.userProperties.password, {
path: TopMenu.inventoryPath,
waiter: InventoryInstances.waitContentLoading,
}).then(() => {
ConsortiumManager.checkCurrentTenantInTopMenu(tenantNames.central);
InventorySearchAndFilter.selectBrowseCallNumbers();
});
});

after('Delete user, data', () => {
cy.resetTenant();
cy.getAdminToken();
Users.deleteViaApi(testData.userProperties.userId);

cy.setTenant(Affiliations.College);
createdItemIds.forEach((id) => {
InventoryItems.deleteItemViaApi(id);
});
createdHoldingsIds.forEach((id) => {
InventoryHoldings.deleteHoldingRecordViaApi(id);
});
Locations.deleteViaApi(location);
cy.deleteLoanType(loanTypeId);

cy.setTenant(Affiliations.College);
createdInstanceIds.college.forEach((id) => {
InventoryInstance.deleteInstanceViaApi(id);
});
cy.resetTenant();
createdInstanceIds.consortia.forEach((id) => {
InventoryInstance.deleteInstanceViaApi(id);
});
});

it(
'C410759 Call numbers from "Shared" Instance records are shown in the browse result list on Central tenant (consortia) (spitfire)',
{ tags: ['criticalPathECS', 'spitfire'] },
() => {
InventorySearchAndFilter.browseSearch(callNumberPrefix);
BrowseCallNumber.checkNonExactSearchResult(callNumberPrefix);
allVisibleCNs.forEach((callNumber) => {
BrowseCallNumber.checkValuePresentInResults(callNumber);
});
InventorySearchAndFilter.browseSearch(allNonVisibleCNs[0]);
BrowseCallNumber.checkNonExactSearchResult(allNonVisibleCNs[0]);
allNonVisibleCNs.forEach((callNumber) => {
BrowseCallNumber.checkValuePresentInResults(callNumber, false);
});
InventorySearchAndFilter.browseSearch(allVisibleCNs[0]);
BrowseCallNumber.valueInResultTableIsHighlighted(allVisibleCNs[0]);
allVisibleCNs.forEach((callNumber) => {
BrowseCallNumber.checkValuePresentInResults(callNumber);
});
BrowseCallNumber.clickOnResult(allVisibleCNs[0]);
InventorySearchAndFilter.verifyInstanceDisplayed(testData.instances[0].title);
InventorySearchAndFilter.verifyNumberOfSearchResults(1);
InventoryInstance.verifySharedIcon();
InventorySearchAndFilter.switchToBrowseTab();
InventorySearchAndFilter.verifyCallNumberBrowsePane();
BrowseCallNumber.valueInResultTableIsHighlighted(allVisibleCNs[0]);
allVisibleCNs.forEach((callNumber) => {
BrowseCallNumber.checkValuePresentInResults(callNumber);
});
BrowseCallNumber.clickOnResult(allVisibleCNs[2]);
InventorySearchAndFilter.verifyInstanceDisplayed(testData.instances[2].title);
InventorySearchAndFilter.verifyNumberOfSearchResults(1);
InventoryInstance.verifySharedIcon();
},
);
});
});
});
65 changes: 65 additions & 0 deletions cypress/support/api/inventory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid from 'uuid';
import { INSTANCE_SOURCE_NAMES } from '../constants';
import QuickMarcEditor from '../fragments/quickMarcEditor';

const DEFAULT_INSTANCE = {
source: INSTANCE_SOURCE_NAMES.FOLIO,
Expand Down Expand Up @@ -333,3 +334,67 @@ Cypress.Commands.add('getHridHandlingSettingsViaApi', () => {
return body;
});
});

Cypress.Commands.add('createSimpleMarcBibViaAPI', (title) => {
cy.okapiRequest({
path: 'records-editor/records',
method: 'POST',
isDefaultSearchParamsRequired: false,
body: {
_actionType: 'create',
leader: QuickMarcEditor.defaultValidLdr,
fields: [
{
tag: '008',
content: QuickMarcEditor.defaultValid008Values,
},
{
tag: '245',
content: `$a ${title}`,
indicators: ['\\', '\\'],
},
],
suppressDiscovery: false,
marcFormat: 'BIBLIOGRAPHIC',
},
}).then(({ body }) => cy.wrap(body).as('body'));
return cy.get('@body');
});

Cypress.Commands.add(
'createSimpleMarcHoldingsViaAPI',
(instanceId, instanceHrid, locationCode, actionNote = 'note') => {
cy.okapiRequest({
path: 'records-editor/records',
method: 'POST',
isDefaultSearchParamsRequired: false,
body: {
_actionType: 'create',
externalId: instanceId,
fields: [
{
content: instanceHrid,
tag: '004',
},
{
content: QuickMarcEditor.defaultValid008HoldingsValues,
tag: '008',
},
{
content: `$b ${locationCode}`,
indicators: ['\\', '\\'],
tag: '852',
},
{
content: `$a ${actionNote}`,
indicators: ['\\', '\\'],
tag: '583',
},
],
leader: QuickMarcEditor.defaultValidHoldingsLdr,
marcFormat: 'HOLDINGS',
suppressDiscovery: false,
},
}).then(({ body }) => cy.expect(body.status === 'IN_PROGRESS'));
},
);
Loading

0 comments on commit f7dd86d

Please sign in to comment.