Skip to content

Commit

Permalink
UIQM-709 Duplicate LCCN checking query > Do not return instance/bib r…
Browse files Browse the repository at this point in the history
…ecord that is set for deletion
  • Loading branch information
BogdanDenis committed Oct 3, 2024
1 parent 30c579b commit 87aaa7f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* [UIQM-706](https://issues.folio.org/browse/UIQM-706) *BREAKING* Upgrade `marc-records-editor` to `6.0`.
* [UIQM-698](https://issues.folio.org/browse/UIQM-698) Validate 006/007 field lengths.
* [UIQM-704](https://issues.folio.org/browse/UIQM-704) Linked fields - combine split fields before sending for validation.
* [UIQM-709](https://issues.folio.org/browse/UIQM-709) Duplicate LCCN checking query > Do not return instance/bib record that is set for deletion.

## [8.0.1] (https://github.com/folio-org/ui-quick-marc/tree/v8.0.1) (2024-04-18)

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useValidation/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const BASE_BIB_VALIDATORS = [
{
tag: '010',
validator: RULES.DUPLICATE_LCCN,
ignore: ({ duplicateLccnCheckingEnabled }) => !duplicateLccnCheckingEnabled,
message: () => ({ id: 'ui-quick-marc.record.error.010.lccnDuplicated' }),
},
];
Expand Down
115 changes: 115 additions & 0 deletions src/hooks/useValidation/useValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ describe('useValidation', () => {
marcType: MARC_TYPES.HOLDINGS,
action: QUICK_MARC_ACTIONS.EDIT,
locations,
instance: {},
};

testCommonValidationRules({ marcContext });
Expand All @@ -365,6 +366,7 @@ describe('useValidation', () => {
marcType: MARC_TYPES.HOLDINGS,
action: QUICK_MARC_ACTIONS.CREATE,
locations,
instance: {},
};

testCommonValidationRules({ marcContext });
Expand Down Expand Up @@ -409,6 +411,7 @@ describe('useValidation', () => {
linkableBibFields,
linkingRules,
fixedFieldSpec: fixedFieldSpecBib,
instance: {},
};

const record = {
Expand Down Expand Up @@ -651,6 +654,60 @@ describe('useValidation', () => {
}));
});
});

describe('when instance is staff suppressed', () => {
it('should not validate LCCN duplication', async () => {
useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances: [{}] }),
}),
});
const { result } = renderHook(() => useValidation({
...marcContext,
instance: {
staffSuppress: true,
},
}), {
wrapper: getWrapper(),
});

await result.current.validate(record.records);

expect(quickMarcContext.setValidationErrors).not.toHaveBeenCalledWith(expect.objectContaining({
4: [{
id: 'ui-quick-marc.record.error.010.lccnDuplicated',
severity: 'error',
}],
}));
});
});

describe('when instance is discovery suppressed', () => {
it('should not validate LCCN duplication', async () => {
useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances: [{}] }),
}),
});
const { result } = renderHook(() => useValidation({
...marcContext,
instance: {
discoverySuppress: true,
},
}), {
wrapper: getWrapper(),
});

await result.current.validate(record.records);

expect(quickMarcContext.setValidationErrors).not.toHaveBeenCalledWith(expect.objectContaining({
4: [{
id: 'ui-quick-marc.record.error.010.lccnDuplicated',
severity: 'error',
}],
}));
});
});
});

describe('when validating Holdings record', () => {
Expand Down Expand Up @@ -889,6 +946,7 @@ describe('useValidation', () => {
marcType: MARC_TYPES.HOLDINGS,
action: QUICK_MARC_ACTIONS.EDIT,
locations,
instance: {},
};

testBaseHoldingsValidation({ marcContext });
Expand All @@ -900,6 +958,7 @@ describe('useValidation', () => {
marcType: MARC_TYPES.HOLDINGS,
action: QUICK_MARC_ACTIONS.CREATE,
locations,
instance: {},
};

testBaseHoldingsValidation({ marcContext });
Expand Down Expand Up @@ -944,6 +1003,7 @@ describe('useValidation', () => {
linkableBibFields,
linkingRules,
fixedFieldSpec: fixedFieldSpecAuth,
instance: {},
};

const record = {
Expand Down Expand Up @@ -1039,6 +1099,60 @@ describe('useValidation', () => {
}]);
});
});

describe('when instance is staff suppressed', () => {
it('should not validate LCCN duplication', async () => {
useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances: [{}] }),
}),
});
const { result } = renderHook(() => useValidation({
...marcContext,
instance: {
staffSuppress: true,
},
}), {
wrapper: getWrapper(),
});

await result.current.validate(record.records);

expect(quickMarcContext.setValidationErrors).not.toHaveBeenCalledWith(expect.objectContaining({
4: [{
id: 'ui-quick-marc.record.error.010.lccnDuplicated',
severity: 'error',
}],
}));
});
});

describe('when instance is discovery suppressed', () => {
it('should not validate LCCN duplication', async () => {
useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances: [{}] }),
}),
});
const { result } = renderHook(() => useValidation({
...marcContext,
instance: {
discoverySuppress: true,
},
}), {
wrapper: getWrapper(),
});

await result.current.validate(record.records);

expect(quickMarcContext.setValidationErrors).not.toHaveBeenCalledWith(expect.objectContaining({
4: [{
id: 'ui-quick-marc.record.error.010.lccnDuplicated',
severity: 'error',
}],
}));
});
});
});

describe('when action is CREATE', () => {
Expand Down Expand Up @@ -1076,6 +1190,7 @@ describe('useValidation', () => {
linkableBibFields,
linkingRules,
fixedFieldSpec: fixedFieldSpecAuth,
instance: {},
};

const record = {
Expand Down
19 changes: 10 additions & 9 deletions src/hooks/useValidation/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,19 @@ export const validateFixedFieldLength = ({ marcRecords, fixedFieldSpec, marcType

return undefined;
};
export const validateLccnDuplication = async ({
ky,
marcRecords,
duplicateLccnCheckingEnabled,
instanceId,
action,
marcType,
}, rule) => {
if (!duplicateLccnCheckingEnabled) {
export const validateLccnDuplication = async (context, rule) => {
if (rule.ignore?.(context)) {
return undefined;
}

const {
ky,
marcRecords,
instanceId,
action,
marcType,
} = context;

const fields = marcRecords.filter(record => record.tag.match(rule.tag));

const validateField = async (field) => {
Expand Down

0 comments on commit 87aaa7f

Please sign in to comment.