Skip to content

Commit

Permalink
fix: support branch pagination (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpshr authored Feb 26, 2020
1 parent 7789a92 commit 34e6a42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abstract-sdk",
"version": "8.0.0-beta.11",
"version": "8.0.0-beta.12",
"description": "Universal JavaScript bindings for the Abstract API and CLI",
"keywords": [
"abstract",
Expand Down
7 changes: 4 additions & 3 deletions src/endpoints/Branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import querystring from "query-string";
import type {
Branch,
BranchDescriptor,
ListOptions,
ProjectDescriptor,
RequestOptions
} from "../types";
Expand Down Expand Up @@ -45,16 +46,16 @@ export default class Branches extends Endpoint {
list(
descriptor?: ProjectDescriptor,
options: {
...RequestOptions,
...ListOptions,
filter?: "active" | "archived" | "mine",
search?: string
} = {}
) {
const { filter, search, ...requestOptions } = options;
const { limit, offset, filter, search, ...requestOptions } = options;

return this.configureRequest<Promise<Branch[]>>({
api: async () => {
const query = querystring.stringify({ filter, search });
const query = querystring.stringify({ limit, offset, filter, search });
const requestUrl = descriptor
? `projects/${descriptor.projectId}/branches/?${query}`
: `branches/?${query}`;
Expand Down
23 changes: 23 additions & 0 deletions tests/endpoints/Branches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ describe("branches", () => {
]);
});

test("api - pagination", async () => {
mockAPI("/branches/?offset=5&limit=10", {
data: {
branches: [
{
id: "branch-id"
}
]
}
});

const response = await API_CLIENT.branches.list(undefined, {
offset: 5,
limit: 10
});

expect(response).toEqual([
{
id: "branch-id"
}
]);
});

test("cli", async () => {
mockCLI(["branches", "list", "--project-id=project-id"], {
branches: [
Expand Down

0 comments on commit 34e6a42

Please sign in to comment.