[#647] tests for web push
This commit is contained in:
parent
4cbaab2181
commit
bc7570c282
14 changed files with 648 additions and 220 deletions
|
|
@ -229,15 +229,32 @@ defmodule Pleroma.Factory do
|
|||
end
|
||||
|
||||
def oauth_token_factory do
|
||||
user = insert(:user)
|
||||
oauth_app = insert(:oauth_app)
|
||||
|
||||
%Pleroma.Web.OAuth.Token{
|
||||
token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
|
||||
refresh_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
|
||||
user_id: user.id,
|
||||
user: build(:user),
|
||||
app_id: oauth_app.id,
|
||||
valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
|
||||
}
|
||||
end
|
||||
|
||||
def push_subscription_factory do
|
||||
%Pleroma.Web.Push.Subscription{
|
||||
user: build(:user),
|
||||
token: build(:oauth_token),
|
||||
endpoint: "https://example.com/example/1234",
|
||||
key_auth: "8eDyX_uCN0XRhSbY5hs7Hg==",
|
||||
key_p256dh:
|
||||
"BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA=",
|
||||
data: %{}
|
||||
}
|
||||
end
|
||||
|
||||
def notification_factory do
|
||||
%Pleroma.Notification{
|
||||
user: build(:user)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
23
test/support/web_push_http_client_mock.ex
Normal file
23
test/support/web_push_http_client_mock.ex
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebPushHttpClientMock do
|
||||
def get(url, headers \\ [], options \\ []) do
|
||||
{
|
||||
res,
|
||||
%Tesla.Env{status: status}
|
||||
} = Pleroma.HTTP.request(:get, url, "", headers, options)
|
||||
|
||||
{res, %{status_code: status}}
|
||||
end
|
||||
|
||||
def post(url, body, headers \\ [], options \\ []) do
|
||||
{
|
||||
res,
|
||||
%Tesla.Env{status: status}
|
||||
} = Pleroma.HTTP.request(:post, url, body, headers, options)
|
||||
|
||||
{res, %{status_code: status}}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue