Skip to content
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(payment): Make payment catalog mockable eliminating reliance on fjs #16471

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

norda-gunni
Copy link
Contributor

@norda-gunni norda-gunni commented Oct 18, 2024

...

Attach a link to issue if relevant

What

Mock catalogAPI

Why

When fjs is down paymentcatalog is not available

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new mock payment catalog API for enhanced testing flexibility.
    • Added support for mock payment functionality in various forms and templates.
  • Bug Fixes

    • Removed deprecated enableMockPayment properties from configurations to streamline payment handling.
  • Documentation

    • Updated README to include instructions for configuring mock payments and utilizing new APIs.
  • Refactor

    • Enhanced state management in components to improve user interactions related to mock payments.

@norda-gunni norda-gunni requested review from a team as code owners October 18, 2024 13:48
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request enhances the payment functionality by introducing a new method, mockPaymentCatalog, in the PaymentService class, which provides a mock payment catalog item. The existing paymentCatalog method is modified to utilize this mock data based on the enableMockPayment flag. Additionally, various components and templates are updated to incorporate new mockable APIs, replacing existing ones. The README.md documentation is also revised to include instructions for using these new features and configurations.

Changes

File Change Summary
libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts Added mockPaymentCatalog method; modified paymentCatalog to return mock data based on enableMockPayment.
libs/application/templates/example-payment/mock-data/fjs-closed.json Added new JSON file for mock payment data structure.
libs/application/templates/example-payment/src/forms/draft.ts Added MockablePaymentCatalogApi; removed PaymentCatalogApi; removed enableMockPayment.
libs/application/templates/example-payment/src/lib/examplePaymentTemplate.ts Added MockablePaymentCatalogApi to States.DRAFT configuration.
libs/application/ui-shell/src/components/FormExternalDataProvider.tsx Introduced shouldUseMockPayment and hasApproved state variables; updated method signature to remove enableMockPayment.
libs/application/ui-shell/src/components/Screen.tsx Updated to utilize new state management for mock payments.

Possibly related PRs

Suggested reviewers

  • jonnigs
  • baering
  • HjorturJ

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 7

🧹 Outside diff range and nitpick comments (21)
libs/application/types/src/lib/template-api/shared-api/shared-api-definitions/payment-catalog.ts (1)

18-27: LGTM: Addition of MockablePaymentCatalogApi

The new MockablePaymentCatalogApi directly addresses the PR objective of making the payment catalog mockable. It effectively reuses the PaymentCatalogParameters interface and defineTemplateApi function, promoting code reuse and consistency.

The default true value for enableMockPayment ensures mock behavior by default, which is appropriate for this API. The new action and externalDataId clearly differentiate this API from the regular one.

Consider adding a brief comment above the MockablePaymentCatalogApi definition to explain its purpose and how it differs from the regular PaymentCatalogApi. This would enhance code readability and maintainability.

libs/application/templates/driving-license/src/dataProviders/index.ts (1)

25-31: LGTM: Addition of MockableSyslumadurPaymentCatalogApi

The new export constant MockableSyslumadurPaymentCatalogApi aligns well with the coding guidelines and PR objectives. It promotes reusability and adheres to TypeScript usage. The implementation is consistent with the existing SyslumadurPaymentCatalogApi, which is good for maintainability.

For improved consistency, consider adding a comment explaining the purpose of this mockable API, similar to how you might document the non-mockable version.

libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/dataProviders/index.ts (1)

17-23: LGTM: New mockable API export is well-implemented.

The addition of MockableSamgongustofaPaymentCatalogApi successfully addresses the PR objective of making the payment catalog mockable. The configuration is consistent with the existing SamgongustofaPaymentCatalogApi, which is good for maintaining code consistency and reusability across different NextJS apps.

For even better code consistency, consider using object shorthand notation for the organizationId in the params object:

export const MockableSamgongustofaPaymentCatalogApi =
  MockablePaymentCatalogApi.configure({
    params: {
      organizationId: InstitutionNationalIds.SAMGONGUSTOFA,
    },
    externalDataId: 'payment',
  })

This minor change would make it identical to the SamgongustofaPaymentCatalogApi configuration style.

libs/application/templates/marriage-conditions/src/dataProviders/index.ts (1)

31-37: LGTM: New mockable API enhances testing capabilities

The addition of MockableDistrictCommissionersPaymentCatalogApi successfully implements the PR's objective of making the payment catalog mockable. It maintains consistency with the existing non-mockable version and adheres to TypeScript usage guidelines.

Consider extracting the common configuration options into a separate constant to reduce code duplication:

const districtCommissionersConfig = {
  params: {
    organizationId: InstitutionNationalIds.SYSLUMENN,
  },
  externalDataId: 'paymentDistrictCommissioners',
};

export const DistrictCommissionersPaymentCatalogApi =
  PaymentCatalogApi.configure(districtCommissionersConfig);

export const MockableDistrictCommissionersPaymentCatalogApi =
  MockablePaymentCatalogApi.configure(districtCommissionersConfig);

This approach would improve maintainability and reduce the risk of inconsistencies between the two APIs.

libs/application/templates/marriage-conditions/src/forms/sharedSections/dataCollection.ts (1)

38-38: LGTM: Provider updated to use mockable API

The update to use MockableDistrictCommissionersPaymentCatalogApi as the provider aligns with the PR objective and corresponds to the import statement change. This modification supports the goal of making the payment catalog mockable.

Consider adding a comment explaining why this specific API is made mockable, to improve code clarity for future developers:

 buildDataProviderItem({
+  // Use mockable API to eliminate reliance on fjs service
   provider: MockableDistrictCommissionersPaymentCatalogApi,
   title: '',
   subTitle: '',
 }),
libs/application/templates/id-card/src/dataProviders/index.ts (1)

59-65: LGTM: New export for MockableSyslumadurPaymentCatalogApi

The addition of MockableSyslumadurPaymentCatalogApi is well-implemented and aligns with the PR objective. It follows the existing patterns in the file and uses TypeScript effectively.

For consistency, consider using a const assertion:

export const MockableSyslumadurPaymentCatalogApi = MockablePaymentCatalogApi.configure({
  params: {
    organizationId: InstitutionNationalIds.SYSLUMENN,
  },
  externalDataId: 'payment',
}) as const;

This ensures that the configuration object is treated as a readonly constant, which can help prevent accidental modifications and improve type inference.

libs/application/templates/driving-license/src/forms/prerequisites/sectionExternalData.ts (1)

19-21: LGTM! Consider removing unused import.

The addition of MockableSyslumadurPaymentCatalogApi aligns with the PR objective of making the payment catalog mockable. However, since SyslumadurPaymentCatalogApi is no longer used in this file, consider removing it to keep the imports clean.

import {
  GlassesCheckApi,
  MockableSyslumadurPaymentCatalogApi,
- SyslumadurPaymentCatalogApi,
} from '../../dataProviders'
libs/application/templates/example-payment/src/forms/draft.ts (1)

Line range hint 1-89: Adherence to coding guidelines confirmed

The code adheres to the guidelines for the libs directory:

  1. It defines reusable components for NextJS applications.
  2. TypeScript is used for type definitions and exports.
  3. The code structure supports effective tree-shaking and bundling.

For improved type safety, consider explicitly typing the draft constant:

export const draft: Form = buildForm({
  // ... existing configuration
})

This change would make the type more explicit and improve code readability.

libs/application/templates/directorate-of-immigration/citizenship/src/dataProviders/index.ts (1)

22-28: LGTM: New mockable API export addresses PR objectives

The addition of MockableUtlendingastofnunPaymentCatalogApi successfully implements a mockable version of the payment catalog API, aligning with the PR's main objective. It maintains consistency with the existing code structure and adheres to the coding guidelines for the libs directory by promoting reusability, using TypeScript, and supporting effective tree-shaking.

For improved clarity and maintainability, consider adding a brief comment explaining the purpose of this mockable API and when it should be used.

+// Mockable version of UtlendingastofnunPaymentCatalogApi for testing and development
 export const MockableUtlendingastofnunPaymentCatalogApi =
   MockablePaymentCatalogApi.configure({
     params: {
       organizationId: InstitutionNationalIds.UTLENDINGASTOFNUN,
     },
     externalDataId: 'payment',
   })
libs/application/templates/example-payment/src/lib/examplePaymentTemplate.ts (1)

72-72: LGTM: API array updated to include mockable version

The addition of MockablePaymentCatalogApi to the api array in the States.DRAFT configuration aligns well with the PR's objective. This change enhances flexibility in payment handling during testing while maintaining backwards compatibility.

Consider adding a brief comment explaining the order of APIs in the array for future maintainers:

api: [
  MockablePaymentCatalogApi, // Mock API for testing
  PaymentCatalogApi, // Original API for production use
],
libs/application/templates/example-payment/mock-data/fjs-closed.json (3)

1-9: LGTM! Consider adding a comment for clarity.

The basic configuration looks good. The UUID, name, and other properties are well-defined for a mock server setup.

Consider adding a comment at the top of the file to explain the purpose of this mock data, especially regarding the empty hostname and endpointPrefix, and the choice of port 8081. This would enhance readability and maintainability.


10-89: LGTM! Consider adding more mock scenarios.

The route configuration is well-structured and correctly simulates a scenario where the payment system is closed. The error response and headers are appropriately set.

To improve the mock's versatility, consider adding more routes or responses to simulate different scenarios (e.g., successful payments, other error types). This would enhance the mock's usefulness for testing various conditions.


127-141: LGTM! Consider removing empty structures if unused.

The final configuration segment is correctly structured. The empty proxy headers, data, and callbacks arrays allow for future expansion.

If these empty structures (proxyReqHeaders, proxyResHeaders, data, callbacks) are not planned to be used in the near future, consider removing them to keep the configuration concise. Alternatively, add a comment explaining their purpose for future use.

libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (2)

37-59: Approve changes with a suggestion for improvement.

The modifications to the paymentCatalog method effectively implement mock payment capabilities, enhancing the reusability and testability of the component. The use of TypeScript for return type definition is commendable.

However, consider making the mock payment item more flexible:

Consider extracting the mock payment item to a configurable constant or a separate method. This would allow for easier customization of mock data in different testing scenarios. For example:

private getMockPaymentItem(params: PaymentCatalogParameters): PaymentCatalogItem {
  return {
    performingOrgID: params?.organizationId ?? 'mock-org-id',
    chargeType: 'mock-charge-type',
    chargeItemCode: 'MockPayment',
    chargeItemName: 'Mock Payment Item',
    priceAmount: 100000, // Adjust as needed
  };
}

Then use it in the paymentCatalog method:

if (enableMockPayment.data) {
  return [this.getMockPaymentItem(params)];
}

This approach would improve the flexibility and maintainability of the mock data.


62-76: Approve new method with suggestion for refactoring.

The addition of the mockPaymentCatalog method enhances the testability of the component, which is great. The use of TypeScript for parameter and return types is correct and follows the guidelines.

However, there's duplication between this method and the mock logic in paymentCatalog.

To improve code maintainability and adhere to the DRY principle, consider refactoring the mock payment item creation into a shared private method. This method could then be used by both paymentCatalog and mockPaymentCatalog. For example:

private createMockPaymentItem(params?: PaymentCatalogParameters): PaymentCatalogItem {
  return {
    performingOrgID: params?.organizationId ?? 'string',
    chargeType: 'string',
    chargeItemCode: 'Payment',
    chargeItemName: 'Mock',
    priceAmount: 123123,
  };
}

Then update both methods to use this shared logic:

async mockPaymentCatalog({ params }: TemplateApiModuleActionProps<PaymentCatalogParameters>): Promise<PaymentCatalogItem[]> {
  return [this.createMockPaymentItem(params)];
}

// In paymentCatalog method:
if (enableMockPayment.data) {
  return [this.createMockPaymentItem(params)];
}

This refactoring will centralize the mock item creation, making it easier to maintain and update in the future.

libs/application/types/src/lib/Form.ts (1)

140-140: LGTM! Consider adding a comment for clarity.

The addition of enableMockPayment?: boolean to the ExternalDataProvider interface aligns well with the PR objectives of making the payment catalog mockable. This change enhances the flexibility of the payment system during testing.

The modification adheres to the coding guidelines for the libs directory:

  1. It maintains the reusability of the interface across different NextJS apps.
  2. It uses TypeScript for defining the property type.
  3. The optional nature of the property (?) allows for effective tree-shaking.

Consider adding a brief comment to explain the purpose of this property for better maintainability. For example:

/** Enables mock payment functionality for testing purposes */
enableMockPayment?: boolean

This addition would improve code readability and make the intent clearer for other developers.

libs/application/templates/passport/src/forms/Draft.ts (1)

62-64: LGTM: Mockable payment catalog implementation looks good.

The replacement of SyslumadurPaymentCatalogApi with MockablePaymentCatalogApi.configure({ externalDataId: 'payment' }) successfully implements the mockable payment catalog. This change enhances the reusability of the component across different NextJS apps, aligning with our coding guidelines.

Consider adding a brief comment explaining the purpose of the 'payment' externalDataId for better code clarity:

 provider: MockablePaymentCatalogApi.configure({
   externalDataId: 'payment',
+  // 'payment' externalDataId is used to identify this specific catalog in the mocking system
 }),
libs/application/templates/marriage-conditions/src/lib/MarriageConditionsTemplate.ts (2)

94-94: LGTM: API declaration updated for APPLICANT role

The addition of MockableDistrictCommissionersPaymentCatalogApi to the api array for the APPLICANT role is consistent with the PR objectives and enhances the component's flexibility for testing and development.

Consider adding a comment explaining the purpose of using the mockable API to improve code readability:

api: [
  // ... other APIs
  MockableDistrictCommissionersPaymentCatalogApi, // Allows mocking of payment catalog for testing
],

161-161: LGTM: API declaration updated for ASSIGNED_SPOUSE role

The addition of MockableDistrictCommissionersPaymentCatalogApi to the api array for the ASSIGNED_SPOUSE role is consistent with the PR objectives and maintains consistency across different roles in the template.

For consistency with the previous suggestion, consider adding a similar comment here:

api: [
  // ... other APIs
  MockableDistrictCommissionersPaymentCatalogApi, // Allows mocking of payment catalog for testing
],
libs/application/templates/passport/src/lib/PassportTemplate.ts (1)

111-113: LGTM: MockablePaymentCatalogApi integrated correctly

The integration of MockablePaymentCatalogApi is done correctly and follows the existing pattern for API configuration in the template. This change aligns with the PR objective of making the payment catalog mockable, enhancing the flexibility of the application.

The use of the configure method with externalDataId promotes type-safety, which is excellent for TypeScript usage. The localized nature of this change maintains the overall structure and reusability of the template.

Consider adding a brief comment explaining the purpose of this mockable API for better code clarity:

MockablePaymentCatalogApi.configure({
  externalDataId: 'payment',
}), // Allows mocking of payment catalog for testing and development
libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (1)

152-152: LGTM: API configuration updated for mockable payment catalog

The addition of MockableSyslumadurPaymentCatalogApi to the api array in the PREREQUISITES state configuration is consistent with the import changes and aligns with the PR objective. This modification enhances the template's flexibility for testing scenarios.

The change maintains the existing TypeScript usage for defining props and exporting types, adhering to the coding guidelines for libs/**/* files.

For consistency, consider moving the MockableSyslumadurPaymentCatalogApi to be grouped with other payment-related APIs in the array, if any exist.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7267ce3 and 7f36afc.

📒 Files selected for processing (26)
  • libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (2 hunks)
  • libs/application/templates/directorate-of-immigration/citizenship/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/directorate-of-immigration/citizenship/src/forms/Prerequisites/index.ts (2 hunks)
  • libs/application/templates/directorate-of-immigration/citizenship/src/lib/CitizenshipTemplate.ts (2 hunks)
  • libs/application/templates/driving-license/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/driving-license/src/forms/prerequisites/sectionExternalData.ts (2 hunks)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
  • libs/application/templates/example-payment/mock-data/fjs-closed.json (1 hunks)
  • libs/application/templates/example-payment/src/forms/draft.ts (2 hunks)
  • libs/application/templates/example-payment/src/lib/examplePaymentTemplate.ts (2 hunks)
  • libs/application/templates/id-card/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/id-card/src/forms/Prerequisites/index.ts (2 hunks)
  • libs/application/templates/id-card/src/lib/IdCardTemplate.ts (2 hunks)
  • libs/application/templates/marriage-conditions/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/marriage-conditions/src/forms/application.ts (0 hunks)
  • libs/application/templates/marriage-conditions/src/forms/sharedSections/dataCollection.ts (2 hunks)
  • libs/application/templates/marriage-conditions/src/lib/MarriageConditionsTemplate.ts (3 hunks)
  • libs/application/templates/passport/src/forms/Draft.ts (2 hunks)
  • libs/application/templates/passport/src/lib/PassportTemplate.ts (2 hunks)
  • libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/forms/TransferOfVehicleOwnershipForm/prerequisitesSection.ts (2 hunks)
  • libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/TransferOfVehicleOwnershipTemplate.ts (2 hunks)
  • libs/application/types/src/lib/Form.ts (1 hunks)
  • libs/application/types/src/lib/template-api/shared-api/shared-api-definitions/payment-catalog.ts (1 hunks)
  • libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (6 hunks)
  • libs/application/ui-shell/src/components/Screen.tsx (0 hunks)
💤 Files with no reviewable changes (2)
  • libs/application/templates/marriage-conditions/src/forms/application.ts
  • libs/application/ui-shell/src/components/Screen.tsx
🧰 Additional context used
📓 Path-based instructions (24)
libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.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/application/templates/directorate-of-immigration/citizenship/src/dataProviders/index.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/application/templates/directorate-of-immigration/citizenship/src/forms/Prerequisites/index.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/application/templates/directorate-of-immigration/citizenship/src/lib/CitizenshipTemplate.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/application/templates/driving-license/src/dataProviders/index.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/application/templates/driving-license/src/forms/prerequisites/sectionExternalData.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/application/templates/driving-license/src/lib/drivingLicenseTemplate.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/application/templates/example-payment/mock-data/fjs-closed.json (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/application/templates/example-payment/src/forms/draft.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/application/templates/example-payment/src/lib/examplePaymentTemplate.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/application/templates/id-card/src/dataProviders/index.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/application/templates/id-card/src/forms/Prerequisites/index.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/application/templates/id-card/src/lib/IdCardTemplate.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/application/templates/marriage-conditions/src/dataProviders/index.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/application/templates/marriage-conditions/src/forms/sharedSections/dataCollection.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/application/templates/marriage-conditions/src/lib/MarriageConditionsTemplate.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/application/templates/passport/src/forms/Draft.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/application/templates/passport/src/lib/PassportTemplate.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/application/templates/transport-authority/transfer-of-vehicle-ownership/src/dataProviders/index.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/application/templates/transport-authority/transfer-of-vehicle-ownership/src/forms/TransferOfVehicleOwnershipForm/prerequisitesSection.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/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/TransferOfVehicleOwnershipTemplate.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/application/types/src/lib/Form.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/application/types/src/lib/template-api/shared-api/shared-api-definitions/payment-catalog.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/application/ui-shell/src/components/FormExternalDataProvider.tsx (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 (49)
libs/application/types/src/lib/template-api/shared-api/shared-api-definitions/payment-catalog.ts (3)

6-6: LGTM: Addition of enableMockPayment property

The new enableMockPayment property in the PaymentCatalogParameters interface aligns well with the PR objective of making the payment catalog mockable. This change enhances the flexibility of the payment system and adheres to the coding guidelines by using TypeScript for defining the interface.


14-14: LGTM: Consistent update to PaymentCatalogApi

The addition of enableMockPayment: false to the params object in PaymentCatalogApi is consistent with the interface update. Setting the default value to false maintains backwards compatibility while allowing for mock payments when explicitly enabled.


Line range hint 1-27: Overall assessment: Excellent changes

The modifications to this file align perfectly with the PR objectives and adhere to the coding guidelines for the libs directory. The changes enhance the reusability and flexibility of the payment system by introducing mock payment capabilities.

Key points:

  1. TypeScript is used effectively for defining props and exporting types.
  2. The new MockablePaymentCatalogApi and the updates to PaymentCatalogParameters promote reusability across different NextJS apps.
  3. The changes support effective tree-shaking and bundling practices by clearly separating the mock API from the regular one.

Great job on implementing these changes!

libs/application/templates/driving-license/src/dataProviders/index.ts (2)

4-4: LGTM: Import of MockablePaymentCatalogApi

The addition of MockablePaymentCatalogApi import aligns with the coding guidelines for libs/**/* files. It supports TypeScript usage and promotes reusability across different NextJS apps by importing from a shared module.


Line range hint 1-32: Adherence to coding guidelines for libs//* files**

The changes in this file adhere well to the coding guidelines:

  1. Reusability: The file exports both mockable and non-mockable versions of the API, promoting reuse across different NextJS apps.
  2. TypeScript usage: Proper use of TypeScript for importing and exporting types is evident.
  3. Tree-shaking and bundling: While not directly addressed, the modular nature of the exports supports effective tree-shaking and bundling practices.

Overall, the changes maintain the quality standards expected for files in the libs directory.

libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/dataProviders/index.ts (2)

Line range hint 1-6: LGTM: Import statement addition is appropriate.

The addition of MockablePaymentCatalogApi to the import statement is in line with the PR objective of making the payment catalog mockable. This import adheres to the TypeScript usage guidelines for the libs directory.


Line range hint 1-24: Coding guidelines for libs/**/* are followed.

The changes in this file adhere to the coding guidelines for the libs directory:

  1. Reusability: The new mockable API enhances reusability across different NextJS apps.
  2. TypeScript usage: Proper TypeScript practices are followed in defining and exporting types.
  3. Tree-shaking and bundling: The changes don't negatively impact these practices.

Great job on maintaining code quality and following the established guidelines!

libs/application/templates/marriage-conditions/src/dataProviders/index.ts (2)

3-3: LGTM: New import aligns with PR objectives

The addition of MockablePaymentCatalogApi to the import statement is appropriate and aligns with the PR's goal of making the payment catalog mockable. This named import also maintains good tree-shaking practices.


Line range hint 1-37: Overall compliance with coding guidelines

The changes in this file adhere to the specified coding guidelines for the libs directory:

  1. The new export enhances reusability across different NextJS apps.
  2. TypeScript is used effectively for defining and exporting types.
  3. The changes maintain good tree-shaking and bundling practices.

Great job on maintaining code quality and consistency!

libs/application/templates/marriage-conditions/src/forms/sharedSections/dataCollection.ts (3)

8-8: LGTM: Import statement updated correctly

The import of MockableDistrictCommissionersPaymentCatalogApi aligns with the PR objective of making the payment catalog mockable. The naming convention is consistent with the existing code style.


Line range hint 1-41: Adherence to coding guidelines for libs/**/* files

The changes in this file comply with the coding guidelines for the libs directory:

  1. They don't negatively impact the reusability of components and hooks across different NextJS apps.
  2. While not directly related to TypeScript usage for defining props and exporting types, the changes maintain the existing TypeScript structure.
  3. The modifications don't affect tree-shaking or bundling practices.

Line range hint 1-41: Summary: Successful implementation of mockable payment catalog

The changes in this file successfully implement the use of a mockable DistrictCommissionersPaymentCatalogApi, aligning with the PR objective of eliminating reliance on fjs. The modifications are minimal, focused, and maintain the existing code structure and style. These changes contribute to enhancing the reliability of the payment system by allowing it to function even when the fjs service is down.

libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/forms/TransferOfVehicleOwnershipForm/prerequisitesSection.ts (2)

12-12: LGTM: Import change aligns with PR objectives

The change from SamhgongustofaPaymentCatalogApi to MockableSamgongustofaPaymentCatalogApi aligns well with the PR objective of making the payment catalog mockable. This modification enhances the flexibility of the code, allowing for easier testing and reducing reliance on the fjs service.


Line range hint 1-52: Overall assessment: Changes align with guidelines and PR objectives

The modifications in this file adhere to the coding guidelines for the libs directory:

  1. They improve reusability by introducing a mockable API for the payment catalog.
  2. TypeScript is used consistently throughout the file.
  3. The changes should support effective tree-shaking and bundling practices.

These changes align well with the PR objective of eliminating reliance on fjs for the payment catalog, enhancing the reliability of the payment system. The introduction of the mockable API allows for more flexible testing scenarios, which is particularly valuable for a critical component like the payment system.

libs/application/templates/id-card/src/dataProviders/index.ts (2)

7-7: LGTM: Import statement for MockablePaymentCatalogApi

The addition of the MockablePaymentCatalogApi import is correct and aligns with the existing import structure. This import supports the PR objective of making the payment catalog mockable.


Line range hint 1-66: Overall assessment: Changes align with guidelines and PR objectives

The modifications to this file adhere well to the coding guidelines for the libs directory:

  1. Reusability: The new MockableSyslumadurPaymentCatalogApi enhances reusability across different NextJS apps, particularly for testing scenarios.
  2. TypeScript usage: Proper TypeScript practices are maintained, with types being correctly inferred.
  3. Tree-shaking and bundling: The use of named exports supports effective tree-shaking.

These changes successfully address the PR objective of making the payment catalog mockable while maintaining the existing functionality. The implementation is consistent with the file's overall structure and follows best practices for reusable components in the application template.

libs/application/templates/driving-license/src/forms/prerequisites/sectionExternalData.ts (1)

Line range hint 1-79: Overall assessment: Changes comply with coding guidelines

The modifications in this file adhere to the coding guidelines:

  1. The component remains reusable across different NextJS apps.
  2. TypeScript is consistently used for defining props and exporting types.
  3. The changes don't negatively impact tree-shaking or bundling practices.

The introduction of MockableSyslumadurPaymentCatalogApi enhances the flexibility of the payment system while maintaining the overall structure and exportability of the module.

libs/application/templates/example-payment/src/forms/draft.ts (2)

10-15: LGTM: Import changes align with PR objectives

The replacement of PaymentCatalogApi with MockablePaymentCatalogApi in the imports is consistent with the PR's goal of making the payment catalog mockable. This change should enhance the system's reliability when the fjs service is unavailable.


37-37: Verify the removal of enableMockPayment property

The change from PaymentCatalogApi to MockablePaymentCatalogApi in the data provider configuration is consistent with the PR objectives. However, could you please clarify why the enableMockPayment property has been removed from the buildExternalDataProvider configuration? How will mock payments be enabled when necessary?

libs/application/templates/directorate-of-immigration/citizenship/src/dataProviders/index.ts (2)

3-3: LGTM: New import aligns with PR objectives

The addition of MockablePaymentCatalogApi import is consistent with the existing code style and supports the PR's goal of making the payment catalog mockable. It also adheres to the coding guidelines for the libs directory by promoting reusability and using TypeScript for type definitions.


Line range hint 1-28: Overall assessment: Changes successfully implement PR objectives

The modifications to this file effectively address the PR's main goal of making the payment catalog mockable, which will help eliminate reliance on the fjs service. The changes adhere to the coding guidelines for the libs directory by:

  1. Promoting reusability of components across different NextJS apps
  2. Utilizing TypeScript for type definitions
  3. Supporting effective tree-shaking through named exports

The new mockable API is implemented consistently with existing patterns, ensuring easy integration and maintenance. These changes provide a solid foundation for enhancing the reliability of the payment system during testing and development.

libs/application/templates/example-payment/src/lib/examplePaymentTemplate.ts (2)

16-16: LGTM: New import aligns with PR objectives

The addition of MockablePaymentCatalogApi import is in line with the PR's goal of making the payment catalog mockable. This change adheres to TypeScript usage guidelines and promotes reusability across different NextJS apps by importing from a shared types module.


Line range hint 1-124: Overall assessment: Changes effectively implement mockable payment catalog

The modifications in this file successfully introduce the ability to mock the payment catalog API while maintaining backwards compatibility. These changes align well with the PR objectives and adhere to the coding guidelines for the libs directory, including:

  1. Enhancing reusability across different NextJS apps
  2. Proper TypeScript usage for importing and using types
  3. Maintaining effective bundling practices by importing from shared modules

The implementation allows for flexible testing scenarios without impacting the production behavior, which is a valuable addition to the payment system's reliability.

libs/application/templates/example-payment/mock-data/fjs-closed.json (3)

90-98: LGTM! Proxy configuration is well-defined.

The root children and proxy configuration are correctly set up. The use of different ports for the mock server and proxy is a good practice, allowing for flexible testing scenarios.


99-126: LGTM! Be cautious with CORS in production.

The TLS and CORS configurations are appropriately set for a mock server environment. Disabling TLS and enabling CORS with '*' origin is suitable for testing purposes.

Ensure that these permissive CORS settings are not used in production environments. Consider adding a comment to explicitly state that these settings are for testing purposes only.


1-141: Overall, well-structured mock configuration with room for minor improvements.

This mock configuration file adheres to the coding guidelines for the libs directory and provides a reusable setup for payment testing scenarios. It effectively simulates a closed payment system, which aligns with the PR objective of making the payment catalog mockable.

Key strengths:

  1. Well-defined route and response structure
  2. Appropriate CORS and proxy configurations for testing

Suggestions for improvement:

  1. Add comments to explain the purpose and usage of this mock configuration
  2. Consider expanding the mock scenarios for more comprehensive testing
  3. Review and potentially remove unused empty structures

These improvements would further enhance the file's maintainability and extensibility, making it an even more valuable asset for testing the payment system independently of the fjs service.

libs/application/templates/directorate-of-immigration/citizenship/src/forms/Prerequisites/index.ts (3)

29-29: LGTM: Import of MockableUtlendingastofnunPaymentCatalogApi

The addition of MockableUtlendingastofnunPaymentCatalogApi to the imports is consistent with the PR objective of making the payment catalog mockable. The import follows the existing naming conventions and is correctly placed with other API imports.


Line range hint 1-168: Compliance with coding guidelines for library files

The file adheres to the specified coding guidelines for library files:

  1. Reusability: The form structure defined in this file can potentially be reused across different NextJS apps.
  2. TypeScript usage: The file correctly uses TypeScript for importing types and defining the form structure.
  3. Tree-shaking: The use of named imports and exports supports effective tree-shaking and bundling practices.

Overall, the changes maintain compliance with the coding guidelines for library files.


110-112: LGTM: Usage of MockableUtlendingastofnunPaymentCatalogApi

The replacement of UtlendingastofnunPaymentCatalogApi with MockableUtlendingastofnunPaymentCatalogApi in the dataProviders array is consistent with the PR objective of making the payment catalog mockable. The usage follows the existing pattern for other data providers.

Note: The AI summary mentioned the removal of an enableMockPayment property, but this change is not visible in the provided code. Please confirm if this property removal is still part of the changes or if it has been addressed elsewhere.

To verify the removal of the enableMockPayment property, please run the following script:

✅ Verification successful

Please run the following script to verify the removal of the enableMockPayment property:


Verified: Removal of enableMockPayment Property

The enableMockPayment property is no longer present in the Prerequisites/index.ts file, confirming its removal as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the presence of 'enableMockPayment' in the file

# Test: Search for 'enableMockPayment' in the file
rg --type typescript 'enableMockPayment' libs/application/templates/directorate-of-immigration/citizenship/src/forms/Prerequisites/index.ts

Length of output: 174


Script:

#!/bin/bash
# Description: Check for the presence of 'enableMockPayment' in the specified file

# Test: Search for 'enableMockPayment' in the file without specifying file type
rg 'enableMockPayment' libs/application/templates/directorate-of-immigration/citizenship/src/forms/Prerequisites/index.ts

Length of output: 121

libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (1)

Line range hint 1-76: Overall changes enhance testability and flexibility.

The modifications to the PaymentService successfully introduce mock payment capabilities while preserving existing functionality. These changes align well with the coding guidelines for libs files, enhancing reusability and maintaining proper TypeScript usage.

To ensure the changes don't negatively impact other parts of the system:

Please run the following script to check for any potential breaking changes or inconsistencies:

#!/bin/bash
# Description: Verify the impact of PaymentService changes

# Test 1: Check for any imports of PaymentService that might be affected
echo "Checking imports of PaymentService:"
rg --type typescript "import.*PaymentService" libs/

# Test 2: Look for usages of paymentCatalog method that might need updating
echo "Checking usages of paymentCatalog method:"
rg --type typescript "paymentCatalog\(" libs/

# Test 3: Ensure no direct references to the old logic exist
echo "Checking for any remaining direct references to chargeFjsV2ClientService.getCatalogByPerformingOrg:"
rg --type typescript "chargeFjsV2ClientService\.getCatalogByPerformingOrg" libs/

This script will help identify any areas of the codebase that might need attention due to the changes in PaymentService.

libs/application/templates/directorate-of-immigration/citizenship/src/lib/CitizenshipTemplate.ts (2)

96-96: LGTM: API change aligns with PR objectives

The replacement of UtlendingastofnunPaymentCatalogApi with MockableUtlendingastofnunPaymentCatalogApi directly addresses the main objective of this PR. This change allows for mocking the payment catalog, which will help eliminate reliance on the fjs service and improve the system's resilience when the fjs service is down.

This modification enhances the testability of the application without altering its core functionality, which is a positive improvement.


Line range hint 1-200: LGTM: File structure adheres to coding guidelines

The overall structure of this file adheres well to the coding guidelines for libs/**/* files:

  1. Reusability: The template structure and use of imported components (e.g., buildPaymentState) promote reusability across different NextJS apps.
  2. TypeScript usage: The file makes extensive use of TypeScript for defining props and exporting types, enhancing type safety and developer experience.
  3. Tree-shaking and bundling: The use of dynamic imports for form loaders (e.g., import('../forms/Prerequisites')) supports effective tree-shaking and bundling practices.

These practices contribute to maintaining a high-quality, maintainable codebase.

libs/application/templates/passport/src/forms/Draft.ts (3)

Line range hint 1-200: Summary: Changes align with PR objectives, minor clarifications needed.

Overall, the changes in this file successfully implement the mockable payment catalog, enhancing the reusability and flexibility of the component. The use of MockablePaymentCatalogApi from a shared types package promotes consistency across the project.

To further improve the implementation:

  1. Consider adding a brief comment explaining the purpose of the 'payment' externalDataId.
  2. Provide clarification on how mock payments are now enabled or disabled in the application, given the removal of the enableMockPayment property.

These minor adjustments will enhance code clarity and maintainability.


62-64: Clarify the mechanism for enabling/disabling mock payments.

The enableMockPayment property has been removed from the configuration. Could you please clarify how mock payments are now enabled or disabled in the application? This information would be helpful for maintaining the flexibility of the system and ensuring proper documentation.

Let's check if there's any global configuration for mock payments:

#!/bin/bash
# Description: Search for global mock payment configuration

# Test: Look for any mock payment configuration in the codebase
rg --type typescript "mockPayment|enableMockPayment"

17-17: LGTM: Import changes align with mockable payment catalog objective.

The addition of MockablePaymentCatalogApi and removal of SyslumadurPaymentCatalogApi align well with the PR's objective of making the payment catalog mockable. This change promotes reusability across different NextJS apps as per our coding guidelines.

Let's verify the impact of this change on other parts of the codebase:

Also applies to: 20-20

libs/application/templates/marriage-conditions/src/lib/MarriageConditionsTemplate.ts (2)

28-28: LGTM: Import statement aligns with PR objectives

The addition of MockableDistrictCommissionersPaymentCatalogApi to the import statement aligns well with the PR objective of making the payment catalog mockable. This change enhances the testability of the component, which is crucial for reusable modules in the libs directory.


Line range hint 1-261: Overall assessment: Changes enhance testability and maintain component integrity

The modifications to MarriageConditionsTemplate.ts successfully implement the mockable payment catalog API, aligning with the PR objectives. These changes enhance the testability and flexibility of the component while maintaining its overall structure and design. The updates adhere to the coding guidelines for libs/**/* files, supporting reusability across different NextJS apps and effective TypeScript usage.

To further improve the code:

  1. Consider adding brief comments explaining the purpose of the mockable API in both roles' API arrays.
  2. Ensure that any necessary unit tests are updated or added to cover the new mockable functionality.

Great job on implementing these changes while preserving the component's integrity and enhancing its testability!

libs/application/templates/passport/src/lib/PassportTemplate.ts (2)

16-16: LGTM: Import statement added correctly

The addition of MockablePaymentCatalogApi to the import statement is correct and follows TypeScript conventions. Importing from '@island.is/application/types' promotes reusability across different NextJS apps, which aligns with the coding guidelines for libs/**/* files.


Line range hint 1-324: Summary: Changes align well with PR objectives and coding guidelines

The modifications to PassportTemplate.ts effectively introduce the MockablePaymentCatalogApi, enhancing the mockability of the payment catalog. These changes align well with the PR objectives and adhere to the coding guidelines for libs/**/* files:

  1. Reusability: The changes maintain the template's structure and don't introduce any app-specific logic, preserving its reusability across different NextJS apps.
  2. TypeScript usage: The new API is properly imported and configured using TypeScript, maintaining type safety.
  3. Effective tree-shaking and bundling: The localized nature of the changes doesn't introduce any unnecessary imports or dependencies that might affect tree-shaking.

Overall, this update improves the template's flexibility for testing and development while maintaining its integrity and adherence to best practices.

libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (1)

47-50: LGTM: Import change aligns with PR objective

The replacement of SyslumadurPaymentCatalogApi with MockableSyslumadurPaymentCatalogApi in the import statement aligns well with the PR objective of making the payment catalog mockable. This change supports better testing capabilities without altering the fundamental logic of the application template.

The use of named imports also supports effective tree-shaking, which is in line with the coding guidelines for files in the libs directory.

libs/application/templates/id-card/src/lib/IdCardTemplate.ts (1)

Line range hint 1-338: LGTM! Code adheres to coding guidelines and best practices.

The implementation of IdCardTemplate adheres to the coding guidelines for the libs directory:

  1. It uses TypeScript for defining props and exporting types.
  2. The template structure promotes reusability across different NextJS apps.
  3. The code organization supports effective tree-shaking and bundling practices.

The change to use MockableSyslumadurPaymentCatalogApi is well-integrated and doesn't introduce any apparent issues or inconsistencies.

libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/TransferOfVehicleOwnershipTemplate.ts (3)

32-32: LGTM: Import statement updated to use mockable API

The change from SamhgongustofaPaymentCatalogApi to MockableSamgongustofaPaymentCatalogApi aligns well with the PR objective of making the payment catalog mockable. This modification enhances the flexibility of the payment system, allowing it to function even when the fjs service is down.


Line range hint 1-478: Summary: Successful implementation of mockable payment catalog API

The changes in this file effectively implement the mockable payment catalog API as intended. The modifications are minimal yet impactful, affecting only the import statement and the API array in the DRAFT state. These changes align well with the PR objectives of making the payment catalog mockable and eliminating reliance on the fjs service.

The implementation adheres to the coding guidelines for libs/**/* by maintaining reusability, TypeScript usage, and consistency. The rest of the file remains unchanged, indicating that the modification is self-contained and doesn't require further adjustments to the existing logic.


144-144: LGTM: API array updated to use mockable API

The update to use MockableSamgongustofaPaymentCatalogApi in the API array of the DRAFT state is consistent with the import change and aligns with the PR objectives. This modification ensures that the mockable API is used throughout the application template.

To ensure the change is comprehensive, please run the following command to check if there are any remaining references to the non-mockable API:

libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (5)

212-213: State variables are initialized correctly

The addition of shouldUseMockPayment and hasApproved state variables appropriately manages the component's state related to mock payments and user approval.


245-266: Filtering of data providers based on enableMockPayment is correct

The logic in activateBeforeSubmitCallback correctly filters relevantDataProviders based on the enableMockPayment flag, ensuring that the appropriate data providers are invoked.


299-302: useEffect hook correctly updates the callback

The useEffect hook appropriately calls activateBeforeSubmitCallback whenever hasApproved or shouldUseMockPayment changes, keeping the before submit callback in sync with the component state.


359-359: State update for hasApproved is handled correctly

The onChange handler correctly updates the hasApproved state when the user interacts with the approval checkbox.


399-399: State update for shouldUseMockPayment is handled correctly

The onChange handler correctly updates the shouldUseMockPayment state when the user interacts with the mock payment checkbox.

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

🧹 Outside diff range and nitpick comments (3)
libs/application/template-api-modules/README.md (3)

Line range hint 415-434: LGTM! Clear instructions for enabling payment mocking.

The new section on enabling payment mocking is well-written and provides clear instructions with a relevant code example. This addition aligns perfectly with the PR objective of making the payment catalog mockable.

Consider adding a brief explanation of why payment mocking might be useful in development and local environments. This could help developers understand the purpose and benefits of this feature.


435-469: Great example for template updates!

The code example effectively demonstrates how to update the template to use MockablePaymentCatalogApi. The explanation of the checkbox functionality is clear and helpful for developers implementing this feature.

For consistency, consider using the same code formatting style throughout the document. In this example, the indentation seems to be a mix of spaces and tabs. Standardizing on one (preferably spaces) would improve readability.


Line range hint 1-469: Informative and relevant code examples throughout the document.

The code examples provided in this README are informative, relevant, and effectively illustrate the concepts being explained. They cover a wide range of use cases, which will be very helpful for developers working with template API modules.

To further improve the document:

  1. Ensure consistent formatting across all code examples (e.g., indentation, spacing).
  2. Consider adding comments within the code examples to explain key points or complex logic.
  3. Where applicable, show both the "before" and "after" code to clearly illustrate the changes being made.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7f36afc and 617f5be.

📒 Files selected for processing (1)
  • libs/application/template-api-modules/README.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/template-api-modules/README.md (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 (2)
libs/application/template-api-modules/README.md (2)

Line range hint 1-469: Excellent improvements to the README documentation!

The additions to this README file significantly enhance its value as a comprehensive guide for working with Application Template API Modules. The new sections on data providers, custom ordering, error handling, and shared data providers provide crucial information for developers. The document's structure is logical and easy to follow, making it a valuable resource for the team.

These improvements will greatly assist developers in understanding and implementing template API modules, particularly the new mockable payment functionality.


Line range hint 1-469: Excellent documentation update aligning with PR objectives.

This comprehensive update to the README file not only addresses the primary objective of the PR (making the payment catalog mockable) but also significantly enhances the overall documentation for Application Template API Modules. The new sections on enabling payment mocking and updating templates provide clear instructions that directly support the PR's goal.

The additional improvements to other sections of the document, while not directly related to the PR objective, greatly enhance the overall quality and usefulness of this guide. This will undoubtedly help developers better understand and implement template API modules, including the new mockable payment functionality.

Great job on improving both the specific feature documentation and the general guide!

Copy link
Member

@berglindoma13 berglindoma13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@norda-gunni norda-gunni added the automerge Merge this PR as soon as all checks pass label Oct 18, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented Oct 18, 2024

Datadog Report

All test runs 3071cf7 🔗

21 Total Test Services: 0 Failed, 20 Passed
🔻 Test Sessions change in coverage: 4 decreased, 19 increased, 68 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 7.74s 1 no change Link
api 0 0 0 4 0 2.85s 1 no change Link
application-api-files 0 0 0 12 0 5.8s 1 increased (+0.03%) Link
application-core 0 0 0 92 0 18.6s 1 increased (+0.23%) Link
application-system-api 0 0 0 120 2 2m 57.68s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 19.83s 1 decreased (-0.01%) Link
application-templates-accident-notification 0 0 0 148 0 20.14s 1 increased (+0.06%) Link
application-templates-criminal-record 0 0 0 2 0 10.87s 1 increased (+0.11%) Link
application-templates-driving-license 0 0 0 13 0 15.21s 1 increased (+0.16%) Link
application-templates-example-payment 0 0 0 2 0 10.72s 1 increased (+0.11%) Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • application-templates-parental-leave - jest 35.06% (-0.07%) - Details
  • application-ui-shell - jest 27.94% (-0.06%) - Details
  • application-template-api-modules - jest 30.08% (-0.01%) - Details
  • application-types - jest 5.47% (-0.01%) - Details

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: 1

🧹 Outside diff range and nitpick comments (4)
libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (2)

37-58: LGTM with a minor suggestion for improvement

The changes to the paymentCatalog method effectively implement the mockable payment catalog as per the PR objectives. The code is well-structured and maintains the original functionality when mocking is disabled.

To enhance type safety, consider using a type assertion for the mock data:

return [{
  performingOrgID: params?.organizationId ?? 'string',
  chargeType: 'string',
  chargeItemCode: 'Payment',
  chargeItemName: 'Mock',
  priceAmount: 123123,
}] as PaymentCatalogItem[];

This ensures that the mock data strictly adheres to the PaymentCatalogItem type.


62-76: Approve the new method with suggestions for improvement

The mockPaymentCatalog method is a good addition that enhances the reusability of the mock data generation. However, there are a few suggestions to improve its clarity and potential future extensibility:

  1. Since the method doesn't use its input parameters, consider removing them to avoid confusion:
async mockPaymentCatalog(): Promise<PaymentCatalogItem[]> {
  // ... implementation ...
}
  1. To make the mock data more flexible, consider accepting optional parameters to override default values:
async mockPaymentCatalog(overrides: Partial<PaymentCatalogItem> = {}): Promise<PaymentCatalogItem[]> {
  return [{
    performingOrgID: 'string',
    chargeType: 'string',
    chargeItemCode: 'Payment',
    chargeItemName: 'Mock',
    priceAmount: 123123,
    ...overrides
  }];
}

This approach allows for more versatile mock data generation while maintaining simplicity for the default case.

libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (2)

244-260: LGTM: Improved activateBeforeSubmitCallback with mock payment support.

The function now correctly handles the mock payment scenario by dynamically filtering the relevant data providers. This aligns well with the PR objectives of making the payment catalog mockable.

Consider simplifying the provider filtering logic for better readability:

-        let providers = relevantDataProviders
-        if (enableMockPayment) {
-          providers = relevantDataProviders.filter(
-            (x) => x.action !== 'Payment.paymentCatalog',
-          )
-        } else {
-          providers = relevantDataProviders.filter(
-            (x) => x.action !== 'Payment.mockPaymentCatalog',
-          )
-        }
+        const providers = relevantDataProviders.filter(
+          (x) => enableMockPayment
+            ? x.action !== 'Payment.paymentCatalog'
+            : x.action !== 'Payment.mockPaymentCatalog'
+        )

This change reduces code duplication and makes the logic more concise.


Line range hint 1-413: Overall: Excellent implementation of mockable payment catalog.

The changes in this file effectively implement the mockable payment catalog as per the PR objectives. The new state variables and logic additions support this feature while maintaining consistency with the existing codebase. The implementation adheres to React best practices and the coding guidelines for the libs directory.

Key improvements:

  1. Introduction of shouldUseMockPayment and hasApproved state variables.
  2. Updated activateBeforeSubmitCallback to handle mock payments.
  3. New useEffect hook to manage callback activation.
  4. Updated Checkbox components to use new state setters.

These changes enhance the reliability of the payment system by allowing it to function even when the fjs service is down, which aligns perfectly with the PR objectives.

To further improve the component's reusability across different NextJS apps, consider extracting the mock payment logic into a custom hook. This would enhance modularity and make it easier to use this functionality in other components if needed.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 617f5be and 66a1a8b.

📒 Files selected for processing (3)
  • libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (1 hunks)
  • libs/application/templates/example-payment/mock-data/fjs-closed.json (1 hunks)
  • libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/application/templates/example-payment/mock-data/fjs-closed.json
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.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/application/ui-shell/src/components/FormExternalDataProvider.tsx (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 (4)
libs/application/template-api-modules/src/lib/modules/shared/api/payment/payment.service.ts (1)

Line range hint 1-1: Past issue resolved: Unused import removed

The previously flagged issue regarding the unused getValueViaPath import has been addressed. The import is no longer present in the file, which helps maintain a clean and efficient codebase.

libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (3)

212-213: LGTM: New state variables for mock payment and approval.

The introduction of shouldUseMockPayment and hasApproved state variables improves the component's ability to manage mock payment and user approval states. The naming is clear and follows React conventions.


235-237: Great job implementing the previous suggestion!

The use of some() instead of findIndex() for checking the presence of 'Payment.mockPaymentCatalog' in dataProviders is more appropriate and expresses the intent clearly. This change improves code readability and efficiency.


358-358: LGTM: Updated Checkbox components to use new state setters.

The onChange handlers for both Checkbox components have been correctly updated to use the new setHasApproved and setShouldUseMockPayment state setters. This change aligns well with the new state management approach and maintains consistency between both checkboxes.

Also applies to: 398-398

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 15.78947% with 32 lines in your changes missing coverage. Please review.

Project coverage is 36.73%. Comparing base (d1c22d8) to head (2af1505).
Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
...-shell/src/components/FormExternalDataProvider.tsx 0.00% 18 Missing ⚠️
.../lib/modules/shared/api/payment/payment.service.ts 0.00% 13 Missing ⚠️
...tes/marriage-conditions/src/dataProviders/index.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16471      +/-   ##
==========================================
- Coverage   36.75%   36.73%   -0.02%     
==========================================
  Files        6835     6837       +2     
  Lines      141330   141436     +106     
  Branches    40238    40325      +87     
==========================================
+ Hits        51949    51961      +12     
- Misses      89381    89475      +94     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
application-api-files 56.89% <100.00%> (+0.02%) ⬆️
application-core 71.67% <100.00%> (+0.42%) ⬆️
application-system-api 41.35% <23.52%> (-0.02%) ⬇️
application-template-api-modules 27.85% <7.14%> (-0.01%) ⬇️
application-templates-accident-notification 29.31% <100.00%> (+0.04%) ⬆️
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.42% <100.00%> (+0.08%) ⬆️
application-templates-driving-license 18.44% <100.00%> (+0.11%) ⬆️
application-templates-estate 12.34% <100.00%> (+0.01%) ⬆️
application-templates-example-payment 25.23% <100.00%> (+0.08%) ⬆️
application-templates-financial-aid 15.54% <100.00%> (+0.04%) ⬆️
application-templates-general-petition 23.53% <100.00%> (+0.08%) ⬆️
application-templates-inheritance-report 6.52% <100.00%> (+0.03%) ⬆️
application-templates-marriage-conditions 15.24% <50.00%> (+0.07%) ⬆️
application-templates-mortgage-certificate 43.85% <100.00%> (+0.02%) ⬆️
application-templates-parental-leave 29.85% <100.00%> (-0.11%) ⬇️
application-types 6.62% <0.00%> (-0.02%) ⬇️
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.34% <5.26%> (-0.03%) ⬇️
clients-charge-fjs-v2 24.11% <ø> (ø)
web 1.81% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...immigration/citizenship/src/dataProviders/index.ts 100.00% <100.00%> (ø)
...gration/citizenship/src/lib/CitizenshipTemplate.ts 54.54% <ø> (ø)
...mplates/driving-license/src/dataProviders/index.ts 100.00% <100.00%> (ø)
...nse/src/forms/prerequisites/sectionExternalData.ts 0.00% <ø> (ø)
.../driving-license/src/lib/drivingLicenseTemplate.ts 7.69% <ø> (ø)
...ation/templates/example-payment/src/forms/draft.ts 0.00% <ø> (ø)
.../example-payment/src/lib/examplePaymentTemplate.ts 16.66% <ø> (ø)
...ation/templates/id-card/src/dataProviders/index.ts 100.00% <100.00%> (ø)
...cation/templates/id-card/src/lib/IdCardTemplate.ts 26.78% <ø> (ø)
...lates/marriage-conditions/src/forms/application.ts 0.00% <ø> (ø)
... and 10 more

... and 22 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1c22d8...2af1505. Read the comment docs.

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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 66a1a8b and 2af1505.

📒 Files selected for processing (1)
  • libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (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 (4)
libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (4)

212-213: State initialization is appropriate

The state variables shouldUseMockPayment and hasApproved are correctly initialized.


235-237: Good use of some() for action checking

Using some() to check if dataProviders contains the action Payment.mockPaymentCatalog enhances readability.


359-359: State update on approval is correct

The setHasApproved function correctly updates the state based on user input.


399-399: State update on mock payment preference is correct

The setShouldUseMockPayment function correctly updates the state when the user toggles the mock payment option.

Copy link
Member

@jonnigs jonnigs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@kksteini kksteini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowner files LGTM

@obmagnusson obmagnusson removed the automerge Merge this PR as soon as all checks pass label Oct 21, 2024
Copy link
Member

@obmagnusson obmagnusson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the applications and will only work with the mock. The MockablePaymentCatalog only returns a single mocked object and FJS is never invoked even if the Enable mock payment is not checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants