From 8ef9ca80b62ced7ae404a157487331445e569133 Mon Sep 17 00:00:00 2001 From: Simon J Date: Wed, 11 Oct 2023 12:45:27 +1100 Subject: [PATCH] Fix issue #177 (#178) --- src/subsonic.ts | 3 ++- tests/subsonic.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/subsonic.ts b/src/subsonic.ts index 55e5881..7917e09 100644 --- a/src/subsonic.ts +++ b/src/subsonic.ts @@ -956,6 +956,7 @@ export class Subsonic implements MusicService { }; if (credentials.type == "navidrome") { + // todo: there does not seem to be a test for this?? return Promise.resolve({ ...genericSubsonic, flavour: () => "navidrome", @@ -964,7 +965,7 @@ export class Subsonic implements MusicService { TE.tryCatch( () => axios.post( - `${this.url}/auth/login`, + this.url.append({ pathname: '/auth/login' }).href(), _.pick(credentials, "username", "password") ), () => new AuthFailure("Failed to get bearerToken") diff --git a/tests/subsonic.test.ts b/tests/subsonic.test.ts index 761346b..e2560db 100644 --- a/tests/subsonic.test.ts +++ b/tests/subsonic.test.ts @@ -928,6 +928,34 @@ describe("Subsonic", () => { }); }); + describe("bearerToken", () => { + describe("when flavour is generic subsonic", () => { + it("should return undefined", async () => { + const credentials = { username: "foo", password: "bar" }; + const token = { ...credentials, type: "subsonic", bearer: undefined } + const client = await subsonic.login(asToken(token)); + + const bearerToken = await pipe(client.bearerToken(credentials))(); + expect(bearerToken).toStrictEqual(E.right(undefined)); + }); + }); + + describe("when flavour is navidrome", () => { + it("should get a bearerToken from navidrome", async () => { + const credentials = { username: "foo", password: "bar" }; + const token = { ...credentials, type: "navidrome", bearer: undefined } + const client = await subsonic.login(asToken(token)); + + mockPOST.mockImplementationOnce(() => Promise.resolve(ok({ token: 'theBearerToken' }))) + + const bearerToken = await pipe(client.bearerToken(credentials))(); + expect(bearerToken).toStrictEqual(E.right('theBearerToken')); + + expect(axios.post).toHaveBeenCalledWith(url.append({ pathname: '/auth/login' }).href(), credentials) + }); + }); + }); + describe("getting genres", () => { describe("when there are none", () => { beforeEach(() => {