Integration test: Vipps and BankID client components end-to-end
epic-bankid-vipps-login-api-clients-task-007 — Write integration tests for the Vipps API Client, BankID Provider Client, and Deep Link Handler using test-environment credentials and mock HTTP adapters. Cover the happy path (successful token exchange, userinfo retrieval, assertion validation), error paths (network failure, expired tokens, invalid state parameter, BankID session timeout), and provider routing in the deep link handler. Verify that typed errors propagate correctly to the service layer boundary and that no raw HTTP details leak upward.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
The key goal of these tests is verifying the layer boundaries: typed errors from the client layer must reach the service layer boundary without being wrapped in untyped exceptions. Use a shared AuthTestFixtures class with factory methods for valid and invalid response payloads to keep tests DRY. For the deep link handler tests, inject a Stream
Document the test fixtures clearly — future developers need to understand what each mock response represents. Consider adding a golden file test for the full Vipps auth flow state machine if BLoC is used.
Testing Requirements
Integration tests using flutter_test with ProviderContainer for Riverpod dependency injection. Use mockito or mocktail to mock the HTTP client interface shared by both API clients. Create a MockHttpClient that returns pre-canned response fixtures for each endpoint. Tests should instantiate the full dependency chain (config → client → service boundary) to verify typed error propagation end-to-end.
Separate test groups for: (1) VippsApiClient integration, (2) BankIdProviderClient integration, (3) DeepLinkHandler routing. Use fake_async or a manual test scheduler for BankID session polling tests to avoid real time delays. Run via `flutter test test/integration/auth/` in CI.
Norway has multiple BankID broker providers (e.g., Signicat, Criipto, Nets) with different integration contracts, pricing, and WebView behavior. If the broker is not selected and contractually agreed before implementation begins, the BankIDProviderClient may need to be rewritten after initial build.
Mitigation & Contingency
Mitigation: Define a minimal broker interface abstraction (session initiation, WebView URL generation, assertion validation) before writing any provider-specific code. Confirm broker selection with Norse Digital Products before starting this epic.
Contingency: If the broker changes after implementation, the abstraction layer allows replacing the provider-specific implementation behind the same interface with a targeted rewrite rather than a full redesign.
Android deep link handling with custom URI schemes can conflict with existing app links (HTTPS-based) or fail silently on certain Android versions if the intent filter is misconfigured, causing OAuth callbacks to never reach the app and leaving users stranded on the Vipps or BankID page.
Mitigation & Contingency
Mitigation: Use HTTPS app links (Android App Links) rather than custom URI schemes where possible, as they are more reliable on modern Android. Test deep link receipt on Android 12+ explicitly during development, as this version changed intent flag requirements.
Contingency: Implement a polling fallback for Vipps (check auth status on app foreground) as a secondary callback mechanism if deep link receipt fails on specific Android configurations.
Vipps Login has a separate test environment (mt2.vipps.no) that requires distinct test merchant credentials which must be applied for separately. If test credentials are delayed, integration testing of the VippsApiClient cannot proceed, blocking the entire authentication flow.
Mitigation & Contingency
Mitigation: Apply for Vipps test merchant credentials at the start of the project sprint, not when implementation begins. Use Vipps' publicly documented mock token responses for unit tests to decouple unit testing from live credentials.
Contingency: Implement the VippsApiClient with full mock injection support so all service-layer tests can run against a stub client while waiting for official test credentials.