Skip to content

Conversation

@HauklandJ
Copy link
Contributor

@HauklandJ HauklandJ commented Nov 7, 2025

Description

Repoted issue with the validation of org number on external slack:
https://digdir-samarbeid.slack.com/archives/CCQEQKGJD/p1762502941835949

This was due to a special case handling of the control number for the case where the calculated check number is 11.

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Tests

    • Added expanded test cases for organization number validation, improving test coverage across various formats.
  • Refactor

    • Enhanced the organization number validation algorithm while preserving all existing behavior and functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

📝 Walkthrough

Walkthrough

The changes introduce a helper function refactoring for checksum calculation and expand test coverage. A new mod11 helper is extracted in the validation module with post-processing to convert 11 to 0, while the test file adds positive test cases covering additional 9-digit org number strings without altering existing negative tests.

Changes

Cohort / File(s) Summary
Test Coverage Expansion
src/layout/OrganisationLookup/validation.test.ts
Adds multiple new positive test cases for checkValidOrgnNr with 9-digit org number strings ('974683520', '900010605', '123778847', etc.). Expands valid org number coverage without modifying existing false-case tests.
Helper Function Refactoring
src/layout/OrganisationLookup/validation.ts
Extracts check digit calculation into a new private mod11 helper function. Post-processes result by converting 11 to 0. Maintains identical external behavior of checkValidOrgnNr while reorganizing internal calculation path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that the mod11 helper implementation correctly replicates the original inline calculation logic
  • Confirm that the 11 → 0 post-processing adjustment maintains algorithmic equivalence with the prior behavior
  • Validate that new test case values are legitimate org numbers for the checksum algorithm

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: orgnr validation' clearly and concisely summarizes the main change—fixing organization number validation logic, which aligns with the changeset that corrects check digit calculation handling.
Description check ✅ Passed The PR description follows the required template with all major sections present, though some checkboxes lack confirmation of completion and the Related Issue placeholder remains unfilled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/orgnr-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@HauklandJ HauklandJ added kind/incident-C C incident backport This PR should be cherry-picked onto older release branches labels Nov 7, 2025
@olemartinorg olemartinorg added the kind/bug Something isn't working label Nov 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (3)
src/layout/OrganisationLookup/validation.ts (2)

45-50: Fix correctly handles the mod11 special case.

The refactoring correctly addresses the bug where calculated check digit 11 should be converted to 0. This aligns with the Norwegian organization number validation standard.

One of the new test cases ('974683520') specifically validates this scenario where the weighted sum yields a modulo result requiring the 11→0 conversion.

Optional: Consider adding a brief comment for clarity.

 
 let calculatedCheckDigit = mod11(sum);
 
+// Norwegian org numbers: if check digit calculates to 11, use 0 instead
 if (calculatedCheckDigit === 11) {
   calculatedCheckDigit = 0;
 }

57-58: Helper function is correct and improves maintainability.

The mod11 helper correctly implements the modulo 11 check digit algorithm: 11 - (value % 11).

Optional: Consider placement closer to usage.

While technically correct (the module loads before functions execute), conventional style would place helper functions before their usage or immediately after the function that calls them, rather than after the schema definitions.

src/layout/OrganisationLookup/validation.test.ts (1)

7-39: Consider more descriptive test names to improve maintainability.

All 11 new test cases share the same description "should return true when the orgNr is valid". When a test fails, it will be harder to identify which specific organization number caused the failure.

Consider including the org number in each test description:

-  it('should return true when the orgNr is valid', () => {
+  it('should return true for orgNr 974683520', () => {
     expect(checkValidOrgnNr('974683520')).toBe(true);
   });
-  it('should return true when the orgNr is valid', () => {
+  it('should return true for orgNr 900010605', () => {
     expect(checkValidOrgnNr('900010605')).toBe(true);
   });
   // ... and so on for remaining tests

Alternatively, use a parameterized test approach:

it.each([
  '974683520',
  '900010605',
  '123778847',
  // ... other valid org numbers
])('should return true for valid orgNr %s', (orgNr) => {
  expect(checkValidOrgnNr(orgNr)).toBe(true);
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e81ca65 and dd15f02.

📒 Files selected for processing (2)
  • src/layout/OrganisationLookup/validation.test.ts (1 hunks)
  • src/layout/OrganisationLookup/validation.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Avoid using any and unnecessary type casts (as Type) in TypeScript; prefer precise typings and refactor existing casts/anys
For TanStack Query, use objects to manage query keys and functions, and centralize shared options via queryOptions

Files:

  • src/layout/OrganisationLookup/validation.ts
  • src/layout/OrganisationLookup/validation.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

In tests, use renderWithProviders from src/test/renderWithProviders.tsx to supply required form layout context

Files:

  • src/layout/OrganisationLookup/validation.test.ts
🧬 Code graph analysis (1)
src/layout/OrganisationLookup/validation.test.ts (1)
src/layout/OrganisationLookup/validation.ts (1)
  • checkValidOrgnNr (36-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Type-checks, eslint, unit tests and SonarCloud
  • GitHub Check: Install
  • GitHub Check: Analyze (javascript)

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 7, 2025

@HauklandJ HauklandJ merged commit 7942dc0 into main Nov 7, 2025
16 of 19 checks passed
@HauklandJ HauklandJ deleted the fix/orgnr-validation branch November 7, 2025 09:10
github-actions bot pushed a commit that referenced this pull request Nov 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Automatic backport successful!

A backport PR has been automatically created for the release/v4.22 release branch.

The release branch release/v4.22 already existed and was updated.

The cherry-pick was clean with no conflicts. Please review the backport PR when it appears.

HauklandJ added a commit that referenced this pull request Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working kind/incident-C C incident

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants