share provider connection logic between setup wizard and providers form

Extract Products.connect_provider/2 that tests the connection, fetches
shop_id, creates the record, and enqueues sync. Both the setup wizard
and the providers form now use this shared function instead of
duplicating the flow. Also makes the products empty state context-aware
(distinguishes "no provider" from "provider connected but no products").

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-03-03 15:19:17 +00:00
parent 5b41f3fedf
commit 0853b6f528
6 changed files with 92 additions and 50 deletions

View File

@@ -125,7 +125,7 @@ defmodule BerrypodWeb.Admin.ProductsTest do
{:ok, _view, html} = live(conn, ~p"/admin/products")
assert html =~ "No products yet"
assert html =~ "Connect a provider"
assert html =~ "providers page"
end
end

View File

@@ -136,6 +136,12 @@ defmodule BerrypodWeb.Admin.ProvidersTest do
describe "form - new" do
setup %{conn: conn, user: user} do
Application.put_env(:berrypod, :provider_modules, %{
"printify" => MockProvider
})
on_exit(fn -> Application.delete_env(:berrypod, :provider_modules) end)
%{conn: log_in_user(conn, user)}
end
@@ -170,6 +176,10 @@ defmodule BerrypodWeb.Admin.ProvidersTest do
end
test "saves new connection", %{conn: conn} do
expect(MockProvider, :test_connection, fn _conn ->
{:ok, %{shop_name: "My Printify Shop", shop_id: 12345}}
end)
{:ok, view, _html} = live(conn, ~p"/admin/providers/new")
{:ok, _view, html} =