Skip to content

Commit

Permalink
fix: unit count
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 13, 2022
1 parent 05278ac commit 0634a08
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const virtualFields = {
serialNumberPattern,
);

return unitCount + 1; // Unit blocks are inclusive bound;
return unitCount;
},
},
};
Expand Down
9 changes: 4 additions & 5 deletions src/utils/data-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ export const assertSumOfSplitUnitsIsValid = (
serialNumberPattern,
splitRecords,
) => {
const sumOfSplitUnits =
splitRecords.reduce(
(previousValue, currentValue) =>
previousValue.unitCount + currentValue.unitCount,
) + 1; // Add one to handle inclusiveness boundry
const sumOfSplitUnits = splitRecords.reduce(
(previousValue, currentValue) =>
previousValue.unitCount + currentValue.unitCount,
); // Add one to handle inclusiveness boundry

const [unitBlockStart, unitBlockEnd, unitCount] = transformSerialNumberBlock(
serialNumberBlock,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const transformSerialNumberBlock = (
return [null, null, null];
}

const blockStart = Number(unitBlocks[1]);
const blockStart = Number(unitBlocks[1]) - 1; // Unit blocks are inclusive bound
const blockEnd = Number(unitBlocks[2]);
return [blockStart, blockEnd, blockEnd - blockStart];
};
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('Unit Resource Integration Tests', function () {
expect(splitRecord1.unitOwner).to.equal(newUnitOwner);
expect(splitRecord2.unitOwner).to.equal(unitRecord.unitOwner);

expect(splitRecord1.unitCount).to.equal(9);
expect(splitRecord1.unitCount).to.equal(10);
expect(splitRecord2.unitCount).to.equal(1);

// Expect the split unitscounts to add up to the original unit count
Expand Down

0 comments on commit 0634a08

Please sign in to comment.