<commit_before>defmodule Classlab.AssignUserPlugTest do
  alias Classlab.{AssignUserPlug, Session}

  use Classlab.ConnCase

  test "VALID user_id_jwt in session it assigns the correct user", %{conn: conn} do
    user = Factory.insert(:user)
    conn =
      conn
      |> Session.login(user)
      |> AssignUserPlug.call(%{})

    assert conn.assigns[:current_user] == user
  end

  test "INVALID user_id_jwt in session it assigns nil for the user", %{conn: conn} do
    conn = AssignUserPlug.call(conn, %{})
    refute conn.assigns[:current_user]
  end
end<commit_msg>add missing tests for assign_user_plug<commit_after>defmodule Classlab.AssignUserPlugTest do
  alias Classlab.{AssignUserPlug, JWT.UserIdToken, Session}

  use Classlab.ConnCase

  describe "#call" do
    test "VALID user_id_jwt in session it assigns the correct user", %{conn: conn} do
      user = Factory.insert(:user)
      conn =
        conn
        |> Session.login(user)
        |> AssignUserPlug.call(%{})

      assert conn.assigns[:current_user] == user
    end

    test "INVALID user_id_jwt in session it assigns nil for the user", %{conn: conn} do
      conn = AssignUserPlug.call(conn, %{})
      refute conn.assigns[:current_user]
    end

    test "user_id_jwt in session calls login", %{conn: conn} do
      user = Factory.insert(:user)

      conn =
        conn
        |> put_session(:user_id_jwt, UserIdToken.encode(%UserIdToken{user_id: user.id}))
        |> AssignUserPlug.call(%{})

      assert conn.assigns[:current_user] == user
    end
  end

  describe "#init" do
    opts = %{"test" => true}
    assert AssignUserPlug.init(opts) == opts
  end
end
{'fraction_non_alphanumeric': 0.11050394656952034, 'fraction_numerical': 0.0, 'mean_word_length': 3.2256410256410257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3387203', 'n_tokens_mistral': 548, 'n_tokens_neox': 512, 'n_words': 141}