<commit_before>defmodule Scripture.AuthenticatePlugTest do
  use Scripture.ConnCase, async: true

  @opts Scripture.AuthenticatePlug.init("reader")

  test "denies access if no logged in user" do
    conn = browser_conn()
    |> get("/admin/articles")
    |> Phoenix.Controller.accepts(["html"])
    |> Scripture.AuthenticatePlug.call(@opts)

    assert conn.status == 403
    assert String.contains?(get_flash(conn, :info), "Bitte logge dich ein")
  end

  test "does not trigger redirect if logged in user" do
    conn = browser_conn()
      |> get("/")
      |> log_in_as(persist_fixture(:user))
      |> Scripture.AuthenticatePlug.call(@opts)

    assert conn.status == nil # no answer yet<commit_msg>add an actual authentication test<commit_after>defmodule Scripture.AuthenticatePlugTest do
  use Scripture.ConnCase, async: true

  @opts Scripture.AuthenticatePlug.init("admin")

  test "denies access if no logged in user" do
    conn = browser_conn()
    |> get("/admin/articles")
    |> Scripture.AuthenticatePlug.call(@opts)

    assert conn.status == 403
    assert String.contains?(get_flash(conn, :info), "Bitte logge dich ein")
  end

  test "denies access if unauthorized user" do
    conn = browser_conn()
    |> get("/admin/articles")
    |> log_in_as(persist_fixture(:user))
    |> Scripture.AuthenticatePlug.call(@opts)

    assert conn.status == 403
    assert String.contains?(get_flash(conn, :error), "Du bist nicht berechtigt, auf diese Seite zuzugreifen.")
  end

  test "does not halt connection if logged in authorized user" do
    conn = browser_conn()
      |> get("/")
      |> log_in_as(persist_fixture(:admin))
      |> Scripture.AuthenticatePlug.call(@opts)

    assert conn.status == nil # no answer yet
{'fraction_non_alphanumeric': 0.12046109510086456, 'fraction_numerical': 0.005187319884726225, 'mean_word_length': 3.8356545961002784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6630724', 'n_tokens_mistral': 575, 'n_tokens_neox': 517, 'n_words': 140}