-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(licenses): pkpass status on machine license #16679
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (4)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseMapper.ts (3)
12-13
: Add type safety and documentation to the compareDates helper.The function logic is correct, but could benefit from additional type safety and documentation.
Consider applying these improvements:
+/** + * Compares two dates and returns the later one + * @param newDate - The date to compare + * @param latestDate - Optional reference date + * @returns The later date between the two + */ -const compareDates = (newDate: Date, latestDate?: Date) => +const compareDates = (newDate: Date | string, latestDate?: Date | string) => { + const newDateTime = new Date(newDate) + const latestDateTime = latestDate ? new Date(latestDate) : undefined + + if (isNaN(newDateTime.getTime())) { + throw new Error('Invalid newDate') + } + if (latestDateTime && isNaN(latestDateTime.getTime())) { + throw new Error('Invalid latestDate') + } + + return !latestDateTime || newDateTime > latestDateTime ? newDateTime : latestDateTime +}
20-30
: Enhance type safety and readability of findLatestExpirationDate.The refactored implementation is cleaner and more maintainable.
Consider these improvements:
-export const findLatestExpirationDate = (license: VinnuvelaDto) => { +export const findLatestExpirationDate = (license: VinnuvelaDto): string | null => { if (!license.vinnuvelaRettindi) { return null } let latestDate: Date | undefined - for (const right of license.vinnuvelaRettindi) { + license.vinnuvelaRettindi.forEach((right) => { if (right.stjorna) { latestDate = compareDates(new Date(right.stjorna), latestDate) } if (right.kenna) { latestDate = compareDates(new Date(right.kenna), latestDate) } - } + }) return latestDate ? latestDate.toISOString() : null }
Line range hint
1-116
: Add explicit return types to exported functions.The code demonstrates good TypeScript practices and reusability. However, some exported functions would benefit from explicit return type annotations.
Add return types to these functions:
-export const parseRightsForPkpassInput = ( +export const parseRightsForPkpassInput = ( rights?: Array<VinnuvelaRettindiDto>, locale?: Locale, -) => { +): string => { -export const createPkPassDataInput = ( +export const createPkPassDataInput = ( license: VinnuvelaDto, nationalId: string, locale?: Locale, -) => { +): Array<{ identifier: string; value: string }> | null => {libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts (1)
49-51
: Add type safety for expiration date.The expirationDate variable lacks type information, which could lead to runtime issues.
- const expirationDate = licenseInfo + const expirationDate: string | null = licenseInfo ? findLatestExpirationDate(licenseInfo) : null
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts
(2 hunks)libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseMapper.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseMapper.ts (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts (1)
49-62
: Verify the impact of updated license validation logic.
The changes to license validation logic might affect other parts of the codebase that rely on this validation.
✅ Verification successful
The search results show that the LicensePkPassAvailability
enum is consistently used across multiple license client services (hunting, firearm, machine, ADR, driving, and disability) with the same pattern of returning Unknown
, NotAvailable
, or Available
based on license validation. The changes in the machine license client follow this same pattern and maintain consistency with other implementations.
Let me verify the specific implementation pattern by searching for the actual validation logic:
License validation changes maintain consistent behavior
The changes to the license validation logic in machineLicenseClient.service.ts
follow the established pattern across all license client services. The findLatestExpirationDate
function is properly scoped to the machine license module and is used consistently within its service. The validation logic maintains the same LicensePkPassAvailability
enum states (Unknown, NotAvailable, Available) as other license client implementations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the usage of LicensePkPassAvailability and potential impacts
# Test 1: Find all usages of LicensePkPassAvailability enum
echo "Checking LicensePkPassAvailability usage:"
rg "LicensePkPassAvailability\." -A 3
# Test 2: Find all implementations of checkLicenseValidityForPkPass
echo -e "\nChecking checkLicenseValidityForPkPass implementations:"
ast-grep --pattern 'checkLicenseValidityForPkPass($_) { $$$ }'
Length of output: 11570
Script:
#!/bin/bash
# Search for license validation implementations
echo "Checking license validation patterns:"
ast-grep --pattern 'checkLicenseValidityForPkPass($_) {
$$$
}'
# Search for findLatestExpirationDate usage
echo -e "\nChecking findLatestExpirationDate usage:"
rg "findLatestExpirationDate" -A 3
Length of output: 3293
...lients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts
Show resolved
Hide resolved
...lients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.service.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good too me, haven't tested yet though 😄 One comment to see if I'm understanding correctly.
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseMapper.ts
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16679 +/- ##
==========================================
- Coverage 36.54% 36.53% -0.01%
==========================================
Files 6890 6890
Lines 143640 143638 -2
Branches 40926 40924 -2
==========================================
- Hits 52488 52479 -9
- Misses 91152 91159 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Affected services are: api,license-api, Deployed services: api,license-api,consultation-portal,web,services-bff-portals-admin. |
Datadog ReportAll test runs ✅ 3 Total Test Services: 0 Failed, 2 Passed Test Services
🔻 Code Coverage Decreases vs Default Branch (1)
|
…achine-license' into fix/pkpass-status-machine-license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts (1)
10-10
: Consider using a more reasonable test date.The test uses a hardcoded date far in the future (2080). While this works, it's better to use a more reasonable date range to prevent the test from becoming outdated or misleading.
-const expectedDate = new Date('2080-01-01T00:00:00Z').toISOString() +const expectedDate = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString() // One year from now
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts
Outdated
Show resolved
Hide resolved
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts
Outdated
Show resolved
Hide resolved
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts (2)
7-13
: Improve test reliability and precision.Two suggestions for improvement:
- Use
toBe
instead oftoMatch
for exact string comparison- Consider using a more maintainable approach for test dates
- expect(result).toMatch(expectedDate) + expect(result).toBe(expectedDate)Consider using a relative date calculation instead of a hardcoded future date:
const futureDate = new Date() futureDate.setFullYear(futureDate.getFullYear() + 1) const expectedDate = futureDate.toISOString()
14-18
: Remove unnecessary async keyword.The test function doesn't contain any asynchronous operations, so the
async
keyword can be removed.- it('should return undefined if no license info', async () => { + it('should return undefined if no license info', () => {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (3)
libs/clients/license-client/src/lib/clients/machine-license-client/machineLicenseClient.spec.ts (3)
5-6
: LGTM! Clear and descriptive test structure.
The describe blocks are well-organized and accurately reflect the test suite's purpose.
20-31
: LGTM! Well-structured test for multiple dates.
The test effectively verifies the handling of multiple expiration dates with clear test data.
33-40
: LGTM! Good error handling coverage.
The test properly verifies the handling of invalid date formats.
…achine-license' into fix/pkpass-status-machine-license
* fix: init * fix: type * fix: date wrangling * fix: tests * fix: build * fix: machine license client tests * fix: remove invalid tests --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
* fix: init * fix: type * fix: date wrangling * fix: tests * fix: build * fix: machine license client tests * fix: remove invalid tests --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
What
Why
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
checkLicenseExpirationDate
function and simplified date handling in thefindLatestExpirationDate
function.