hotfix: correct traversal paths and improve test assertions
Fixed incorrect object traversal paths in `YTMusic.getHome` method to properly navigate through nested JSON. Enhanced `getHome.spec.ts` by adding a check for non-empty array of `HomePageContent` and logging the length of the retrieved contents.
This commit is contained in:
parent
f1eaeb7143
commit
9b30a9e5f6
|
|
@ -510,7 +510,7 @@ export default class YTMusic {
|
|||
public async getHome(): Promise<HomePageContent[]> {
|
||||
const results: HomePageContent[] = []
|
||||
const page = await this.constructRequest("browse", { browseId: FE_MUSIC_HOME })
|
||||
traverseList(page, "contents").forEach(content => {
|
||||
traverseList(page, "sectionListRenderer", "contents").forEach(content => {
|
||||
const parsed = Parser.parseMixedContent(content)
|
||||
parsed && results.push(parsed)
|
||||
})
|
||||
|
|
@ -518,7 +518,7 @@ export default class YTMusic {
|
|||
let continuation = traverseString(page, "continuation")
|
||||
while (continuation) {
|
||||
const nextPage = await this.constructRequest("browse", {}, { continuation })
|
||||
traverseList(nextPage, "contents").forEach(content => {
|
||||
traverseList(nextPage, "sectionListContinuation", "contents").forEach(content => {
|
||||
const parsed = Parser.parseMixedContent(content)
|
||||
parsed && results.push(parsed)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ export default class AlbumParser {
|
|||
|
||||
public static parseSearchResult(item: any): AlbumDetailed {
|
||||
const columns = traverseList(item, "flexColumns", "runs").flat()
|
||||
columns.push(item)
|
||||
|
||||
// No specific way to identify the title
|
||||
const title = columns[0]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { arrayOf, Problem, Type } from "arktype"
|
||||
import { equal } from "assert"
|
||||
import { equal, ok } from "assert"
|
||||
import { afterAll, beforeEach, describe, it } from "bun:test"
|
||||
|
||||
import { HomePageContent } from "../@types/types"
|
||||
|
|
@ -25,6 +25,7 @@ const expect = (data: any, type: Type) => {
|
|||
}
|
||||
equal(result.problems, undefined)
|
||||
}
|
||||
|
||||
const ytmusic = new YTMusic()
|
||||
beforeEach(() => {
|
||||
const index = 0
|
||||
|
|
@ -34,8 +35,10 @@ beforeEach(() => {
|
|||
describe(`Query: ${FE_MUSIC_HOME}`, () => {
|
||||
configs.forEach(config => {
|
||||
it(`Get ${config.GL} ${config.HL}`, async () => {
|
||||
const page = await ytmusic.getHome()
|
||||
expect(page, arrayOf(HomePageContent))
|
||||
const homePageContents = await ytmusic.getHome()
|
||||
ok(homePageContents.length)
|
||||
expect(homePageContents, arrayOf(HomePageContent))
|
||||
console.log("Length: ", homePageContents.length)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue