2019-09-27 20:12:12 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 20:12:12 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
2020-12-21 04:21:40 -07:00
|
|
|
use Pleroma.Web.ConnCase, async: true
|
2019-09-27 20:12:12 -06:00
|
|
|
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
2019-09-28 20:18:34 -06:00
|
|
|
describe "POST /api/v1/pleroma/scrobble" do
|
2019-12-19 07:23:27 -07:00
|
|
|
test "works correctly" do
|
|
|
|
%{conn: conn} = oauth_access(["write"])
|
2019-09-27 20:12:12 -06:00
|
|
|
|
|
|
|
conn =
|
2020-05-19 05:53:18 -06:00
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> post("/api/v1/pleroma/scrobble", %{
|
2019-09-27 20:12:12 -06:00
|
|
|
"title" => "lain radio episode 1",
|
|
|
|
"artist" => "lain",
|
|
|
|
"album" => "lain radio",
|
|
|
|
"length" => "180000"
|
|
|
|
})
|
|
|
|
|
2020-05-19 05:53:18 -06:00
|
|
|
assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
|
2019-09-27 20:12:12 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-28 18:35:40 -06:00
|
|
|
describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
|
2019-12-19 07:23:27 -07:00
|
|
|
test "works correctly" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["read"])
|
2019-09-27 20:12:12 -06:00
|
|
|
|
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.listen(user, %{
|
2020-05-19 05:53:18 -06:00
|
|
|
title: "lain radio episode 1",
|
|
|
|
artist: "lain",
|
|
|
|
album: "lain radio"
|
2019-09-27 20:12:12 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.listen(user, %{
|
2020-05-19 05:53:18 -06:00
|
|
|
title: "lain radio episode 2",
|
|
|
|
artist: "lain",
|
|
|
|
album: "lain radio"
|
2019-09-27 20:12:12 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.listen(user, %{
|
2020-05-19 05:53:18 -06:00
|
|
|
title: "lain radio episode 3",
|
|
|
|
artist: "lain",
|
|
|
|
album: "lain radio"
|
2019-09-27 20:12:12 -06:00
|
|
|
})
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
|
2019-09-27 20:12:12 -06:00
|
|
|
|
2020-05-19 05:53:18 -06:00
|
|
|
result = json_response_and_validate_schema(conn, 200)
|
2019-09-27 20:12:12 -06:00
|
|
|
|
|
|
|
assert length(result) == 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|