Skip to content

Commit

Permalink
fix(js-sdk): make body in readChanges optional (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris authored Feb 6, 2024
2 parents 1d2a6b0 + 4716dfd commit 30f38e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions config/clients/js/template/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class {{appShortName}}Client extends BaseAPI {

/**
* Read Changes - Read the list of historical relationship tuple writes and deletes
* @param {ClientReadChangesRequest} body
* @param {ClientReadChangesRequest} [body]
* @param {ClientRequestOpts & PaginationOptions} [options]
* @param {number} [options.pageSize]
* @param {string} [options.continuationToken]
Expand All @@ -312,8 +312,8 @@ export class {{appShortName}}Client extends BaseAPI {
* @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request
* @param {number} [options.retryParams.minWaitInMs] - Override the minimum wait before a retry is initiated
*/
async readChanges(body: ClientReadChangesRequest, options: ClientRequestOpts & PaginationOptions = {}): PromiseResult<ReadChangesResponse> {
return this.api.readChanges(body.type, options.pageSize, options.continuationToken, options);
async readChanges(body?: ClientReadChangesRequest, options: ClientRequestOpts & PaginationOptions = {}): PromiseResult<ReadChangesResponse> {
return this.api.readChanges(body?.type, options.pageSize, options.continuationToken, options);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions config/clients/js/template/tests/client.test.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ describe("{{appTitleCaseName}} Client", () => {
expect(scope.isDone()).toBe(true);
expect(response).toMatchObject({ changes: expect.arrayContaining([]) });
});

it("should properly call the {{appShortName}} ReadChanges API with no type", async () => {
const pageSize = 25;
const continuationToken = "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==";
const scope = nocks.readChanges(baseConfig.storeId!, "", pageSize, continuationToken);
expect(scope.isDone()).toBe(false);
const response = await fgaClient.readChanges(undefined, { pageSize, continuationToken });

expect(scope.isDone()).toBe(true);
expect(response).toMatchObject({ changes: expect.arrayContaining([]) });
});
});

describe("Read", () => {
Expand Down
4 changes: 2 additions & 2 deletions config/clients/js/template/tests/helpers/nocks.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export const getNocks = ((nock: typeof Nock) => ({
return nock(basePath)
.get(`/stores/${storeId}/changes`)
.query({
type,
page_size: pageSize,
continuation_token: contToken
continuation_token: contToken,
...(type ? { type } : { })
})
.reply(200, {
changes: [{
Expand Down

0 comments on commit 30f38e4

Please sign in to comment.