forked from octokit/plugin-paginate-graphql.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve implementation of deepFindPathToProperty function
Adopt non-recursive path calculation. Fixes octokit#58
- Loading branch information
Showing
2 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { findPaginatedResourcePath } from "../src/object-helpers"; | ||
import { MissingPageInfo } from "../src/errors"; | ||
|
||
describe("findPaginatedResourcePath()", (): void => {}); | ||
|
||
describe("findPaginatedResourcePath()", (): void => { | ||
it("returns empty array if no pageInfo object exists", async (): Promise<void> => { | ||
expect(() => { | ||
findPaginatedResourcePath({ test: { nested: "value" } }); | ||
}).toThrow(MissingPageInfo); | ||
}); | ||
|
||
it("returns correct path for deeply nested pageInfo", async (): Promise<void> => { | ||
const obj = { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
a: { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
b: { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
c: { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
d: { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
e: { | ||
"branch-out": { x: { y: { z: {} } } }, | ||
f: { | ||
pageInfo: { | ||
endCursor: "Y3Vyc29yOnYyOpEB", | ||
hasNextPage: false, | ||
}, | ||
"branch-out": { x: { y: { z: {} } } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(findPaginatedResourcePath(obj)).toEqual([ | ||
"a", | ||
"b", | ||
"c", | ||
"d", | ||
"e", | ||
"f", | ||
]); | ||
}); | ||
|
||
it("returns correct path for shallow nested pageInfo", async (): Promise<void> => { | ||
const obj = { | ||
a: { | ||
pageInfo: { | ||
endCursor: "Y3Vyc29yOnYyOpEB", | ||
hasNextPage: false, | ||
}, | ||
"branch-out": { x: { y: { z: {} } } }, | ||
}, | ||
"branch-out": { x: { y: { z: {} } } }, | ||
}; | ||
expect(findPaginatedResourcePath(obj)).toEqual(["a"]); | ||
}); | ||
|
||
it("returns correct path for pageInfo in the root object", async (): Promise<void> => { | ||
const obj = { | ||
pageInfo: { | ||
endCursor: "Y3Vyc29yOnYyOpEB", | ||
hasNextPage: false, | ||
}, | ||
"branch-out": { x: { y: { z: {} } } }, | ||
}; | ||
expect(findPaginatedResourcePath(obj)).toEqual([]); | ||
}); | ||
}); |