Skip to content

Commit

Permalink
Merge pull request #1466 from danskernesdigitalebibliotek/DDFHER-90-i…
Browse files Browse the repository at this point in the history
…nstant-loan-use-name

DDFHER-90 - Refactor `getInstantLoanBranchHoldings` to use `materialGroup.name`
  • Loading branch information
kasperbirch1 authored Oct 8, 2024
2 parents 2f9ddf6 + 3899be0 commit 427cb57
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/apps/material/material.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ const meta: Meta<typeof MaterialEntry> = {
instantLoanUnderlineDescriptionText:
"Bogen er tilgængelig på disse biblioteker nær dig",
instantLoanConfig:
'{ "threshold": "1", "matchStrings": ["31 dages lånetid til alm lånere"], "enabled": "true" }',
'{ "threshold": "1", "matchStrings": ["standard"], "enabled": "true" }',
interestPeriodsConfig:
'{ "interestPeriods":[ { "value":14, "label":"14 days" }, { "value":30, "label":"1 month" }, { "value":60, "label":"2 months" }, { "value":90, "label":"3 months" }, { "value":180, "label":"6 months" }, { "value":365, "label":"1 year" } ], "defaultInterestPeriod":{ "value":"14", "label":"14 days" } }',
openOrderResponseTitleText: "Order from another library:",
Expand Down
5 changes: 2 additions & 3 deletions src/components/reservation/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,11 @@ export const getInstantLoanBranchHoldings = (
const filteredMaterials = consolidatedHoldings(filteredBranchHoldings)
.map(({ branch, materials }) => {
const filtered = materials.filter(({ materialGroup, available }) => {
// if a material group description contains any of the instant loan strings
// if a material group name contains any of the instant loan strings
// and is available, it is an instant loan.
return (
instantLoanStrings.some(
(instantLoanString) =>
instantLoanString === materialGroup.description
(instantLoanString) => instantLoanString === materialGroup.name
) && available
);
});
Expand Down
44 changes: 22 additions & 22 deletions src/tests/unit/__vitest_data__/instant-loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ const branchHoldings: HoldingsV3[] = [
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched"
name: "I am supposed to be matched",
description: undefined
}
},
{
itemNumber: "000",
available: false,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched" // But am not available
name: "I am supposed to be matched", // But am not available
description: undefined
}
},
{
itemNumber: "000",
available: false,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am NOT supposed to be matched"
name: "I am NOT supposed to be matched",
description: "I am NOT supposed to be matched" // Description is optional and can be undefined
}
}
]
Expand All @@ -47,26 +47,26 @@ const branchHoldings: HoldingsV3[] = [
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched"
name: "I am supposed to be matched",
description: undefined
}
},
{
itemNumber: "000",
available: false,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am also supposed to be matched"
name: "I am also supposed to be matched",
description: undefined
}
},
{
itemNumber: "000",
available: false,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am NOT supposed to be matched"
name: "I am NOT supposed to be matched",
description: undefined
}
}
]
Expand All @@ -82,17 +82,17 @@ const branchHoldings: HoldingsV3[] = [
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched"
name: "I am supposed to be matched",
description: undefined
}
},
{
itemNumber: "5387007409",
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am also supposed to be matched"
name: "I am also supposed to be matched",
description: "I am also supposed to be matched" // Description is optional and can be undefined
}
}
]
Expand All @@ -108,8 +108,8 @@ const branchHoldings: HoldingsV3[] = [
available: false,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am NOT supposed to be matched"
name: "I am NOT supposed to be matched",
description: undefined
}
}
]
Expand All @@ -125,8 +125,8 @@ const branchHoldings: HoldingsV3[] = [
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched"
name: "I am supposed to be matched",
description: undefined
}
}
]
Expand All @@ -142,8 +142,8 @@ const branchHoldings: HoldingsV3[] = [
available: true,
periodical: undefined,
materialGroup: {
name: "standard",
description: "I am supposed to be matched"
name: "I am supposed to be matched",
description: undefined
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions src/tests/unit/instant-loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test("getInstantLoanBranchHoldings should return materials grouped by branches f
expect(result[0].branch.title).toBe("Åby");
expect(result[0].materials).toHaveLength(2);
expect(result[0].materials[0].available).toBe(true);
expect(result[0].materials[0].materialGroup.description).toBe(
expect(result[0].materials[0].materialGroup.name).toBe(
"I am supposed to be matched"
);

Expand All @@ -39,7 +39,7 @@ test("getInstantLoanBranchHoldings should return materials grouped by branches f
expect(result[1].branch.title).toBe("Sabro");
expect(result[1].materials).toHaveLength(1);
expect(result[1].materials[0].available).toBe(true);
expect(result[1].materials[0].materialGroup.description).toBe(
expect(result[1].materials[0].materialGroup.name).toBe(
"I am supposed to be matched"
);

Expand All @@ -50,11 +50,11 @@ test("getInstantLoanBranchHoldings should return materials grouped by branches f
expect(result[2].branch.title).toBe("Hasle");
expect(result[2].materials).toHaveLength(2);
expect(result[2].materials[0].available).toBe(true);
expect(result[2].materials[0].materialGroup.description).toBe(
expect(result[2].materials[0].materialGroup.name).toBe(
"I am supposed to be matched"
);
expect(result[2].materials[1].available).toBe(true);
expect(result[2].materials[1].materialGroup.description).toBe(
expect(result[2].materials[1].materialGroup.name).toBe(
"I am also supposed to be matched"
);
});
Expand Down

0 comments on commit 427cb57

Please sign in to comment.