Skip to content

Commit

Permalink
fix: use proper runId for paginated queries (#42)
Browse files Browse the repository at this point in the history
* fix: runId was required in config

* fix: runId replaced by existingRun.id

Co-authored-by: Jérémy Torralba <[email protected]>
  • Loading branch information
trooperjey01 and jeremyagatha authored Oct 12, 2022
1 parent 07f257d commit ad427e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const prepareRun = async (
);
}
} else if (existingRun) {
const tests = await getAllTests(testrailAPI, config);
const tests = await getAllTests(testrailAPI, existingRun.id);
const currentCaseIds = tests?.map((test) => test.case_id) || [];
const additionalDescription = "\n" + runDescription;
const newDescription = existingRun.description
Expand Down Expand Up @@ -271,7 +271,7 @@ class TestcafeTestrailReporter {
const { value: results } = await throwOnApiError(
testrailAPI.addResultsForCases(runId, resultsToPush)
);
const tests = await getAllTests(testrailAPI, this.config);
const tests = await getAllTests(testrailAPI, runId);

if (this.config.uploadScreenshots) {
await uploadScreenshots({
Expand Down
6 changes: 3 additions & 3 deletions src/utils/testrail-getResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export const getAllCases = async (testrailAPI: TestRail, config: Config) => {
return cases;
};

export const getAllTests = async (testrailAPI: TestRail, config: Config) => {
export const getAllTests = async (testrailAPI: TestRail, runId: number) => {
let { value: testsResult } = await throwOnApiError(
testrailAPI.getTests(config.runId)
testrailAPI.getTests(runId)
);
let tests = testsResult.tests || [];
let offsetVal = 0;
while (testsResult._links.next !== null) {
offsetVal += 250;
({ value: testsResult } = await throwOnApiError(
testrailAPI.getTests(config.runId, { offset: offsetVal })
testrailAPI.getTests(runId, { offset: offsetVal })
));
tests = tests.concat(testsResult.tests);
}
Expand Down

0 comments on commit ad427e3

Please sign in to comment.