Skip to content

feat: implement network connectivity monitor interface and mock service (#26)#28

Open
rohansaini-02 wants to merge 1 commit into
theapprenticeproject:mainfrom
rohansaini-02:feature/connectivity-monitor
Open

feat: implement network connectivity monitor interface and mock service (#26)#28
rohansaini-02 wants to merge 1 commit into
theapprenticeproject:mainfrom
rohansaini-02:feature/connectivity-monitor

Conversation

@rohansaini-02
Copy link
Copy Markdown

Summary

Implementation of a decoupled Connectivity Monitor Utility Proof of Concept (PoC). This module introduces an interface-driven architecture for monitoring network states, ensuring the core application remains agnostic of underlying native network libraries.

Related Issue

Resolves #26

Problem Statement

The TAP Buddy application relies on accurate network state detection for critical features like the Offline Sync Engine and AI Tutor WebSockets. Hardcoding a specific library (like NetInfo) directly into these services creates tight coupling and makes unit testing network transitions (e.g., WiFi to Offline) impossible without a physical device.

Changes Made

  • Isolated Module Creation: Developed the poc-connectivity standalone TypeScript package.
  • INetworkService Interface: Defined a strict contract for network monitoring, including synchronous state retrieval and an observer pattern for changes.
  • MockNetworkService Implementation: Created a robust mock service with helper methods (simulateOffline(), simulateOnline()) for environment simulation.
  • Observer Pattern: Implemented a listener subscription model to notify the application of connectivity changes in real-time.
  • Automated Validation: Integrated a Jest test suite with 100% coverage across statements, branches, and functions.
  • Housekeeping: Added a local .gitignore to keep the module structure clean and free of build artifacts.

Technical Decisions

  • Interface Segregation: Chose an interface-driven approach to allow seamless swapping of the mock implementation with the real @react-native-community/netinfo later without modifying the Sync Engine.
  • Mock-First Development: Prioritized a mockable implementation to unblock the functional validation of the Sync Engine ([PoW] Offline-First Sync Engine: Queue-Based Write Architecture #13) in local development environments.
  • Zero-Dependency Architecture: The core logic is built with pure TypeScript to ensure maximum portability across the project.

Testing Performed

  • 100% Code Coverage: Verified all logic paths using Jest.
  • State Transition Testing: Confirmed isOnline() logic across various simulated states (WiFi, Cellular, None).
  • Listener Validation: Verified that subscribers are correctly notified during state transitions and that the initial state is pushed upon subscription.
  • Cleanup Logic: Confirmed that unsubscribe() correctly removes listeners to prevent memory leaks.

Results

A fully testable connectivity utility that provides the foundation for reliable offline-first syncing.

Checklist

  • Code follows project conventions
  • Tests pass (100% coverage achieved)
  • Documentation updated (README included in PoC)
  • Changes are scoped to one problem

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.

feat: implement network connectivity monitor interface

1 participant