Skip to content

[Tests] Unit and integration tests for Stats Collection #42

@LeGeRyChEeSe

Description

@LeGeRyChEeSe

Description

Set up the test strategy for the Stats Collection module.

Test files to create

  • app/src/test/java/com/vrhub/data/StatsCollectorTest.kt
  • app/src/test/java/com/vrhub/data/ConsentPreferencesTest.kt
  • app/src/androidTest/java/com/vrhub/.../StatsCollectionIntegrationTest.kt

Unit test scenarios (StatsCollector)

  • collectStats does nothing when consent is false (no network call)
  • collectStats sends correct payload when consent is true
  • collectStats includes correct package_name and is_favorite
  • collectStats includes correct tier and timestamp
  • updateConsent calls API with correct value
  • getUserTier returns tier or null on error

Unit test scenarios (ConsentPreferences)

  • consentEnabled emits false by default
  • setConsentEnabled(true) persists and emits true
  • setConsentEnabled(false) persists and emits false

Integration test scenarios

  • Full flow: consent granted → stats sent → worker enqueued
  • Consent revoked → worker cancelled
  • Favorite change → triggers maybeCollectStats()

Required mocks

  • FakeStatsApiService implementing StatsApiService
  • FakeConsentPreferences or in-memory DataStore usage

Reference

  • docs/CLIENT_IMPLEMENTATION.md §10

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions