Remove xpath-ts from project

This commit is contained in:
simojenki
2021-03-01 17:46:49 +11:00
parent 007db24713
commit 333c9eace9
4 changed files with 69 additions and 52 deletions

View File

@@ -24,8 +24,7 @@
"underscore":"^1.12.0", "underscore":"^1.12.0",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"winston": "^3.3.3", "winston": "^3.3.3",
"x2js": "^3.4.0", "x2js": "^3.4.0"
"xmldom-ts": "^0.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.2.14", "@types/chai": "^4.2.14",
@@ -39,8 +38,7 @@
"supertest": "^6.1.3", "supertest": "^6.1.3",
"ts-jest": "^26.4.4", "ts-jest": "^26.4.4",
"ts-mockito": "^2.6.1", "ts-mockito": "^2.6.1",
"ts-node": "^9.1.1", "ts-node": "^9.1.1"
"xpath-ts": "^1.3.13"
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",

View File

@@ -98,7 +98,12 @@ function server(
<stringtables xmlns="http://sonos.com/sonosapi"> <stringtables xmlns="http://sonos.com/sonosapi">
<stringtable rev="1" xml:lang="en-US"> <stringtable rev="1" xml:lang="en-US">
<string stringId="AppLinkMessage">Linking sonos with bonob</string> <string stringId="AppLinkMessage">Linking sonos with bonob</string>
<string stringId="string2">string2</string>
</stringtable> </stringtable>
<stringtable rev="1" xml:lang="fr-FR">
<string stringId="AppLinkMessage">Linking sonos with bonob fr</string>
<string stringId="string2">string2 fr</string>
</stringtable>
</stringtables> </stringtables>
`); `);
}); });

View File

@@ -1,23 +1,29 @@
import crypto from "crypto"; import crypto from "crypto";
import request from "supertest"; import request from "supertest";
import { Client, createClientAsync } from "soap"; import { Client, createClientAsync } from "soap";
import X2JS from "x2js";
import { DOMParserImpl } from "xmldom-ts";
import * as xpath from "xpath-ts";
import { InMemoryLinkCodes, LinkCodes } from "../src/link_codes"; import { InMemoryLinkCodes, LinkCodes } from "../src/link_codes";
import makeServer from "../src/server"; import makeServer from "../src/server";
import { bonobService, SONOS_DISABLED } from "../src/sonos"; import { bonobService, SONOS_DISABLED } from "../src/sonos";
import { STRINGS_ROUTE, LOGIN_ROUTE, getMetadataResult, container } from "../src/smapi"; import {
STRINGS_ROUTE,
LOGIN_ROUTE,
getMetadataResult,
container,
} from "../src/smapi";
import { aService, BLONDIE, BOB_MARLEY, getAppLinkMessage, someCredentials } from "./builders"; import {
aService,
BLONDIE,
BOB_MARLEY,
getAppLinkMessage,
someCredentials,
} from "./builders";
import { InMemoryMusicService } from "./in_memory_music_service"; import { InMemoryMusicService } from "./in_memory_music_service";
import supersoap from "./supersoap"; import supersoap from "./supersoap";
import { AuthSuccess } from "../src/music_service"; import { AuthSuccess } from "../src/music_service";
const parseXML = (value: string) => new DOMParserImpl().parseFromString(value);
const select = xpath.useNamespaces({ sonos: "http://sonos.com/sonosapi" });
describe("service config", () => { describe("service config", () => {
describe("strings.xml", () => { describe("strings.xml", () => {
const server = makeServer( const server = makeServer(
@@ -32,13 +38,11 @@ describe("service config", () => {
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
const xml = parseXML(res.text); const strings: any = new X2JS({
const x = select( arrayAccessFormPaths: ["stringtables", "stringtables.stringtable"],
"//sonos:string[@stringId='AppLinkMessage']/text()", }).xml2js(res.text);
xml
) as Node[]; expect(strings.stringtables.stringtable[0].string[0]._stringId).toEqual("AppLinkMessage")
expect(x.length).toEqual(1);
expect(x[0]!.nodeValue).toEqual("Linking sonos with bonob");
}); });
}); });
}); });
@@ -289,10 +293,10 @@ describe("api", () => {
const username = "userThatGetsDeleted"; const username = "userThatGetsDeleted";
const password = "password1"; const password = "password1";
musicService.hasUser({ username, password }); musicService.hasUser({ username, password });
const token = await musicService.generateToken({ const token = (await musicService.generateToken({
username, username,
password, password,
}) as AuthSuccess; })) as AuthSuccess;
musicService.hasNoUsers(); musicService.hasNoUsers();
const ws = await createClientAsync(`${service.uri}?wsdl`, { const ws = await createClientAsync(`${service.uri}?wsdl`, {
@@ -321,10 +325,10 @@ describe("api", () => {
beforeEach(async () => { beforeEach(async () => {
musicService.hasUser({ username, password }); musicService.hasUser({ username, password });
token = await musicService.generateToken({ token = (await musicService.generateToken({
username, username,
password, password,
}) as AuthSuccess; })) as AuthSuccess;
ws = await createClientAsync(`${service.uri}?wsdl`, { ws = await createClientAsync(`${service.uri}?wsdl`, {
endpoint: service.uri, endpoint: service.uri,
httpClient: supersoap(server, rootUrl), httpClient: supersoap(server, rootUrl),
@@ -339,12 +343,14 @@ describe("api", () => {
index: 0, index: 0,
count: 100, count: 100,
}); });
expect(root[0]).toEqual(getMetadataResult({ expect(root[0]).toEqual(
mediaCollection: [ getMetadataResult({
container({ id: "artists", title: "Artists" }), mediaCollection: [
container({ id: "albums", title: "Albums" }), container({ id: "artists", title: "Artists" }),
], container({ id: "albums", title: "Albums" }),
})); ],
})
);
}); });
}); });
@@ -357,9 +363,13 @@ describe("api", () => {
index: 0, index: 0,
count: 100, count: 100,
}); });
expect(artists[0]).toEqual(getMetadataResult({ expect(artists[0]).toEqual(
mediaCollection: [BLONDIE, BOB_MARLEY].map(it => container({ id: `artist:${it.id}`, title: it.name })), getMetadataResult({
})); mediaCollection: [BLONDIE, BOB_MARLEY].map((it) =>
container({ id: `artist:${it.id}`, title: it.name })
),
})
);
}); });
}); });
@@ -372,9 +382,16 @@ describe("api", () => {
index: 0, index: 0,
count: 100, count: 100,
}); });
expect(albums[0]).toEqual(getMetadataResult({ expect(albums[0]).toEqual(
mediaCollection: [...BLONDIE.albums, ...BOB_MARLEY.albums].map(it => container({ id: `album:${it.id}`, title: it.name })), getMetadataResult({
})); mediaCollection: [
...BLONDIE.albums,
...BOB_MARLEY.albums,
].map((it) =>
container({ id: `album:${it.id}`, title: it.name })
),
})
);
}); });
}); });
@@ -390,15 +407,22 @@ describe("api", () => {
index: 2, index: 2,
count: 2, count: 2,
}); });
expect(albums[0]).toEqual(getMetadataResult({ expect(albums[0]).toEqual(
mediaCollection: [ getMetadataResult({
container({ id: `album:${BOB_MARLEY.albums[0]!.id}`, title: BOB_MARLEY.albums[0]!.name }), mediaCollection: [
container({ id: `album:${BOB_MARLEY.albums[1]!.id}`, title: BOB_MARLEY.albums[1]!.name }), container({
], id: `album:${BOB_MARLEY.albums[0]!.id}`,
})); title: BOB_MARLEY.albums[0]!.name,
}),
container({
id: `album:${BOB_MARLEY.albums[1]!.id}`,
title: BOB_MARLEY.albums[1]!.name,
}),
],
})
);
}); });
}); });
}); });
}); });
}); });

View File

@@ -5018,11 +5018,6 @@ xmlchars@^2.2.0:
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw== integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==
xmldom-ts@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/xmldom-ts/-/xmldom-ts-0.3.1.tgz#a70df029e44e9af3c03ba22d88f174a953830091"
integrity sha512-dmEBAK3Msm+BPVZOiwhXCyM0/q3BeiI4eoAPj2Us1nDhsPPhePtZ5RkgEdngNQQFp3j6QFKMLHlBIRUxdpomcQ==
xmldom@0.1.27: xmldom@0.1.27:
version "0.1.27" version "0.1.27"
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9" resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9"
@@ -5033,11 +5028,6 @@ xmldom@^0.1.19:
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff" resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ== integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
xpath-ts@^1.3.13:
version "1.3.13"
resolved "https://registry.yarnpkg.com/xpath-ts/-/xpath-ts-1.3.13.tgz#abca4f15dd7010161acf5b9cd01566f7b8d9541f"
integrity sha512-eNVXzDWbCV9KEB6fGNQ3qHFGC9PWBH7y2h13vZ+CMPNqOTZ+fgYTG4Sb0p5bVHiAwZrzgE6/tx987003P3dYpA==
xpath@0.0.27: xpath@0.0.27:
version "0.0.27" version "0.0.27"
resolved "https://registry.yarnpkg.com/xpath/-/xpath-0.0.27.tgz#dd3421fbdcc5646ac32c48531b4d7e9d0c2cfa92" resolved "https://registry.yarnpkg.com/xpath/-/xpath-0.0.27.tgz#dd3421fbdcc5646ac32c48531b4d7e9d0c2cfa92"