Skip to content

Commit

Permalink
FAT-16627: test added (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
zentestuken authored Sep 23, 2024
1 parent 59e8c81 commit fcde950
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 12 deletions.
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

0 comments on commit fcde950

Please sign in to comment.