fix CSS
[akkoma] / test / pleroma / web / o_auth / token / utils_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OAuth.Token.UtilsTest do
6 use Pleroma.DataCase
7 alias Pleroma.Web.OAuth.Token.Utils
8 import Pleroma.Factory
9
10 describe "fetch_app/1" do
11 test "returns error when credentials is invalid" do
12 assert {:error, :not_found} =
13 Utils.fetch_app(%Plug.Conn{params: %{"client_id" => 1, "client_secret" => "x"}})
14 end
15
16 test "returns App by params credentails" do
17 app = insert(:oauth_app)
18
19 assert {:ok, load_app} =
20 Utils.fetch_app(%Plug.Conn{
21 params: %{"client_id" => app.client_id, "client_secret" => app.client_secret}
22 })
23
24 assert load_app == app
25 end
26
27 test "returns App by header credentails" do
28 app = insert(:oauth_app)
29 header = "Basic " <> Base.encode64("#{app.client_id}:#{app.client_secret}")
30
31 conn =
32 %Plug.Conn{}
33 |> Plug.Conn.put_req_header("authorization", header)
34
35 assert {:ok, load_app} = Utils.fetch_app(conn)
36 assert load_app == app
37 end
38 end
39
40 describe "format_created_at/1" do
41 test "returns formatted created at" do
42 token = insert(:oauth_token)
43 date = Utils.format_created_at(token)
44
45 token_date =
46 token.inserted_at
47 |> DateTime.from_naive!("Etc/UTC")
48 |> DateTime.to_unix()
49
50 assert token_date == date
51 end
52 end
53 end