Skip to content

Add testing support - #53

Merged
nirebu merged 11 commits into
mainfrom
nirebu/testing-support
Mar 25, 2026
Merged

nirebu merged 11 commits into
mainfrom
nirebu/testing-support

Conversation

@nirebu

@nirebu nirebu commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #45

This pull request introduces a comprehensive, built-in testing framework for active_shopify_graphql, enabling developers to register and use in-memory test data for models and their associations. It allows all major query patterns (find, where, find_by, includes, and connections) to work transparently in tests without making real API calls. The framework is modular, extensible, and integrates with RSpec or other test setups via simple enable/reset hooks.

nirebu and others added 9 commits March 25, 2026 16:18
Exclude the testing directory and entry point from Zeitwerk autoloading
so it is only activated via explicit `require 'active_shopify_graphql/testing'`.
This keeps the testing module out of production code paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Store holds test records keyed by model class with GID-normalized IDs.
Supports find by ID, hash/string where filtering, and extracting inline
connection data from parent records. Comparison uses .to_s for flexible
ID matching between integers and strings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TestLoader extends Loader and overrides load_attributes,
load_paginated_collection, and load_connection_records to serve data
from the testing Store. Supports eager-loaded and lazy-loaded connections,
nested includes, inverse_of wiring, and cursor-based pagination.
Raises if perform_graphql_query is ever called.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LoaderSwitchableHook overrides default_loader_class to return TestLoader
when testing is enabled (used by Relation#build_loader).
FinderMethodsHook overrides default_loader to return fresh TestLoader
instances (used by Connections for lazy loading), preventing memoization
leaks between tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entry point that wires everything together: requires sub-files,
defines the Testing module with enable!/reset!/register API, and
applies the prepend hooks onto LoaderSwitchable and FinderMethods
at load time. Only activated via explicit require.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Covers: enable!/reset!/enabled? lifecycle, ID normalization, find/where/find_by,
search field filtering (non-attribute keys), eager-loaded and lazy-loaded
connections, pagination, GraphQL query guard, test isolation, and disabled
state fallback to AdminApiLoader.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add setup instructions, data registration examples, and usage patterns
for the new in-memory testing module. Keeps the existing manual mocking
approach as a simpler alternative.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Disable Lint/UnusedMethodArgument inline for sort_key and reverse
params in load_paginated_collection — they must match the parent
class signature but aren't used by the in-memory implementation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nirebu
nirebu force-pushed the nirebu/testing-support branch from 3c67feb to 4d3cc1c Compare March 25, 2026 15:19
@nirebu nirebu self-assigned this Mar 25, 2026
@nirebu
nirebu marked this pull request as ready for review March 25, 2026 15:39
@nirebu
nirebu merged commit 46e912c into main Mar 25, 2026
5 checks passed
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.

Add proper testing harnesses

1 participant