This commit is contained in:
Simon J
2023-10-11 12:45:27 +11:00
committed by GitHub
parent a5689c3d4b
commit 8ef9ca80b6
2 changed files with 30 additions and 1 deletions

View File

@@ -956,6 +956,7 @@ export class Subsonic implements MusicService {
}; };
if (credentials.type == "navidrome") { if (credentials.type == "navidrome") {
// todo: there does not seem to be a test for this??
return Promise.resolve({ return Promise.resolve({
...genericSubsonic, ...genericSubsonic,
flavour: () => "navidrome", flavour: () => "navidrome",
@@ -964,7 +965,7 @@ export class Subsonic implements MusicService {
TE.tryCatch( TE.tryCatch(
() => () =>
axios.post( axios.post(
`${this.url}/auth/login`, this.url.append({ pathname: '/auth/login' }).href(),
_.pick(credentials, "username", "password") _.pick(credentials, "username", "password")
), ),
() => new AuthFailure("Failed to get bearerToken") () => new AuthFailure("Failed to get bearerToken")

View File

@@ -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("getting genres", () => {
describe("when there are none", () => { describe("when there are none", () => {
beforeEach(() => { beforeEach(() => {