Skip to content

Commit

Permalink
UIQM-709 use search search parameters to not include suppressed records
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Oct 4, 2024
1 parent f3acbd9 commit a78bd3f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 174 deletions.
166 changes: 0 additions & 166 deletions src/hooks/useValidation/useValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,118 +651,6 @@ describe('useValidation', () => {
}));
});
});

describe('when all instances are staff suppressed', () => {
it('should not return LCCN duplication error', async () => {
const instances = [{
staffSuppress: true,
}, {
staffSuppress: true,
}];

useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances }),
}),
});
const { result } = renderHook(() => useValidation(marcContext), {
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 one of the instances is not staff suppressed', () => {
it('should return LCCN duplication error', async () => {
const instances = [{
staffSuppress: true,
}, {
staffSuppress: false,
}];

useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances }),
}),
});
const { result } = renderHook(() => useValidation(marcContext), {
wrapper: getWrapper(),
});

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

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

describe('when all instances are discovery suppressed', () => {
it('should not return LCCN duplication error', async () => {
const instances = [{
discoverySuppress: true,
}, {
discoverySuppress: true,
}];

useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances }),
}),
});
const { result } = renderHook(() => useValidation(marcContext), {
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 one of the instances is not discovery suppressed', () => {
it('should return LCCN duplication error', async () => {
const instances = [{
discoverySuppress: true,
}, {
discoverySuppress: false,
}];

useOkapiKy.mockReturnValueOnce({
get: jest.fn().mockReturnValue({
json: jest.fn().mockResolvedValue({ instances }),
}),
});
const { result } = renderHook(() => useValidation(marcContext), {
wrapper: getWrapper(),
});

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

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

describe('when validating Holdings record', () => {
Expand Down Expand Up @@ -1151,60 +1039,6 @@ 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
10 changes: 2 additions & 8 deletions src/hooks/useValidation/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export const validateLccnDuplication = async (context, rule) => {

const searchParams = {
limit: 1,
query: `(${lccnQuery})${idQuery}`,
query: `(${lccnQuery})${idQuery} and (staffSuppress=="false" or discoverySuppress=="false")`,
};

const requests = {
Expand All @@ -491,13 +491,7 @@ export const validateLccnDuplication = async (context, rule) => {
try {
const response = await requests[marcType]().json();

const records = response?.authorities || response?.instances || [];

if (!records.length) {
return undefined;
}

const isLccnDuplicated = records.some((record) => !record.staffSuppress && !record.discoverySuppress);
const isLccnDuplicated = response?.authorities?.[0] || response?.instances?.[0];

if (isLccnDuplicated) {
return rule.message();
Expand Down

0 comments on commit a78bd3f

Please sign in to comment.