defmodule SimpleshopTheme.WebhooksTest do use SimpleshopTheme.DataCase alias SimpleshopTheme.Webhooks import SimpleshopTheme.ProductsFixtures setup do conn = provider_connection_fixture(%{provider_type: "printify"}) {:ok, provider_connection: conn} end describe "handle_printify_event/2" do test "product:updated triggers sync", %{provider_connection: _conn} do # With inline Oban, the job executes immediately (and fails due to no real API key) # But the handler should still return {:ok, _} after inserting the job result = Webhooks.handle_printify_event( "product:updated", %{"id" => "123", "shop_id" => "456"} ) assert {:ok, %Oban.Job{}} = result end test "product:publish:started triggers sync", %{provider_connection: _conn} do result = Webhooks.handle_printify_event( "product:publish:started", %{"id" => "123"} ) assert {:ok, %Oban.Job{}} = result end test "product:deleted triggers delete", %{provider_connection: _conn} do result = Webhooks.handle_printify_event( "product:deleted", %{"id" => "123"} ) assert {:ok, %Oban.Job{}} = result end test "shop:disconnected returns ok" do assert :ok = Webhooks.handle_printify_event("shop:disconnected", %{}) end test "unknown event returns ok" do assert :ok = Webhooks.handle_printify_event("unknown:event", %{}) end test "returns error when no provider connection" do # Delete all connections first SimpleshopTheme.Repo.delete_all(SimpleshopTheme.Products.ProviderConnection) assert {:error, :no_connection} = Webhooks.handle_printify_event( "product:updated", %{"id" => "123"} ) end end end