Test the Subscriptions
Learn how to test your API and subscriptions.
We'll cover the following...
Subscriptions testing
Testing your API is important, and subscriptions are no exception. We’ve been using helpers from the PlateSlate.ConnCase
module in our test to ease building HTTP based integration tests. We’ll need a similar PlateSlate.SubscriptionCase
module to manage the subscription integration tests with channels. While the ConnCase
module is generated by Phoenix when we first create the project, we’ll need to make the SubscriptionCase
module ourselves:
Press + to interact
defmodule PlateSlateWeb.SubscriptionCase do@moduledoc """This module defines the test case to be used bysubscription tests"""use ExUnit.CaseTemplateusing doquote do# Import conveniences for testing with channelsuse PlateSlateWeb.ChannelCaseuse Absinthe.Phoenix.SubscriptionTest,schema: PlateSlateWeb.Schemasetup doPlateSlate.Seeds.run(){:ok, socket} =Phoenix.ChannelTest.connect(PlateSlateWeb.UserSocket, %{}){:ok, socket} =Absinthe.Phoenix.SubscriptionTest.join_absinthe(socket){:ok, socket: socket}endimport unquote(__MODULE__), only: [menu_item: 1]endend# handy function for grabbing a fixturedef menu_item(name) doPlateSlate.Repo.get_by!(PlateSlate.Menu.Item, name: name)endend
This module sets up the socket we’ll use ...