Skip to content

Commit

Permalink
Fix PaginatedResult.next() behaviour when no next page
Browse files Browse the repository at this point in the history
It is meant to return `null` (per TG4 and our documentation comments),
but was returning `undefined`.

Resolves #1542.
  • Loading branch information
lawrence-forooghian committed Dec 11, 2023
1 parent 95ef9e2 commit 8bd1706
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3460,13 +3460,13 @@ declare namespace Types {
*
* @param results - A function which, upon success, will be fulfilled with a page of results for message and presence history, stats, and REST presence requests. Upon failure, the function will be called with information about the error.
*/
next(results: paginatedResultCallback<T>): void;
next(results: StandardCallback<PaginatedResult<T> | null>): void;
/**
* Returns a new `PaginatedResult` loaded with the next page of results. If there are no further pages, then `null` is returned.
*
* @returns A promise which, upon success, will be fulfilled with a page of results for message and presence history, stats, and REST presence requests. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
*/
next(): Promise<PaginatedResult<T>>;
next(): Promise<PaginatedResult<T> | null>;
/**
* Returns the `PaginatedResult` for the current page of results.
*
Expand Down
2 changes: 1 addition & 1 deletion src/common/lib/client/paginatedresource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class PaginatedResult<T> {
if ('next' in relParams) {
self.get(relParams.next, callback);
} else {
callback(null);
callback(null, null);
}
};

Expand Down
20 changes: 20 additions & 0 deletions test/rest/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,26 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) {
}
});

restTestOnJsonMsgpack('history_no_next_page', function (done, rest, channelName) {
const channel = rest.channels.get(channelName);

channel.history(function (err, firstPage) {
if (err) {
done(err);
return;
}
firstPage.next(function (err, secondPage) {
if (err) {
done(err);
return;
}

expect(secondPage).to.equal(null);
done();
});
});
});

if (typeof Promise !== 'undefined') {
it('historyPromise', function (done) {
var rest = helper.AblyRest({ promises: true });
Expand Down

0 comments on commit 8bd1706

Please sign in to comment.