Merge remote-tracking branch 'remotes/origin/develop' into oauth-scopes-tweaks-and-tests

This commit is contained in:
Ivan Tashkinov 2019-12-19 17:24:08 +03:00
commit ead2d18826
18 changed files with 120 additions and 45 deletions

View File

@ -1,13 +1,13 @@
image: elixir:1.8.1 image: elixir:1.8.1
variables: variables: &global_variables
POSTGRES_DB: pleroma_test POSTGRES_DB: pleroma_test
POSTGRES_USER: postgres POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
DB_HOST: postgres DB_HOST: postgres
MIX_ENV: test MIX_ENV: test
cache: cache: &global_cache_policy
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
paths: paths:
- deps - deps
@ -46,6 +46,10 @@ benchmark:
unit-testing: unit-testing:
stage: test stage: test
cache: &testing_cache_policy
<<: *global_cache_policy
policy: pull
services: services:
- name: postgres:9.6 - name: postgres:9.6
alias: postgres alias: postgres
@ -58,6 +62,7 @@ unit-testing:
federated-testing: federated-testing:
stage: test stage: test
cache: *testing_cache_policy
services: services:
- name: minibikini/postgres-with-rum:12 - name: minibikini/postgres-with-rum:12
alias: postgres alias: postgres
@ -71,11 +76,13 @@ federated-testing:
unit-testing-rum: unit-testing-rum:
stage: test stage: test
cache: *testing_cache_policy
services: services:
- name: minibikini/postgres-with-rum:12 - name: minibikini/postgres-with-rum:12
alias: postgres alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"] command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
variables: variables:
<<: *global_variables
RUM_ENABLED: "true" RUM_ENABLED: "true"
script: script:
- mix deps.get - mix deps.get
@ -86,17 +93,20 @@ unit-testing-rum:
lint: lint:
stage: test stage: test
cache: *testing_cache_policy
script: script:
- mix format --check-formatted - mix format --check-formatted
analysis: analysis:
stage: test stage: test
cache: *testing_cache_policy
script: script:
- mix deps.get - mix deps.get
- mix credo --strict --only=warnings,todo,fixme,consistency,readability - mix credo --strict --only=warnings,todo,fixme,consistency,readability
docs-deploy: docs-deploy:
stage: deploy stage: deploy
cache: *testing_cache_policy
image: alpine:latest image: alpine:latest
only: only:
- stable@pleroma/pleroma - stable@pleroma/pleroma

View File

@ -70,6 +70,8 @@
seconds_valid: 60, seconds_valid: 60,
method: Pleroma.Captcha.Native method: Pleroma.Captcha.Native
config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.ch"
config :pleroma, :hackney_pools, config :pleroma, :hackney_pools,
federation: [ federation: [
max_connections: 50, max_connections: 50,

View File

@ -95,8 +95,6 @@
config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock
config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.ch"
if File.exists?("./config/test.secret.exs") do if File.exists?("./config/test.secret.exs") do
import_config "test.secret.exs" import_config "test.secret.exs"
else else

View File

@ -397,7 +397,7 @@ def handle_incoming(
%{"type" => "Create", "object" => %{"type" => objtype} = object} = data, %{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
options options
) )
when objtype in ["Article", "Note", "Video", "Page", "Question", "Answer"] do when objtype in ["Article", "Event", "Note", "Video", "Page", "Question", "Answer"] do
actor = Containment.get_actor(data) actor = Containment.get_actor(data)
data = data =

View File

@ -22,7 +22,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
require Logger require Logger
require Pleroma.Constants require Pleroma.Constants
@supported_object_types ["Article", "Note", "Video", "Page", "Question", "Answer", "Audio"] @supported_object_types [
"Article",
"Note",
"Event",
"Video",
"Page",
"Question",
"Answer",
"Audio"
]
@strip_status_report_states ~w(closed resolved) @strip_status_report_states ~w(closed resolved)
@supported_report_states ~w(open closed resolved) @supported_report_states ~w(open closed resolved)
@valid_visibilities ~w(public unlisted private direct) @valid_visibilities ~w(public unlisted private direct)

View File

@ -201,7 +201,6 @@ def render("followers.json", %{user: user} = opts) do
%{ %{
"id" => "#{user.ap_id}/followers", "id" => "#{user.ap_id}/followers",
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => total,
"first" => "first" =>
if showing_items do if showing_items do
collection(followers, "#{user.ap_id}/followers", 1, showing_items, total) collection(followers, "#{user.ap_id}/followers", 1, showing_items, total)
@ -209,6 +208,7 @@ def render("followers.json", %{user: user} = opts) do
"#{user.ap_id}/followers?page=1" "#{user.ap_id}/followers?page=1"
end end
} }
|> maybe_put_total_items(showing_count, total)
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -251,6 +251,12 @@ def render("activity_collection_page.json", %{activities: activities, iri: iri})
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
defp maybe_put_total_items(map, false, _total), do: map
defp maybe_put_total_items(map, true, total) do
Map.put(map, "totalItems", total)
end
def collection(collection, iri, page, show_items \\ true, total \\ nil) do def collection(collection, iri, page, show_items \\ true, total \\ nil) do
offset = (page - 1) * 10 offset = (page - 1) * 10
items = Enum.slice(collection, offset, 10) items = Enum.slice(collection, offset, 10)

View File

@ -421,7 +421,8 @@ def get_reply_to(%{data: %{"object" => _object}} = activity, _) do
end end
end end
def render_content(%{data: %{"type" => "Video"}} = object) do def render_content(%{data: %{"type" => object_type}} = object)
when object_type in ["Video", "Event"] do
with name when not is_nil(name) and name != "" <- object.data["name"] do with name when not is_nil(name) and name != "" <- object.data["name"] do
"<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}" "<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}"
else else

View File

@ -111,7 +111,8 @@ defp follow_template(_), do: "follow_login.html"
defp is_status?(acct) do defp is_status?(acct) do
case Pleroma.Object.Fetcher.fetch_and_contain_remote_object_from_id(acct) do case Pleroma.Object.Fetcher.fetch_and_contain_remote_object_from_id(acct) do
{:ok, %{"type" => type}} when type in ["Article", "Note", "Video", "Page", "Question"] -> {:ok, %{"type" => type}}
when type in ["Article", "Event", "Note", "Video", "Page", "Question"] ->
true true
_ -> _ ->

View File

@ -5,7 +5,9 @@
defmodule Pleroma.Conversation.ParticipationTest do defmodule Pleroma.Conversation.ParticipationTest do
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Conversation
alias Pleroma.Conversation.Participation alias Pleroma.Conversation.Participation
alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
@ -98,7 +100,9 @@ test "it creates a participation for a conversation and a user" do
assert participation.user_id == user.id assert participation.user_id == user.id
assert participation.conversation_id == conversation.id assert participation.conversation_id == conversation.id
# Needed because updated_at is accurate down to a second
:timer.sleep(1000) :timer.sleep(1000)
# Creating again returns the same participation # Creating again returns the same participation
{:ok, %Participation{} = participation_two} = {:ok, %Participation{} = participation_two} =
Participation.create_for_user_and_conversation(user, conversation) Participation.create_for_user_and_conversation(user, conversation)
@ -150,9 +154,7 @@ test "it marks all the user's participations as read" do
test "gets all the participations for a user, ordered by updated at descending" do test "gets all the participations for a user, ordered by updated at descending" do
user = insert(:user) user = insert(:user)
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"}) {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
:timer.sleep(1000)
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"}) {:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
:timer.sleep(1000)
{:ok, activity_three} = {:ok, activity_three} =
CommonAPI.post(user, %{ CommonAPI.post(user, %{
@ -161,6 +163,17 @@ test "gets all the participations for a user, ordered by updated at descending"
"in_reply_to_status_id" => activity_one.id "in_reply_to_status_id" => activity_one.id
}) })
# Offset participations because the accuracy of updated_at is down to a second
for {activity, offset} <- [{activity_two, 1}, {activity_three, 2}] do
conversation = Conversation.get_for_ap_id(activity.data["context"])
participation = Participation.for_user_and_conversation(user, conversation)
updated_at = NaiveDateTime.add(Map.get(participation, :updated_at), offset)
Ecto.Changeset.change(participation, %{updated_at: updated_at})
|> Repo.update!()
end
assert [participation_one, participation_two] = Participation.for_user(user) assert [participation_one, participation_two] = Participation.for_user(user)
object2 = Pleroma.Object.normalize(activity_two) object2 = Pleroma.Object.normalize(activity_two)

View File

@ -0,0 +1 @@
{"@context":["https://www.w3.org/ns/activitystreams","https://litepub.social/litepub/context.jsonld",{"GeoCoordinates":"sc:GeoCoordinates","Hashtag":"as:Hashtag","Place":"sc:Place","PostalAddress":"sc:PostalAddress","address":{"@id":"sc:address","@type":"sc:PostalAddress"},"addressCountry":"sc:addressCountry","addressLocality":"sc:addressLocality","addressRegion":"sc:addressRegion","category":"sc:category","commentsEnabled":{"@id":"pt:commentsEnabled","@type":"sc:Boolean"},"geo":{"@id":"sc:geo","@type":"sc:GeoCoordinates"},"ical":"http://www.w3.org/2002/12/cal/ical#","joinMode":{"@id":"mz:joinMode","@type":"mz:joinModeType"},"joinModeType":{"@id":"mz:joinModeType","@type":"rdfs:Class"},"location":{"@id":"sc:location","@type":"sc:Place"},"maximumAttendeeCapacity":"sc:maximumAttendeeCapacity","mz":"https://joinmobilizon.org/ns#","postalCode":"sc:postalCode","pt":"https://joinpeertube.org/ns#","repliesModerationOption":{"@id":"mz:repliesModerationOption","@type":"mz:repliesModerationOptionType"},"repliesModerationOptionType":{"@id":"mz:repliesModerationOptionType","@type":"rdfs:Class"},"sc":"http://schema.org#","streetAddress":"sc:streetAddress","uuid":"sc:identifier"}],"actor":"https://mobilizon.org/@tcit","attributedTo":"https://mobilizon.org/@tcit","category":"meeting","cc":[],"commentsEnabled":true,"content":"<p>Mobilizon is now federated! 🎉</p><p></p><p>You can view this event from other instances if they are subscribed to mobilizon.org, and soon directly from Mastodon and Pleroma. It is possible that you may see some comments from other instances, including Mastodon ones, just below.</p><p></p><p>With a Mobilizon account on an instance, you may <strong>participate</strong> at events from other instances and <strong>add comments</strong> on events.</p><p></p><p>Of course, it's still <u>a work in progress</u>: if reports made from an instance on events and comments can be federated, you can't block people right now, and moderators actions are rather limited, but this <strong>will definitely get fixed over time</strong> until first stable version next year.</p><p></p><p>Anyway, if you want to come up with some feedback, head over to our forum or - if you feel you have technical skills and are familiar with it - on our Gitlab repository.</p><p></p><p>Also, to people that want to set Mobilizon themselves even though we really don't advise to do that for now, we have a little documentation but it's quite the early days and you'll probably need some help. No worries, you can chat with us on our Forum or though our Matrix channel.</p><p></p><p>Check our website for more informations and follow us on Twitter or Mastodon.</p>","endTime":"2019-12-18T14:00:00Z","ical:status":"CONFIRMED","id":"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39","joinMode":"free","location":{"address":{"addressCountry":"France","addressLocality":"Nantes","addressRegion":"Pays de la Loire","postalCode":null,"streetAddress":" ","type":"PostalAddress"},"geo":{"latitude":-1.54939699141711,"longitude":47.21617415,"type":"GeoCoordinates"},"id":"https://mobilizon.org/address/1368fdab-1e2c-4de6-bcff-a90c84abdee1","name":"Cour du Château des Ducs de Bretagne","type":"Place"},"maximumAttendeeCapacity":0,"mediaType":"text/html","name":"Mobilizon Launching Party","published":"2019-12-17T11:33:56Z","repliesModerationOption":"allow_all","startTime":"2019-12-18T13:00:00Z","tag":[{"href":"https://mobilizon.org/tags/mobilizon","name":"#Mobilizon","type":"Hashtag"},{"href":"https://mobilizon.org/tags/federation","name":"#Federation","type":"Hashtag"},{"href":"https://mobilizon.org/tags/activitypub","name":"#ActivityPub","type":"Hashtag"},{"href":"https://mobilizon.org/tags/party","name":"#Party","type":"Hashtag"}],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Event","updated":"2019-12-17T12:25:01Z","url":"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39","uuid":"252d5816-00a3-4a89-a66f-15bf65c33e39"}

View File

@ -0,0 +1 @@
{"@context":["https://www.w3.org/ns/activitystreams","https://litepub.social/litepub/context.jsonld",{"GeoCoordinates":"sc:GeoCoordinates","Hashtag":"as:Hashtag","Place":"sc:Place","PostalAddress":"sc:PostalAddress","address":{"@id":"sc:address","@type":"sc:PostalAddress"},"addressCountry":"sc:addressCountry","addressLocality":"sc:addressLocality","addressRegion":"sc:addressRegion","category":"sc:category","commentsEnabled":{"@id":"pt:commentsEnabled","@type":"sc:Boolean"},"geo":{"@id":"sc:geo","@type":"sc:GeoCoordinates"},"ical":"http://www.w3.org/2002/12/cal/ical#","joinMode":{"@id":"mz:joinMode","@type":"mz:joinModeType"},"joinModeType":{"@id":"mz:joinModeType","@type":"rdfs:Class"},"location":{"@id":"sc:location","@type":"sc:Place"},"maximumAttendeeCapacity":"sc:maximumAttendeeCapacity","mz":"https://joinmobilizon.org/ns#","postalCode":"sc:postalCode","pt":"https://joinpeertube.org/ns#","repliesModerationOption":{"@id":"mz:repliesModerationOption","@type":"mz:repliesModerationOptionType"},"repliesModerationOptionType":{"@id":"mz:repliesModerationOptionType","@type":"rdfs:Class"},"sc":"http://schema.org#","streetAddress":"sc:streetAddress","uuid":"sc:identifier"}],"endpoints":{"sharedInbox":"https://mobilizon.org/inbox"},"followers":"https://mobilizon.org/@tcit/followers","following":"https://mobilizon.org/@tcit/following","icon":{"mediaType":null,"type":"Image","url":"https://mobilizon.org/media/3a5f18c058a8193b1febfaf561f94ae8b91f85ac64c01ddf5ad7b251fb43baf5.jpg?name=profil.jpg"},"id":"https://mobilizon.org/@tcit","inbox":"https://mobilizon.org/@tcit/inbox","manuallyApprovesFollowers":false,"name":"Thomas Citharel","outbox":"https://mobilizon.org/@tcit/outbox","preferredUsername":"tcit","publicKey":{"id":"https://mobilizon.org/@tcit#main-key","owner":"https://mobilizon.org/@tcit","publicKeyPem":"-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAtzuZFviv5f12SuA0wZFMuwKS8RIlT3IjPCMLRDhiorZeV3UJ1lik\nDYO6mEh22KDXYgJtNVSYGF0Q5LJivgcvuvU+VQ048iTB1B2x0rHMr47KPByPjfVb\nKDeHt6fkHcLY0JK8UkIxW542wXAg4jX5w3gJi3pgTQrCT8VNyPbH1CaA0uW//9jc\nqzZQVFzpfdJoVOM9E3Urc/u58HC4xOptlM7+B/594ZI9drYwy5m+ZxHwlQUYCva4\n34dvwsfOGxkQyIrzXoep80EnWnFpYCLMcCiz+sEhPYxqLgNE+Cmn/6pv7SIscz6p\neVlQXIchdw+J4yl07paJDkFc6CNTCmaIHQIDAQAB\n-----END RSA PUBLIC KEY-----\n\n"},"summary":"Main profile","type":"Person","url":"https://mobilizon.org/@tcit"}

View File

@ -77,6 +77,15 @@ test "it can fetch peertube videos" do
assert object assert object
end end
test "it can fetch Mobilizon events" do
{:ok, object} =
Fetcher.fetch_object_from_id(
"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
)
assert object
end
test "it can fetch wedistribute articles" do test "it can fetch wedistribute articles" do
{:ok, object} = {:ok, object} =
Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810") Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810")

View File

@ -145,9 +145,9 @@ test "are restricted based on remote IP" do
test "can have limits seperate from unauthenticated connections" do test "can have limits seperate from unauthenticated connections" do
limiter_name = :test_authenticated limiter_name = :test_authenticated
scale = 1000 scale = 50
limit = 5 limit = 5
Pleroma.Config.put([:rate_limit, limiter_name], [{1, 10}, {scale, limit}]) Pleroma.Config.put([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
opts = RateLimiter.init(name: limiter_name) opts = RateLimiter.init(name: limiter_name)
@ -164,16 +164,6 @@ test "can have limits seperate from unauthenticated connections" do
assert %{"error" => "Throttled"} = Phoenix.ConnTest.json_response(conn, :too_many_requests) assert %{"error" => "Throttled"} = Phoenix.ConnTest.json_response(conn, :too_many_requests)
assert conn.halted assert conn.halted
Process.sleep(1550)
conn = conn(:get, "/") |> assign(:user, user)
conn = RateLimiter.call(conn, opts)
assert {1, 4} = RateLimiter.inspect_bucket(conn, limiter_name, opts)
refute conn.status == Plug.Conn.Status.code(:too_many_requests)
refute conn.resp_body
refute conn.halted
end end
test "diffrerent users are counted independently" do test "diffrerent users are counted independently" do

View File

@ -308,6 +308,24 @@ def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
}} }}
end end
def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _,
Accept: "application/activity+json"
) do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
}}
end
def get("https://mobilizon.org/@tcit", _, _, Accept: "application/activity+json") do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
}}
end
def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{

View File

@ -1639,13 +1639,10 @@ test "returns a favourite activities sorted by adds to favorite" do
{:ok, _, _} = CommonAPI.favorite(a4.id, user) {:ok, _, _} = CommonAPI.favorite(a4.id, user)
{:ok, _, _} = CommonAPI.favorite(a3.id, other_user) {:ok, _, _} = CommonAPI.favorite(a3.id, other_user)
Process.sleep(1000)
{:ok, _, _} = CommonAPI.favorite(a3.id, user) {:ok, _, _} = CommonAPI.favorite(a3.id, user)
{:ok, _, _} = CommonAPI.favorite(a5.id, other_user) {:ok, _, _} = CommonAPI.favorite(a5.id, other_user)
Process.sleep(1000)
{:ok, _, _} = CommonAPI.favorite(a5.id, user) {:ok, _, _} = CommonAPI.favorite(a5.id, user)
{:ok, _, _} = CommonAPI.favorite(a4.id, other_user) {:ok, _, _} = CommonAPI.favorite(a4.id, other_user)
Process.sleep(1000)
{:ok, _, _} = CommonAPI.favorite(a1.id, user) {:ok, _, _} = CommonAPI.favorite(a1.id, user)
{:ok, _, _} = CommonAPI.favorite(a1.id, other_user) {:ok, _, _} = CommonAPI.favorite(a1.id, other_user)
result = ActivityPub.fetch_favourites(user) result = ActivityPub.fetch_favourites(user)

View File

@ -126,7 +126,7 @@ test "sets totalItems to zero when followers are hidden" do
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user}) refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems")
end end
test "sets correct totalItems when followers are hidden but the follower counter is not" do test "sets correct totalItems when followers are hidden but the follower counter is not" do

View File

@ -394,6 +394,21 @@ test "a peertube video" do
assert length(represented[:media_attachments]) == 1 assert length(represented[:media_attachments]) == 1
end end
test "a Mobilizon event" do
user = insert(:user)
{:ok, object} =
Pleroma.Object.Fetcher.fetch_object_from_id(
"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
)
%Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
represented = StatusView.render("show.json", %{for: user, activity: activity})
assert represented[:id] == to_string(activity.id)
end
describe "build_tags/1" do describe "build_tags/1" do
test "it returns a a dictionary tags" do test "it returns a a dictionary tags" do
object_tags = [ object_tags = [

View File

@ -16,6 +16,10 @@ defmodule Pleroma.Web.StreamerTest do
alias Pleroma.Web.Streamer.Worker alias Pleroma.Web.Streamer.Worker
@moduletag needs_streamer: true, capture_log: true @moduletag needs_streamer: true, capture_log: true
@streamer_timeout 150
@streamer_start_wait 10
clear_config_all([:instance, :skip_thread_containment]) clear_config_all([:instance, :skip_thread_containment])
describe "user streams" do describe "user streams" do
@ -28,7 +32,7 @@ defmodule Pleroma.Web.StreamerTest do
test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, _}, 4_000 assert_receive {:text, _}, @streamer_timeout
end) end)
Streamer.add_socket( Streamer.add_socket(
@ -43,7 +47,7 @@ test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, _}, 4_000 assert_receive {:text, _}, @streamer_timeout
end) end)
Streamer.add_socket( Streamer.add_socket(
@ -61,7 +65,7 @@ test "it doesn't send notify to the 'user:notification' stream when a user is bl
blocked = insert(:user) blocked = insert(:user)
{:ok, _user_relationship} = User.block(user, blocked) {:ok, _user_relationship} = User.block(user, blocked)
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end) task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
Streamer.add_socket( Streamer.add_socket(
"user:notification", "user:notification",
@ -79,7 +83,7 @@ test "it doesn't send notify to the 'user:notification' stream when a thread is
user: user user: user
} do } do
user2 = insert(:user) user2 = insert(:user)
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end) task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
Streamer.add_socket( Streamer.add_socket(
"user:notification", "user:notification",
@ -97,7 +101,7 @@ test "it doesn't send notify to the 'user:notification' stream' when a domain is
user: user user: user
} do } do
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"}) user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end) task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
Streamer.add_socket( Streamer.add_socket(
"user:notification", "user:notification",
@ -116,7 +120,9 @@ test "it sends follow activities to the 'user:notification' stream", %{
user: user user: user
} do } do
user2 = insert(:user) user2 = insert(:user)
task = Task.async(fn -> assert_receive {:text, _}, 4_000 end) task = Task.async(fn -> assert_receive {:text, _}, @streamer_timeout end)
Process.sleep(@streamer_start_wait)
Streamer.add_socket( Streamer.add_socket(
"user:notification", "user:notification",
@ -137,7 +143,7 @@ test "it sends to public" do
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, _}, 4_000 assert_receive {:text, _}, @streamer_timeout
end) end)
fake_socket = %StreamerSocket{ fake_socket = %StreamerSocket{
@ -164,7 +170,7 @@ test "it sends to public" do
} }
|> Jason.encode!() |> Jason.encode!()
assert_receive {:text, received_event}, 4_000 assert_receive {:text, received_event}, @streamer_timeout
assert received_event == expected_event assert received_event == expected_event
end) end)
@ -458,9 +464,7 @@ test "it doesn't send posts from muted threads" do
{:ok, activity} = CommonAPI.add_mute(user2, activity) {:ok, activity} = CommonAPI.add_mute(user2, activity)
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end) task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
Process.sleep(4000)
Streamer.add_socket( Streamer.add_socket(
"user", "user",
@ -482,7 +486,7 @@ test "it sends conversation update to the 'direct' stream", %{} do
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, received_event}, 4_000 assert_receive {:text, received_event}, @streamer_timeout
assert %{"event" => "conversation", "payload" => received_payload} = assert %{"event" => "conversation", "payload" => received_payload} =
Jason.decode!(received_event) Jason.decode!(received_event)
@ -518,13 +522,13 @@ test "it doesn't send conversation update to the 'direct' stream when the last m
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, received_event}, 4_000 assert_receive {:text, received_event}, @streamer_timeout
assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event) assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
refute_receive {:text, _}, 4_000 refute_receive {:text, _}, @streamer_timeout
end) end)
Process.sleep(1000) Process.sleep(@streamer_start_wait)
Streamer.add_socket( Streamer.add_socket(
"direct", "direct",
@ -555,10 +559,10 @@ test "it sends conversation update to the 'direct' stream when a message is dele
task = task =
Task.async(fn -> Task.async(fn ->
assert_receive {:text, received_event}, 4_000 assert_receive {:text, received_event}, @streamer_timeout
assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event) assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
assert_receive {:text, received_event}, 4_000 assert_receive {:text, received_event}, @streamer_timeout
assert %{"event" => "conversation", "payload" => received_payload} = assert %{"event" => "conversation", "payload" => received_payload} =
Jason.decode!(received_event) Jason.decode!(received_event)
@ -567,7 +571,7 @@ test "it sends conversation update to the 'direct' stream when a message is dele
assert last_status["id"] == to_string(create_activity.id) assert last_status["id"] == to_string(create_activity.id)
end) end)
Process.sleep(1000) Process.sleep(@streamer_start_wait)
Streamer.add_socket( Streamer.add_socket(
"direct", "direct",