total rebase
[anni] / test / pleroma / http / web_push_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTP.WebPushTest do
6   use ExUnit.Case
7
8   import Tesla.Mock
9   alias Pleroma.HTTP
10
11   @push_url "https://some-push-server/"
12
13   setup do
14     mock(fn
15       %{
16         method: :post,
17         url: @push_url,
18         headers: headers
19       } ->
20         if {"content-type", "octet-stream"} in headers do
21           %Tesla.Env{
22             status: 200
23           }
24         else
25           %Tesla.Env{
26             status: 403
27           }
28         end
29     end)
30
31     :ok
32   end
33
34   test "post" do
35     response =
36       HTTP.WebPush.post(
37         @push_url,
38         "encrypted payload",
39         %{"authorization" => "WebPush"},
40         []
41       )
42
43     assert {:ok, %{status: 200}} = response
44   end
45 end