Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAT-16627-C506695 #4233

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Permissions } from '../../../../support/dictionary';
import Users from '../../../../support/fragments/users/users';

describe('Inventory', () => {
describe('Settings', () => {
describe('Classification browse', () => {
let user;
let originalDateType;

const testData = {
totalAmountOfDateTypes: 15,
dateTypeSource: 'folio',
displayFormatKey: 'displayFormat',
codeKey: 'code',
delimiterKey: 'delimiter',
keepDelimiterKey: 'keepDelimiter',
sourceKey: 'source',
newCode: 's',
newDelimiter: ',',
newKeepDelimiter: false,
newSource: 'local',
};

const errorMessageText = (key) => `Unrecognized field "${key}"`;

before('Create user, get data', () => {
cy.getAdminToken();
cy.getInstanceDateTypesViaAPI().then((response) => {
originalDateType = response.instanceDateTypes[0];
});
cy.createTempUser([
Permissions.getInstanceDateTypes.gui,
Permissions.patchInstanceDateTypes.gui,
]).then((userProperties) => {
user = userProperties;
});
});

after('Delete user', () => {
cy.getAdminToken();
// restore the original instance date type field values (if changed)
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData[testData.codeKey],
originalDateType[testData.codeKey],
true,
);
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData[testData.displayFormatKey],
{
delimiter: originalDateType[testData.delimiterKey],
keepDelimiter: originalDateType[testData.keepDelimiterKey],
},
true,
);
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData[testData.sourceKey],
originalDateType[testData.sourceKey],
true,
);
Users.deleteViaApi(user.userId);
});

it(
'C506695 Cannot update "code", "delimiter", "keepDelimiter", "source" of Date type (spitfire)',
{ tags: ['criticalPath', 'spitfire'] },
() => {
cy.getUserToken(user.username, user.password);
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData.codeKey,
testData.newCode,
true,
).then(({ status, body }) => {
expect(status).to.eq(422);
expect(body.errors[0].message).to.include(errorMessageText(testData.codeKey));
});
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData.displayFormatKey,
{ delimiter: testData.newDelimiter },
true,
).then(({ status, body }) => {
expect(status).to.eq(422);
expect(body.errors[0].message).to.include(errorMessageText(testData.displayFormatKey));
});
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData.displayFormatKey,
{ keepDelimiter: testData.newKeepDelimiter },
true,
).then(({ status, body }) => {
expect(status).to.eq(422);
expect(body.errors[0].message).to.include(errorMessageText(testData.displayFormatKey));
});
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData.sourceKey,
testData.newSource,
true,
).then(({ status, body }) => {
expect(status).to.eq(422);
expect(body.errors[0].message).to.include(errorMessageText(testData.sourceKey));
});

cy.getInstanceDateTypesViaAPI().then((response) => {
expect(response.status).to.eq(200);
const updatedDateType = response.instanceDateTypes.filter(
(type) => type.id === originalDateType.id,
)[0];
expect(updatedDateType[testData.codeKey]).to.eq(originalDateType[testData.codeKey]);
expect(updatedDateType[testData.displayFormatKey][testData.delimiterKey]).to.eq(
originalDateType[testData.displayFormatKey][testData.delimiterKey],
);
expect(updatedDateType[testData.displayFormatKey][testData.keepDelimiterKey]).to.eq(
originalDateType[testData.displayFormatKey][testData.keepDelimiterKey],
);
expect(updatedDateType[testData.sourceKey]).to.eq(originalDateType[testData.sourceKey]);
});
},
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('Inventory', () => {
originalDateType = response.instanceDateTypes[response.instanceDateTypes.length - 1];
});
cy.createTempUser([
Permissions.uiInventorySettingsConfigureClassificationBrowse.gui,
Permissions.crudClassificationIdentifierTypes.gui,
Permissions.getInstanceDateTypes.gui,
Permissions.patchInstanceDateTypes.gui,
]).then((userProperties) => {
user = userProperties;
});
Expand All @@ -35,6 +35,7 @@ describe('Inventory', () => {
originalDateType.id,
testData.keyToUpdate,
originalDateType.name,
true,
);
Users.deleteViaApi(user.userId);
});
Expand All @@ -43,6 +44,7 @@ describe('Inventory', () => {
'C506694 Update of Date type\'s "name" (spitfire)',
{ tags: ['criticalPath', 'spitfire'] },
() => {
cy.getUserToken(user.username, user.password);
cy.patchInstanceDateTypeViaAPI(
originalDateType.id,
testData.keyToUpdate,
Expand Down
24 changes: 14 additions & 10 deletions cypress/support/api/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,17 @@ Cypress.Commands.add('getInstanceDateTypesViaAPI', (limit = 20) => {
});
});

Cypress.Commands.add('patchInstanceDateTypeViaAPI', (dateTypeId, keyToUpdate, value) => {
const patchBody = {};
patchBody[keyToUpdate] = value;
return cy.okapiRequest({
method: 'PATCH',
path: `instance-date-types/${dateTypeId}`,
body: patchBody,
isDefaultSearchParamsRequired: false,
});
});
Cypress.Commands.add(
'patchInstanceDateTypeViaAPI',
(dateTypeId, keyToUpdate, value, ignoreErrors = false) => {
const patchBody = {};
patchBody[keyToUpdate] = value;
return cy.okapiRequest({
method: 'PATCH',
path: `instance-date-types/${dateTypeId}`,
body: patchBody,
isDefaultSearchParamsRequired: false,
failOnStatusCode: !ignoreErrors,
});
},
);
8 changes: 8 additions & 0 deletions cypress/support/dictionary/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ export default {
internal: 'ui-inventory.instance.view-staff-suppressed-records',
gui: 'Inventory: Enable staff suppress facet',
},
patchInstanceDateTypes: {
internal: 'inventory-storage.instance-date-types.item.patch',
gui: 'inventory storage - patch instance-date-type',
},
getInstanceDateTypes: {
internal: 'inventory-storage.instance-date-types.collection.get',
gui: 'inventory storage - get list of instance-date-types',
},
// Tags
uiTagsPermissionAll: { internal: 'ui-tags.permission.all', gui: 'Tags: All permissions' },
uiViewTagsSettings: {
Expand Down
Loading