feat(stripe): make the Stripe API base URL injectable so the REST paths are testable #43
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/DUNITE-11-injectable-api-base"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
DUNITE-11. Every raw-REST call in the crate hardcoded
https://api.stripe.com, and the async-stripe client was built withClient::new, which pins the same host. Nothing could be pointed at a mock server, which is why DUNITE-10 shipped one acceptance criterion short: "a unit test feeds a 403 error envelope to the list path and asserts it errors rather than returning an empty list" was untestable, so the tests coveredstripe_error_envelopein isolation and left the wiring that actually regressed uncovered.Change
StripeService::with_api_base(config, base)is the new constructor.StripeService::new(config)delegates to it with the newSTRIPE_API_BASEconstant, so no consumer changes.StripeConfig. That was the approach flagged as a blocker in DUNITE-10:StripeConfigis built by struct literal in both consumers, so a new field breaks them at compile time, and it would then have to be threaded through each app's env/DB config loader for something only tests ever set. The host a service instance talks to is not part of the app's Stripe configuration.Client::from_urloff the same base, so SDK-backed methods (products, prices, subscriptions, invoices, checkout) reach the mock too, not just the three raw webhook-endpoint calls.reload()preserves the base: a credential save swaps keys, never the host.http://host:9000/andhttp://host:9000behave identically.grep https://api.stripe.comover the crate now returns the constant and nothing else.with_api_basepanics on a base that is not a parseable absolute URL, becauseClient::from_urldoes; that is documented on the method, and failing at construction beats every later call failing opaquely.Testing
just fmt,just check,just lint,just testall clean. 22 tests in the crate now, 10 of them new:more_permissions_requiredmakeslist_webhook_endpointsreturn an error carrying the code, the status and the request id, notOk(vec![]).dataarray, and a 200 with an empty one, so the error test cannot pass by breaking the happy path.create_webhook_endpointreturns the one-time signing secret;delete_webhook_endpointsurfacesresource_missingon a 404.get_invoiceserved from the mock, proving theClient::from_urlhalf of the wiring reaches async-stripe.get_invoicepinning DUNITE-10's fix: only a genuine missing invoice reportsNotFound, a Stripe fault keeps its status.reload()leaving the base alone.No network and no Stripe credentials: wiremock binds localhost.