       assert {:error, :notfound} == AccountController.find(Random.pk())
     end
 
-    test "using email", context do
-      account = context.account
+    test "using email" do
+      account = Factory.insert(:account)
+
       assert {:ok, found} = AccountController.find_by(email: account.email)
       assert account.account_id == found.account_id
     end


    test "fails when username is invalid" do
      error = AccountController.login("}<]=inv@líd+(usêr)-nämẽ", "password")
      assert {:error, :notfound} == error
    end

    test "fails when password doesn't match", context do
      account = context.account
      error = AccountController.login(account.email, "incorrect_password")
      assert {:error, :notfound} == error
    end
  end

  end

  test "account deletion is idempotent" do
    account = Factory.insert(:account)

    assert Repo.get_by(Account, account_id: account.account_id)

    AccountController.delete(account.account_id)
    AccountController.delete(account.account_id)

    refute Repo.get_by(Account, account_id: account.account_id)
  end

  describe "account updating" do
    test "updates its fields" do
      account = Factory.insert(:account)
      p = Factory.params_for(:account)

      params = %{
        email: p.email,
        password: p.password,
        confirmed: true
      }

      assert {:ok, account2} = AccountController.update(account.account_id, params)
      assert params.email == account2.email
      refute account.password == account2.password
      assert params.confirmed == account2.confirmed
    end

    test "email exists" do
      a = Factory.insert(:account)
      params1 = Factory.params_for(:account)
      params2 = %{params1 | email: a.email}

      assert {:ok, account1} = AccountController.create(params1)
      assert {:error, _} = AccountController.update(account1.account_id, params2)
    end

    test "account not found" do
      pk = HELL.TestHelper.Random.pk()

      assert {:error, :notfound} == AccountController.update(pk, %{})
    end
  end

  describe "account login" do
    test "succeeds with correct username/password" do
      account = Factory.insert(:account)
      pass = "!!!foobar1234"

      account
