simple sonos smapi soap webservice registered

This commit is contained in:
simojenki
2021-02-08 20:45:17 +11:00
parent 2ed2fce280
commit 302efd2878
8 changed files with 2298 additions and 19 deletions

33
tests/bonob_client.ts Normal file
View File

@@ -0,0 +1,33 @@
import getPort from "get-port";
import { createClientAsync } from "soap";
import sonos, { bonobService } from "../src/sonos";
import server from "../src/server";
import logger from "../src/logger";
const bonob = bonobService("bonob-test", 247, "http://localhost:1234");
const app = server(sonos("disabled"), bonob);
getPort().then((port) => {
logger.debug(`Starting on port ${port}`);
app.listen(port);
createClientAsync(`http://localhost:${port}/ws?wsdl`, {
endpoint: `http://localhost:${port}/ws`,
}).then((client) => {
client
.getSessionIdAsync(
{ username: "bob", password: "foo" }
)
.then(
([{ username, sessionId }]: [
{ username: string; sessionId: string }
]) => {
console.log(`${username} has sessionId=${sessionId}`);
}
);
console.log(`done`);
});
});

View File

@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es2019",
"baseUrl": "./",
"module": "commonjs",
"experimentalDecorators": true,

54
tests/ws.test.ts Normal file
View File

@@ -0,0 +1,54 @@
import request from "supertest";
import makeServer from "../src/server";
import { SONOS_DISABLED } from "../src/sonos";
import { aService } from "./builders";
import { createClientAsync } from "soap";
describe("ws", () => {
describe("can call getSessionId", () => {
it("should do something", async () => {
const server = makeServer(SONOS_DISABLED, aService());
const { username, sessionId } = await createClientAsync(
`http://localhost/ws?wsdl`,
{
endpoint: `http://localhost/ws`,
httpClient: {
request: (
rurl: string,
data: any,
callback: (error: any, res?: any, body?: any) => any,
exheaders?: any
) => {
const withoutHost = rurl.replace("http://localhost", "");
const req =
data == null
? request(server).get(withoutHost).send()
: request(server).post(withoutHost).send(data);
req
.set(exheaders || {})
.then((response) => callback(null, response, response.text))
.catch(callback);
},
},
}
).then((client) =>
client
.getSessionIdAsync({ username: "bob", password: "foo" })
.then(
([{ username, sessionId }]: [
{ username: string; sessionId: string }
]) => ({
username,
sessionId,
})
)
);
expect(username).toEqual("bob");
expect(sessionId).toEqual("123");
});
});
});