   end
 
   test "account deletion is idempotent" do
-    account = create_account()
+    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 = create_account()
-      params =
-        generate_params()
-        |> Map.drop([:username])
-        |> Map.put(:confirmed, true)
+      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
-      account = create_account()
-      params = generate_params()
-      params2 = Map.put(params, :email, account.email)
+      a = Factory.insert(:account)
+      params1 = Factory.params_for(:account)
+      params2 = %{params1 | email: a.email}
 
-      assert {:ok, account2} = AccountController.create(params)
-      assert {:error, _} = AccountController.update(account2.account_id, params2)
+      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 = create_account()
+      account = Factory.insert(:account)
       pass = "!!!foobar1234"
 
       account


    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


  alias Helix.Account.Factory

  describe "account creation" do
    test "succeeds with proper data" do
      params = Factory.params_for(:account)

      assert {:ok, _} = AccountController.create(params)
    end

    test "fails when email is already in use" do
      account = Factory.insert(:account)
      params = %{Factory.params_for(:account) | email: account.email}

      assert {:error, changeset} = AccountController.create(params)
      assert :email in Keyword.keys(changeset.errors)
    end

    test "fails when username is already in use" do
      account = Factory.insert(:account)
      params = %{Factory.params_for(:account) | username: account.username}

      assert {:error, changeset} = AccountController.create(params)
      assert :username in Keyword.keys(changeset.errors)
    end

    test "fails when password is too short" do
      params = %{Factory.params_for(:account) | password: "123"}

      assert {:error, changeset} = AccountController.create(params)
      assert :password in Keyword.keys(changeset.errors)
