branch
[akkoma] / test / web / pleroma_api / controllers / scrobble_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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
7
8 alias Pleroma.Web.CommonAPI
9 import Pleroma.Factory
10
11 describe "POST /api/v1/pleroma/scrobble" do
12 test "works correctly", %{conn: conn} do
13 user = insert(:user)
14
15 conn =
16 conn
17 |> assign(:user, user)
18 |> post("/api/v1/pleroma/scrobble", %{
19 "title" => "lain radio episode 1",
20 "artist" => "lain",
21 "album" => "lain radio",
22 "length" => "180000"
23 })
24
25 assert %{"title" => "lain radio episode 1"} = json_response(conn, 200)
26 end
27 end
28
29 describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
30 test "works correctly", %{conn: conn} do
31 user = insert(:user)
32
33 {:ok, _activity} =
34 CommonAPI.listen(user, %{
35 "title" => "lain radio episode 1",
36 "artist" => "lain",
37 "album" => "lain radio"
38 })
39
40 {:ok, _activity} =
41 CommonAPI.listen(user, %{
42 "title" => "lain radio episode 2",
43 "artist" => "lain",
44 "album" => "lain radio"
45 })
46
47 {:ok, _activity} =
48 CommonAPI.listen(user, %{
49 "title" => "lain radio episode 3",
50 "artist" => "lain",
51 "album" => "lain radio"
52 })
53
54 conn =
55 conn
56 |> get("/api/v1/pleroma/accounts/#{user.id}/scrobbles")
57
58 result = json_response(conn, 200)
59
60 assert length(result) == 3
61 end
62 end
63 end