mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
move scrobble into subsonic
This commit is contained in:
@@ -522,6 +522,8 @@ export class Subsonic {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// todo: make private
|
// todo: make private
|
||||||
|
// todo: should I put a catch in here and force a subsonic fail status?
|
||||||
|
// or there is a catch above, that then throws, perhaps can go in there?
|
||||||
getJSON = async <T>(
|
getJSON = async <T>(
|
||||||
{ username, password }: Credentials,
|
{ username, password }: Credentials,
|
||||||
path: string,
|
path: string,
|
||||||
@@ -739,7 +741,13 @@ export class Subsonic {
|
|||||||
this.getJSON<SubsonicResponse>(credentials, `/rest/setRating`, {
|
this.getJSON<SubsonicResponse>(credentials, `/rest/setRating`, {
|
||||||
id,
|
id,
|
||||||
rating,
|
rating,
|
||||||
}).then(it =>
|
})
|
||||||
it.status == "ok"
|
.then(it => it.status == "ok");
|
||||||
);
|
|
||||||
|
scrobble = (credentials: Credentials, id: string, submission: boolean) =>
|
||||||
|
this.getJSON<SubsonicResponse>(credentials, `/rest/scrobble`, {
|
||||||
|
id,
|
||||||
|
submission,
|
||||||
|
})
|
||||||
|
.then(it => it.status == "ok")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,23 +266,12 @@ export class SubsonicMusicLibrary implements MusicLibrary {
|
|||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// todo: unit test the difference between scrobble and nowPlaying
|
||||||
scrobble = async (id: string) =>
|
scrobble = async (id: string) =>
|
||||||
this.subsonic
|
this.subsonic.scrobble(this.credentials, id, true);
|
||||||
.getJSON(this.credentials, `/rest/scrobble`, {
|
|
||||||
id,
|
|
||||||
submission: true,
|
|
||||||
})
|
|
||||||
.then((_) => true)
|
|
||||||
.catch(() => false);
|
|
||||||
|
|
||||||
nowPlaying = async (id: string) =>
|
nowPlaying = async (id: string) =>
|
||||||
this.subsonic
|
this.subsonic.scrobble(this.credentials, id, false);
|
||||||
.getJSON(this.credentials, `/rest/scrobble`, {
|
|
||||||
id,
|
|
||||||
submission: false,
|
|
||||||
})
|
|
||||||
.then((_) => true)
|
|
||||||
.catch(() => false);
|
|
||||||
|
|
||||||
searchArtists = async (query: string) =>
|
searchArtists = async (query: string) =>
|
||||||
this.subsonic
|
this.subsonic
|
||||||
|
|||||||
@@ -1103,4 +1103,76 @@ describe("subsonic", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("scrobble", () => {
|
||||||
|
const id = uuid();
|
||||||
|
|
||||||
|
describe("with submission", () => {
|
||||||
|
const submission = true;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockGET.mockImplementationOnce(() =>
|
||||||
|
Promise.resolve(ok(subsonicResponse({ status: "ok" })))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should scrobble and return true", async () => {
|
||||||
|
const result = await subsonic.scrobble(credentials, id, submission);
|
||||||
|
|
||||||
|
expect(result).toEqual(true);
|
||||||
|
expect(axios.get).toHaveBeenCalledWith(
|
||||||
|
url.append({ pathname: "/rest/scrobble" }).href(),
|
||||||
|
{
|
||||||
|
params: asURLSearchParams({
|
||||||
|
...authParamsPlusJson,
|
||||||
|
id,
|
||||||
|
submission
|
||||||
|
}),
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("without submission", () => {
|
||||||
|
const submission = false;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockGET.mockImplementationOnce(() =>
|
||||||
|
Promise.resolve(ok(subsonicResponse({ status: "ok" })))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should scrobble and return true", async () => {
|
||||||
|
const result = await subsonic.scrobble(credentials, id, submission);
|
||||||
|
|
||||||
|
expect(result).toEqual(true);
|
||||||
|
expect(axios.get).toHaveBeenCalledWith(
|
||||||
|
url.append({ pathname: "/rest/scrobble" }).href(),
|
||||||
|
{
|
||||||
|
params: asURLSearchParams({
|
||||||
|
...authParamsPlusJson,
|
||||||
|
id,
|
||||||
|
submission
|
||||||
|
}),
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when fails", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockGET.mockImplementationOnce(() =>
|
||||||
|
Promise.resolve(ok(subsonicResponse({ status: "not-ok" })))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false", async () => {
|
||||||
|
const result = await subsonic.scrobble(credentials, id, false);
|
||||||
|
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3549,116 +3549,6 @@ describe("SubsonicMusicLibrary", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("scrobble", () => {
|
|
||||||
describe("when succeeds", () => {
|
|
||||||
it("should return true", async () => {
|
|
||||||
const id = uuid();
|
|
||||||
|
|
||||||
mockGET.mockImplementationOnce(() => Promise.resolve(ok(EMPTY)));
|
|
||||||
|
|
||||||
const result = await subsonic.scrobble(id);
|
|
||||||
|
|
||||||
expect(result).toEqual(true);
|
|
||||||
|
|
||||||
expect(mockGET).toHaveBeenCalledWith(
|
|
||||||
url.append({ pathname: "/rest/scrobble" }).href(),
|
|
||||||
{
|
|
||||||
params: asURLSearchParams({
|
|
||||||
...authParamsPlusJson,
|
|
||||||
id,
|
|
||||||
submission: true,
|
|
||||||
}),
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when fails", () => {
|
|
||||||
it("should return false", async () => {
|
|
||||||
const id = uuid();
|
|
||||||
|
|
||||||
mockGET.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
status: 500,
|
|
||||||
data: {},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await subsonic.scrobble(id);
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
|
|
||||||
expect(mockGET).toHaveBeenCalledWith(
|
|
||||||
url.append({ pathname: "/rest/scrobble" }).href(),
|
|
||||||
{
|
|
||||||
params: asURLSearchParams({
|
|
||||||
...authParamsPlusJson,
|
|
||||||
id,
|
|
||||||
submission: true,
|
|
||||||
}),
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("nowPlaying", () => {
|
|
||||||
describe("when succeeds", () => {
|
|
||||||
it("should return true", async () => {
|
|
||||||
const id = uuid();
|
|
||||||
|
|
||||||
mockGET.mockImplementationOnce(() => Promise.resolve(ok(EMPTY)));
|
|
||||||
|
|
||||||
const result = await subsonic.nowPlaying(id);
|
|
||||||
|
|
||||||
expect(result).toEqual(true);
|
|
||||||
|
|
||||||
expect(mockGET).toHaveBeenCalledWith(
|
|
||||||
url.append({ pathname: "/rest/scrobble" }).href(),
|
|
||||||
{
|
|
||||||
params: asURLSearchParams({
|
|
||||||
...authParamsPlusJson,
|
|
||||||
id,
|
|
||||||
submission: false,
|
|
||||||
}),
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when fails", () => {
|
|
||||||
it("should return false", async () => {
|
|
||||||
const id = uuid();
|
|
||||||
|
|
||||||
mockGET.mockImplementationOnce(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
status: 500,
|
|
||||||
data: {},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await subsonic.nowPlaying(id);
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
|
|
||||||
expect(mockGET).toHaveBeenCalledWith(
|
|
||||||
url.append({ pathname: "/rest/scrobble" }).href(),
|
|
||||||
{
|
|
||||||
params: asURLSearchParams({
|
|
||||||
...authParamsPlusJson,
|
|
||||||
id,
|
|
||||||
submission: false,
|
|
||||||
}),
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("searchArtists", () => {
|
describe("searchArtists", () => {
|
||||||
describe("when there is 1 search results", () => {
|
describe("when there is 1 search results", () => {
|
||||||
it("should return true", async () => {
|
it("should return true", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user