logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

scrobble_controller_test.exs (1636B)


  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. defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Web.CommonAPI
  7. describe "POST /api/v1/pleroma/scrobble" do
  8. test "works correctly" do
  9. %{conn: conn} = oauth_access(["write"])
  10. conn =
  11. conn
  12. |> put_req_header("content-type", "application/json")
  13. |> post("/api/v1/pleroma/scrobble", %{
  14. "title" => "lain radio episode 1",
  15. "artist" => "lain",
  16. "album" => "lain radio",
  17. "length" => "180000"
  18. })
  19. assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
  20. end
  21. end
  22. describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
  23. test "works correctly" do
  24. %{user: user, conn: conn} = oauth_access(["read"])
  25. {:ok, _activity} =
  26. CommonAPI.listen(user, %{
  27. title: "lain radio episode 1",
  28. artist: "lain",
  29. album: "lain radio"
  30. })
  31. {:ok, _activity} =
  32. CommonAPI.listen(user, %{
  33. title: "lain radio episode 2",
  34. artist: "lain",
  35. album: "lain radio"
  36. })
  37. {:ok, _activity} =
  38. CommonAPI.listen(user, %{
  39. title: "lain radio episode 3",
  40. artist: "lain",
  41. album: "lain radio"
  42. })
  43. conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
  44. result = json_response_and_validate_schema(conn, 200)
  45. assert length(result) == 3
  46. end
  47. end
  48. end