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 7f254c4
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 13 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
12 changes: 11 additions & 1 deletion src/QuickMarcEditor/QuickMarcCreateWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ const QuickMarcCreateWrapper = ({
sourceFiles,
fixedFieldSpec,
instanceId: instance.id,
}), [initialValues, marcType, locations, linkableBibFields, linkingRules, sourceFiles, fixedFieldSpec, instance.id]);
instance,
}), [
initialValues,
marcType,
locations,
linkableBibFields,
linkingRules,
sourceFiles,
fixedFieldSpec,
instance,
]);
const { validate } = useValidation(validationContext, tenantId);

const prepareForSubmit = useCallback((formValues) => {
Expand Down
3 changes: 2 additions & 1 deletion src/QuickMarcEditor/QuickMarcDeriveWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const QuickMarcDeriveWrapper = ({
linkingRules,
fixedFieldSpec,
instanceId: instance.id,
}), [initialValues, marcType, linkableBibFields, linkingRules, fixedFieldSpec, instance.id]);
instance,
}), [initialValues, marcType, linkableBibFields, linkingRules, fixedFieldSpec, instance]);
const { validate } = useValidation(validationContext);

const prepareForSubmit = useCallback((formValues) => {
Expand Down
4 changes: 2 additions & 2 deletions src/QuickMarcEditor/QuickMarcEditWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const QuickMarcEditWrapper = ({
linkingRules,
fixedFieldSpec,
instanceId: instance.id,
instance,
}), [
initialValues,
marcType,
Expand All @@ -109,8 +110,7 @@ const QuickMarcEditWrapper = ({
linkingRules,
fixedFieldSpec,
linksCount,
instance.naturalId,
instance.id,
instance,
]);
const { validate } = useValidation(validationContext, tenantId);

Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useValidation/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const BASE_BIB_VALIDATORS = [
{
tag: '010',
validator: RULES.DUPLICATE_LCCN,
ignore: ({ duplicateLccnCheckingEnabled, instance }) => {
return !duplicateLccnCheckingEnabled || (instance.discoverySuppress || instance.staffSuppress);
},
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 7f254c4

Please sign in to comment.