total rebase
[anni] / test / pleroma / web / pleroma_api / controllers / scrobble_controller_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.Web.PleromaAPI.ScrobbleControllerTest do
6   use Pleroma.Web.ConnCase, async: true
7
8   alias Pleroma.Web.CommonAPI
9
10   describe "POST /api/v1/pleroma/scrobble" do
11     test "works correctly" do
12       %{conn: conn} = oauth_access(["write"])
13
14       conn =
15         conn
16         |> put_req_header("content-type", "application/json")
17         |> post("/api/v1/pleroma/scrobble", %{
18           "title" => "lain radio episode 1",
19           "artist" => "lain",
20           "album" => "lain radio",
21           "length" => "180000",
22           "externalLink" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
23         })
24
25       assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
26     end
27   end
28
29   describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
30     test "works correctly" do
31       %{user: user, conn: conn} = oauth_access(["read"])
32
33       {:ok, _activity} =
34         CommonAPI.listen(user, %{
35           title: "lain radio episode 1",
36           artist: "lain",
37           album: "lain radio",
38           externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
39         })
40
41       {:ok, _activity} =
42         CommonAPI.listen(user, %{
43           title: "lain radio episode 2",
44           artist: "lain",
45           album: "lain radio",
46           externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
47         })
48
49       {:ok, _activity} =
50         CommonAPI.listen(user, %{
51           title: "lain radio episode 3",
52           artist: "lain",
53           album: "lain radio",
54           externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3"
55         })
56
57       conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
58
59       result = json_response_and_validate_schema(conn, 200)
60
61       assert length(result) == 3
62     end
63   end
64 end