Просмотр исходного кода

feat: XML validation unit test

Sv443 4 месяцев назад
Родитель
Сommit
7a96b0ada0
1 измененных файлов с 19 добавлено и 0 удалено
  1. 19 0
      test/search.spec.ts

+ 19 - 0
test/search.spec.ts

@@ -1,4 +1,5 @@
 import { randomBytes } from "crypto";
+import { XMLParser } from "fast-xml-parser";
 import { baseUrl, defaultFetchOpts } from "./constants";
 import { checkSongProps } from "./hooks";
 
@@ -17,6 +18,24 @@ describe("Search routes", () => {
     checkSongProps(body);
   });
 
+  //#region /search/top xml
+
+  it("Top search with format=xml yields valid XML", async () => {
+    const res = await fetch(`${baseUrl}/search/top?format=xml&q=Lil Nas X - LIGHT AGAIN!`, defaultFetchOpts);
+    const body = await res.text();
+
+    expect(res.status).toBe(200);
+
+    const parsed = new XMLParser().parse(body);
+
+    expect(typeof parsed?.data).toBe("object");
+
+    expect(parsed?.data?.error).toEqual(false);
+    expect(parsed?.data?.matches).toEqual(1);
+
+    checkSongProps(parsed?.data);
+  });
+
   //#region /search
 
   it("Regular search yields <=10 results", async () => {