Skip to content

Conversation

@AnthonyMDev
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for the cache policy conversion functionality added in #859, which maps Apollo's FetchBehavior to URLRequest.CachePolicy.

Changes

  • New test file: GraphQLRequestCachePolicyTests.swift with 18 test cases covering:

    • All 5 standard cache policies (CacheOnly, CacheAndNetwork, CacheFirst, NetworkFirst, NetworkOnly)
    • 4 undefined/edge case FetchBehavior combinations
    • Different operation types (queries, mutations, subscriptions)
    • Cache policy persistence across request modifications
    • URL cache behavior verification
  • Minor API change: Changed FetchBehavior.init from fileprivate to internal to enable testing custom combinations while keeping it internal to the package

Test Coverage

✅ All 18 tests pass successfully

Tests verify that:

  • Each standard FetchBehavior maps to the correct URLRequest.CachePolicy
  • Undefined combinations safely fallback to .reloadIgnoringLocalCacheData
  • Cache policy is correctly set for all operation types
  • Cache policy persists correctly when modifying requests
  • URL cache doesn't interfere with Apollo's cache strategy

Test Results

** TEST SUCCEEDED **

Related to #859

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for apollo-ios-docc canceled.

Name Link
🔨 Latest commit 493ca32
🔍 Latest deploy log https://app.netlify.com/projects/apollo-ios-docc/deploys/695ecfb75091240008452ed2

@apollo-librarian
Copy link

apollo-librarian bot commented Jan 7, 2026

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 190fff59bb9ebee60247c549
Build Logs: View logs

Copy link
Member

@calvincestari calvincestari left a comment

Choose a reason for hiding this comment

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

Looks like there are some duplicate tests, or am I missing the differences?


// MARK: - Ensuring URLCache Doesn't Interfere

func test__cachePolicy__givenCacheOnly__urlShouldNotFetchFromNetwork() throws {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this test the same as test__cachePolicy__givenCacheOnly__shouldReturnCacheDataDontLoad?

Copy link
Member

Choose a reason for hiding this comment

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

The next two tests also appear to be duplicates of test__cachePolicy__givenCacheAndNetwork__shouldReloadIgnoringLocalCache and test__cachePolicy__givenNetworkOnly__shouldReloadIgnoringLocalCache respectively.

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.

3 participants