This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Recursive do | |
def function do | |
function() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PhxstaticWeb.Router do | |
use PhxstaticWeb, :router | |
pipeline :static do | |
plug Plug.Static, | |
at: "/static", | |
from: {:phxstatic, "priv/test"} | |
end | |
scope "/", PhxstaticWeb do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PhxstaticWeb.Router do | |
use PhxstaticWeb, :router | |
pipeline :static do | |
plug Plug.Static, | |
at: "/static", | |
from: {:phxstatic, "priv/test"} | |
end | |
scope "/", PhxstaticWeb do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it ("shows email not confirmed notification in dashboard for unconfirmed user", () => { | |
cy.factorydb('user', { | |
username: "Sven Gehring", | |
password: "password", | |
email: "[email protected]" | |
}) | |
// This is another custom command we use for getting our auth token | |
cy.login('[email protected]', 'password') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cypress.Commands.add("resetdb", () => { | |
cy.exec('docker-compose run myapp mix do ecto.drop, ecto.create, ecto.migrate') | |
}) | |
Cypress.Commands.add("checkoutdb", () => { | |
cy.request('POST', '/api/end-to-end/db/checkout').as('checkoutDb') | |
}) | |
Cypress.Commands.add("checkindb", () => { | |
cy.request('POST', '/api/end-to-end/db/checkin').as('checkinDb') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before(() => { | |
// Before we run any tests, we reset our database. | |
// We also check back in any open database connection. If you save a | |
// test file, cypress will re-run the tests, not finishing the ones it | |
// is currently running, so we might end up with a checked-out connection | |
// lying around and blocking our database reset. | |
cy.checkindb() | |
cy.resetdb() | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post "/db/factory" do | |
# When piped through a generic Phoenix JSON API pipeline, using a route | |
# like this allows you to call your factory via your test API easily. | |
with {:ok, schema} <- Map.fetch(conn.body_params, "schema"), | |
{:ok, attrs} <- Map.fetch(conn.body_params, "attributes") do | |
db_schema = String.to_atom(schema) | |
db_attrs = Enum.map(attrs, fn {k, v} -> {String.to_atom(k), v} end) | |
db_entry = Factory.insert(db_schema, db_attrs) | |
send_resp(conn, 200, Poison.encode!(%{id: db_entry.id})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post "/db/checkout" do | |
# If the agent is registered and alive, a db connection is checked out already | |
# Otherwise, we spawn the agent and let it(!) check out the db connection | |
owner_process = Process.whereis(:db_owner_agent) | |
if owner_process && Process.alive?(owner_process) do | |
send_resp(conn, 200, "connection has already been checked out") | |
else | |
{:ok, _pid} = Agent.start_link(&checkout_shared_db_conn/0, name: :db_owner_agent) | |
send_resp(conn, 200, "checked out database connection") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp checkout_shared_db_conn do | |
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo, ownership_timeout: :infinity) | |
:ok = Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()}) | |
end | |
defp checkin_shared_db_conn(_) do | |
:ok = Ecto.Adapters.SQL.Sandbox.checkin(Repo) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Plug.TestEndToEnd do | |
use Plug.Router | |
plug :match | |
plug :dispatch | |
match _, do: send_resp(conn, 404, "not found") | |
end |