From d1fe139c66fc03afae6f47fa656279e25df22cbb Mon Sep 17 00:00:00 2001 From: Zach Kauffman Date: Fri, 3 May 2024 12:10:17 -0400 Subject: [PATCH] Added "offset" to Result. While working with the SDK, I realized that there is no way to get the offset, so if you don't retain that when passing it to the SDK for querying, the value is lost. * Added a new "private" field, `_offset`, which holds the offset value from the result XML, if it is present. * Added a public getter for the `_offset` field. * Updated the constructor so that if the Result XML has an `offset` attribute, it attempts to parse it to an integer and then set it to the `_offset` field. * Updated ResultTest to add tests for the expected `offset` data. --- src/Xml/Response/Result.ts | 9 +++++++++ test/Xml/Response/ResultTest.ts | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Xml/Response/Result.ts b/src/Xml/Response/Result.ts index 7923542a..55d0b0fb 100644 --- a/src/Xml/Response/Result.ts +++ b/src/Xml/Response/Result.ts @@ -64,6 +64,11 @@ export default class Result { return this._numRemaining; } + private _offset: number; + get offset(): number { + return this._offset; + } + private _resultId: string; get resultId(): string { return this._resultId; @@ -151,6 +156,10 @@ export default class Result { this._numRemaining = parseInt(dataAttr["numremaining"], 10); } + if (dataAttr.hasOwnProperty("offset")) { + this._offset = parseInt(dataAttr["offset"], 10); + } + if (dataAttr.hasOwnProperty("resultId")) { this._resultId = dataAttr["resultId"].toString(); } diff --git a/test/Xml/Response/ResultTest.ts b/test/Xml/Response/ResultTest.ts index b98b040d..8af2101a 100644 --- a/test/Xml/Response/ResultTest.ts +++ b/test/Xml/Response/ResultTest.ts @@ -442,7 +442,7 @@ describe("Result", () => { success readByQuery 818b0a96-3faf-4931-97e6-1cf05818ea44 - + 8 C1234 @@ -471,6 +471,7 @@ describe("Result", () => { chai.assert.equal(result.count, 1); chai.assert.equal(result.totalCount, 2); chai.assert.equal(result.numRemaining, 1); + chai.assert.equal(result.offset, 0); chai.assert.equal(result.resultId, "myResultId"); chai.assert.equal(result.data.length, 1); }); @@ -497,7 +498,7 @@ describe("Result", () => { success readByQuery 818b0a96-3faf-4931-97e6-1cf05818ea44 - + 8 C1234 @@ -543,6 +544,7 @@ describe("Result", () => { chai.assert.equal(result.count, 2); chai.assert.equal(result.totalCount, 3); chai.assert.equal(result.numRemaining, 1); + chai.assert.equal(result.offset, 0); chai.assert.equal(result.resultId, "myResultId"); chai.assert.equal(result.data.length, 2); });