From c92ec058f31d8170a49050dbbf2f0cae0003902a Mon Sep 17 00:00:00 2001 From: Corneliu Duplachi Date: Sun, 5 Apr 2026 22:53:19 +0300 Subject: [PATCH] refactor!: switch to ESM and named exports feat: allow undefined in payloads fix: share rate-limit state across instance methods fix!: make addAttachment* retryable (limited types) chore!: drop node-fetch and form-data chore: merge commands into TestRail client chore: update CI to Node 22/24 and actions v6 --- .github/workflows/nodejs.yml | 9 +- .github/workflows/release-please.yml | 15 +- README.md | 5 +- package.json | 69 +-- rollup.config.js | 82 ---- src/TestRail.ts | 451 +++++++++++------- src/TestRailConfig.ts | 5 + src/TestRailCtx.ts | 12 - src/groups/attachments.ts | 58 --- src/groups/bdd.ts | 11 - src/groups/case-fields.ts | 11 - src/groups/case-types.ts | 7 - src/groups/cases.ts | 48 -- src/groups/configurations.ts | 31 -- src/groups/datasets.ts | 26 - src/groups/groups.ts | 26 - src/groups/index.ts | 26 - src/groups/milestones.ts | 26 - src/groups/plans.ts | 54 --- src/groups/priorities.ts | 7 - src/groups/projects.ts | 26 - src/groups/reports.ts | 11 - src/groups/result-fields.ts | 7 - src/groups/results.ts | 38 -- src/groups/roles.ts | 10 - src/groups/runs.ts | 30 -- src/groups/sections.ts | 30 -- src/groups/shared-steps.ts | 32 -- src/groups/statuses.ts | 14 - src/groups/suites.ts | 26 - src/groups/templates.ts | 7 - src/groups/tests.ts | 14 - src/groups/users.ts | 30 -- src/groups/variables.ts | 22 - src/internal/request.ts | 183 ++++--- src/payload/index.ts | 9 +- src/payload/request/AddAttachment.ts | 13 +- src/payload/request/AddCase.ts | 18 +- src/payload/request/AddCaseField.ts | 52 +- src/payload/request/AddConfig.ts | 2 +- src/payload/request/AddConfigGroup.ts | 6 +- src/payload/request/AddDataset.ts | 20 +- src/payload/request/AddGroup.ts | 8 +- src/payload/request/AddMilestone.ts | 16 +- src/payload/request/AddPlan.ts | 10 +- src/payload/request/AddPlanEntry.ts | 24 +- src/payload/request/AddProject.ts | 12 +- src/payload/request/AddResult.ts | 16 +- src/payload/request/AddResultForCase.ts | 8 +- src/payload/request/AddResultForTest.ts | 8 +- src/payload/request/AddResults.ts | 8 +- src/payload/request/AddResultsForCases.ts | 8 +- src/payload/request/AddRun.ts | 10 +- src/payload/request/AddRunToPlanEntry.ts | 16 +- src/payload/request/AddSection.ts | 10 +- src/payload/request/AddSharedStep.ts | 20 +- src/payload/request/AddSuite.ts | 8 +- src/payload/request/AddUser.ts | 22 +- src/payload/request/AddVariable.ts | 8 +- src/payload/request/CaseFilters.ts | 35 +- src/payload/request/CopyCasesToSection.ts | 6 +- src/payload/request/DeleteCases.ts | 6 +- src/payload/request/DeleteSharedStep.ts | 6 +- src/payload/request/MilestoneFilters.ts | 11 +- src/payload/request/MoveCasesToSection.ts | 6 +- src/payload/request/MoveSection.ts | 8 +- src/payload/request/Pagination.ts | 8 +- src/payload/request/PlanFilters.ts | 17 +- src/payload/request/ProjectFilters.ts | 9 +- src/payload/request/ResultFilters.ts | 11 +- src/payload/request/ResultForRunFilters.ts | 17 +- src/payload/request/RunFilters.ts | 21 +- src/payload/request/SectionFilters.ts | 9 +- src/payload/request/SharedStepFilters.ts | 19 +- src/payload/request/TestFilters.ts | 9 +- src/payload/request/UpdateCase.ts | 8 +- src/payload/request/UpdateCases.ts | 8 +- src/payload/request/UpdateConfig.ts | 2 +- src/payload/request/UpdateConfigGroup.ts | 2 +- src/payload/request/UpdateMilestone.ts | 10 +- src/payload/request/UpdatePlan.ts | 10 +- src/payload/request/UpdatePlanEntry.ts | 16 +- src/payload/request/UpdateProject.ts | 2 +- src/payload/request/UpdateRun.ts | 16 +- src/payload/request/UpdateRunInPlanEntry.ts | 14 +- src/payload/request/UpdateSection.ts | 8 +- src/payload/request/UpdateSharedStep.ts | 2 +- src/payload/request/UpdateSuite.ts | 2 +- src/payload/request/UserFilters.ts | 9 +- src/payload/request/index.ts | 106 ++-- src/payload/response/AttachmentForCase.ts | 2 +- src/payload/response/AttachmentForPlan.ts | 2 +- .../response/AttachmentForPlanEntry.ts | 2 +- src/payload/response/AttachmentForRun.ts | 2 +- src/payload/response/AttachmentForTest.ts | 2 +- src/payload/response/CaseField.ts | 2 +- src/payload/response/CaseHistory.ts | 2 +- src/payload/response/Config.ts | 2 +- src/payload/response/Dataset.ts | 2 +- src/payload/response/FieldConfig.ts | 4 +- src/payload/response/Plan.ts | 2 +- src/payload/response/PlanEntry.ts | 2 +- src/payload/response/ResultField.ts | 2 +- src/payload/response/SharedStepHistory.ts | 2 +- src/payload/response/index.ts | 82 ++-- test/_helper.ts | 24 +- test/attachments.ts | 21 +- test/bdd.ts | 11 +- test/caseFields.ts | 5 +- test/caseTypes.ts | 5 +- test/cases.ts | 13 +- test/configurations.ts | 11 +- test/dataset.ts | 9 +- test/errors.ts | 9 +- test/groups.ts | 7 +- test/milestones.ts | 9 +- test/pagination.ts | 11 +- test/plans.ts | 13 +- test/priorities.ts | 5 +- test/projects.ts | 7 +- test/reports.ts | 9 +- test/resultFields.ts | 5 +- test/results.ts | 11 +- test/roles.ts | 5 +- test/runs.ts | 9 +- test/sections.ts | 9 +- test/sharedStep.ts | 9 +- test/statuses.ts | 5 +- test/suites.ts | 9 +- test/templates.ts | 7 +- test/tests.ts | 9 +- test/users.ts | 7 +- test/variables.ts | 9 +- tsconfig.json | 20 +- 134 files changed, 1008 insertions(+), 1591 deletions(-) delete mode 100644 rollup.config.js create mode 100644 src/TestRailConfig.ts delete mode 100644 src/TestRailCtx.ts delete mode 100644 src/groups/attachments.ts delete mode 100644 src/groups/bdd.ts delete mode 100644 src/groups/case-fields.ts delete mode 100644 src/groups/case-types.ts delete mode 100644 src/groups/cases.ts delete mode 100644 src/groups/configurations.ts delete mode 100644 src/groups/datasets.ts delete mode 100644 src/groups/groups.ts delete mode 100644 src/groups/index.ts delete mode 100644 src/groups/milestones.ts delete mode 100644 src/groups/plans.ts delete mode 100644 src/groups/priorities.ts delete mode 100644 src/groups/projects.ts delete mode 100644 src/groups/reports.ts delete mode 100644 src/groups/result-fields.ts delete mode 100644 src/groups/results.ts delete mode 100644 src/groups/roles.ts delete mode 100644 src/groups/runs.ts delete mode 100644 src/groups/sections.ts delete mode 100644 src/groups/shared-steps.ts delete mode 100644 src/groups/statuses.ts delete mode 100644 src/groups/suites.ts delete mode 100644 src/groups/templates.ts delete mode 100644 src/groups/tests.ts delete mode 100644 src/groups/users.ts delete mode 100644 src/groups/variables.ts diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 71276ec..cf2f983 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -7,14 +7,13 @@ jobs: strategy: matrix: node-version: - - 14.x - - 16.x - - 18.x + - 22.x + - 24.x steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - run: npm install - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm test diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index c5d3890..d0037de 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -3,6 +3,9 @@ on: push: branches: - main +permissions: + id-token: write + contents: read jobs: release-please: runs-on: ubuntu-latest @@ -11,18 +14,16 @@ jobs: id: release with: token: ${{ secrets.GITHUB_TOKEN }} - package-name: '@dlenroc/testrail' + package-name: "@dlenroc/testrail" release-type: node - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 if: ${{ steps.release.outputs.release_created }} - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v6 if: ${{ steps.release.outputs.release_created }} with: - node-version: 18 - registry-url: https://registry.npmjs.org + node-version: "24" + registry-url: "https://registry.npmjs.org" - run: npm install if: ${{ steps.release.outputs.release_created }} - run: npm publish --access public if: ${{ steps.release.outputs.release_created }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index c222a9a..f85c714 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @dlenroc/testrail · [![NPM Version](https://img.shields.io/npm/v/@dlenroc/testrail)](https://www.npmjs.com/package/@dlenroc/testrail) [![Supported Node.js version](https://img.shields.io/node/v/@dlenroc/testrail)](https://github.com/dlenroc/node-testrail-api/actions?query=workflow%3A"Node.js+CI") +# @dlenroc/testrail · [![NPM Version](https://img.shields.io/npm/v/@dlenroc/testrail)](https://www.npmjs.com/package/@dlenroc/testrail) ## Installation @@ -9,8 +9,7 @@ npm install @dlenroc/testrail --save ## Example ```typescript -// import TestRail from '@dlenroc/testrail'; -// const TestRail = require('@dlenroc/testrail'); +import { TestRail } from '@dlenroc/testrail'; const api = new TestRail({ host: 'https://{organization}.testrail.net', diff --git a/package.json b/package.json index d1e4a43..46d61b1 100644 --- a/package.json +++ b/package.json @@ -1,58 +1,39 @@ { "name": "@dlenroc/testrail", - "description": "TestRail API client with error handling and typing", "version": "1.9.5", - "author": "Corneliu Duplachi", - "license": "MIT", - "homepage": "https://github.com/dlenroc/node-testrail-api", - "bugs": "https://github.com/dlenroc/node-testrail-api/issues", - "repository": "dlenroc/node-testrail-api", + "description": "TestRail API client with error handling and typing", "keywords": [ - "testrail", - "api" + "api", + "testrail" ], + "license": "MIT", + "author": "Corneliu Duplachi", + "repository": "dlenroc/node-testrail-api", "files": [ - "src", "dist" ], - "types": "dist/TestRail.d.ts", - "main": "dist/TestRail.node.js", - "module": "dist/TestRail.node.mjs", - "browser": "dist/TestRail.browser.mjs", - "jsdelivr": "dist/TestRail.umd.js", - "unpkg": "dist/TestRail.umd.js", - "scripts": { - "prepare": "npm run build", - "build": "rollup --bundleConfigAsCjs -c && replace-in-file '/(\\.\\.\\/)+src/g' '../src' 'dist/*.map' --isRegex", - "test": "mocha -A -r ts-node/register test/**/*.ts" + "type": "module", + "sideEffects": false, + "exports": { + "types": "./dist/TestRail.d.ts", + "default": "./dist/TestRail.js" }, - "engines": { - "node": ">=10" - }, - "dependencies": { - "form-data": "^4", - "node-fetch": "^2.6.4" + "scripts": { + "prepare": "tsdown --no-config --platform neutral ./src/TestRail.ts", + "test": "node --test" }, "devDependencies": { - "@faker-js/faker": "^7.6.0", - "@rollup/plugin-terser": "^0.4.1", - "@rollup/plugin-typescript": "^11.1.0", - "@types/chai": "^4.3.5", - "@types/chai-as-promised": "^7.1.5", - "@types/deasync": "^0.1.2", - "@types/glob": "^8.1.0", - "@types/mocha": "^10.0.1", - "@types/node": "*", - "chai": "^4.3.7", - "chai-as-promised": "^7.1.1", - "glob": "^10.2.3", + "@faker-js/faker": "^10.4.0", + "@tsconfig/strictest": "^2.0.8", + "@types/chai": "^5.2.3", + "@types/chai-as-promised": "^8.0.2", + "@types/node": "^25.5.0", + "chai": "^6.2.2", + "chai-as-promised": "^8.0.2", + "glob": "^13.0.6", "intermock": "^0.2.5", - "mocha": "^10.2.0", - "nock": "^13.3.1", - "replace-in-file": "^6.3.5", - "rollup": "^3.21.6", - "rollup-plugin-dts": "^5.3.0", - "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "nock": "^14.0.11", + "tsdown": "^0.21.7", + "typescript": "^6.0.2" } } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 4b1352c..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,82 +0,0 @@ -import terser from '@rollup/plugin-terser'; -import typescript from '@rollup/plugin-typescript'; -import dts from "rollup-plugin-dts"; -import pkg from './package.json'; - -export default [ - { - input: 'src/TestRail.ts', - external: ['stream'], - output: { - file: 'dist/TestRail.d.ts', - format: 'es', - footer: '\n// @ts-ignore\nexport = TestRail;', - }, - plugins: [ - dts.default(), - { - generateBundle(_, bundle) { - for (const file of Object.values(bundle)) { - file.code = file.code.replace(/declare const ([\w$]+): typeof (\w+);/g, 'type $1 = $2;'); - } - } - } - ], - }, - { - input: 'src/TestRail.ts', - external: [], - output: [ - { - file: pkg.browser, - format: 'es', - exports: 'default', - sourcemap: true, - }, - { - file: pkg.jsdelivr, - format: 'umd', - exports: 'default', - sourcemap: true, - name: 'TestRail', - }, - { - file: pkg.main, - format: 'cjs', - exports: 'default', - strict: false, - sourcemap: true, - banner: `'use strict';\n` - + `const http = require('http');\n` - + `const https = require('https');\n` - + `const nodeFetch = require('node-fetch');\n` - + `const FormData = require('form-data');\n\n` - + `const options = { keepAlive: true };\n` - + `const httpAgent = new http.Agent(options);\n` - + `const httpsAgent = new https.Agent(options);\n` - + `const agent = (url) => url.protocol === 'http:' ? httpAgent : httpsAgent;\n` - + `const fetch = (url, init) => nodeFetch(url, { agent, ...init });\n`, - }, - { - file: pkg.module, - format: 'es', - exports: 'default', - sourcemap: true, - banner: `` - + `import http from 'http';\n` - + `import https from 'https';\n` - + `import nodeFetch from 'node-fetch';\n` - + `import FormData from 'form-data';\n\n` - + `const options = { keepAlive: true };\n` - + `const httpAgent = new http.Agent(options);\n` - + `const httpsAgent = new https.Agent(options);\n` - + `const agent = (url) => url.protocol === 'http:' ? httpAgent : httpsAgent;\n` - + `const fetch = (url, init) => nodeFetch(url, { agent, ...init });\n`, - }, - ], - plugins: [ - typescript({ tsconfig: './tsconfig.json' }), - terser() - ], - } -]; diff --git a/src/TestRail.ts b/src/TestRail.ts index 39e626f..11c721e 100644 --- a/src/TestRail.ts +++ b/src/TestRail.ts @@ -1,517 +1,644 @@ -import type { TestRailCtx } from './TestRailCtx'; -import { TestRailException } from './TestRailException'; -import * as methods from './groups'; -import type { AddAttachment, AddCase, AddCaseField, AddConfig, AddConfigGroup, AddDataset, AddGroup, AddMilestone, AddPlan, AddPlanEntry, AddProject, AddResult, AddResults, AddResultsForCases, AddRun, AddRunToPlanEntry, AddSection, AddSharedStep, AddSuite, AddUser, AddVariable, AttachmentForCase, AttachmentForPlan, AttachmentForPlanEntry, AttachmentForRun, AttachmentForTest, Case, CaseField, CaseFilters, CaseHistory, CaseStatus, CaseType, Config, ConfigItem, CopyCasesToSection, CreatedAttachment, Dataset, DeleteCases, DeleteSharedStep, Group, Milestone, MilestoneFilters, MoveCasesToSection, MoveSection, Pagination, Plan, PlanEntry, PlanFilters, PlanItem, Priority, Project, ProjectFilters, Report, ReportUrls, Request, Response, Result, ResultField, ResultFilters, ResultForRunFilters, Role, Run, RunFilters, Section, SectionFilters, SharedStep, SharedStepFilters, SharedStepHistory, Status, Suite, Template, Test, TestFilters, UpdateCase, UpdateCases, UpdateConfig, UpdateConfigGroup, UpdateMilestone, UpdatePlan, UpdatePlanEntry, UpdateProject, UpdateRun, UpdateRunInPlanEntry, UpdateSection, UpdateSharedStep, UpdateSuite, User, UserFilters, Variable } from './payload'; - -export * from './payload'; -export type { Request as Payload, Response as Model }; +import type { TestRailConfig } from './TestRailConfig.ts'; +import { TestRailException } from './TestRailException.ts'; +import { pagination } from './internal/pagination.ts'; +import type { Executor, RequestOptions } from './internal/request.ts'; +import { createExecutor } from './internal/request.ts'; +import type { + AddAttachment, + AddCase, + AddCaseField, + AddConfig, + AddConfigGroup, + AddDataset, + AddGroup, + AddMilestone, + AddPlan, + AddPlanEntry, + AddProject, + AddResult, + AddResults, + AddResultsForCases, + AddRun, + AddRunToPlanEntry, + AddSection, + AddSharedStep, + AddSuite, + AddUser, + AddVariable, + AttachmentForCase, + AttachmentForPlan, + AttachmentForPlanEntry, + AttachmentForRun, + AttachmentForTest, + Case, + CaseField, + CaseFilters, + CaseHistory, + CaseStatus, + CaseType, + Config, + ConfigItem, + CopyCasesToSection, + CreatedAttachment, + Dataset, + DeleteCases, + DeleteSharedStep, + Group, + Milestone, + MilestoneFilters, + MoveCasesToSection, + MoveSection, + Pagination, + Plan, + PlanEntry, + PlanFilters, + PlanItem, + Priority, + Project, + ProjectFilters, + Report, + ReportUrls, + Result, + ResultField, + ResultFilters, + ResultForRunFilters, + Role, + Run, + RunFilters, + Section, + SectionFilters, + SharedStep, + SharedStepFilters, + SharedStepHistory, + Status, + Suite, + Template, + Test, + TestFilters, + UpdateCase, + UpdateCases, + UpdateConfig, + UpdateConfigGroup, + UpdateMilestone, + UpdatePlan, + UpdatePlanEntry, + UpdateProject, + UpdateRun, + UpdateRunInPlanEntry, + UpdateSection, + UpdateSharedStep, + UpdateSuite, + User, + UserFilters, + Variable, +} from './payload/index.ts'; + +export * from './payload/index.ts'; type Signal = { signal: AbortSignal }; -export default class TestRail { +export class TestRail { + private send: Executor; + static Exception = TestRailException; - private readonly ctx: TestRailCtx; - constructor(config?: { host: string; username: string; password: string } & Pick) { - this.ctx = { - baseURL: (config?.host || '') + '/index.php?/api/v2/', - // @ts-ignore - Backward compatibility - ...(config?.user && { username: config.user }), - ...(config?.username && { username: config.username }), - ...(config?.password && { password: config.password }), - ...(config?.signal && { signal: config.signal }), - ...(config?.implementations && { implementations: config.implementations }), - }; + constructor(config?: TestRailConfig | undefined) { + this.send = createExecutor({ + ...config, + host: (config?.host || '') + '/index.php?/api/v2/', + }); } addAttachmentToCase(caseId: number, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addAttachmentToCase(ctx, caseId, payload)); + return this._api(`add_attachment_to_case/${caseId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } addAttachmentToPlan(planId: number, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addAttachmentToPlan(ctx, planId, payload)); + return this._api(`add_attachment_to_plan/${planId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } addAttachmentToPlanEntry(planId: number, entryId: string, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addAttachmentToPlanEntry(ctx, planId, entryId, payload)); + return this._api(`add_attachment_to_plan_entry/${planId}/${entryId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } addAttachmentToResult(resultId: number, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addAttachmentToResult(ctx, resultId, payload)); + return this._api(`add_attachment_to_result/${resultId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } addAttachmentToRun(runId: number, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addAttachmentToRun(ctx, runId, payload)); + return this._api(`add_attachment_to_run/${runId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } getAttachmentsForCase(caseId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachmentsForCase(ctx, caseId, filters)); + return pagination('attachments', filters, (filters) => { + return this._api(`get_attachments_for_case/${caseId}`, { ...options, query: filters }); + }); } getAttachmentsForPlan(planId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachmentsForPlan(ctx, planId, filters)); + return pagination('attachments', filters, (filters) => { + return this._api(`get_attachments_for_plan/${planId}`, { ...options, query: filters }); + }); } getAttachmentsForPlanEntry(planId: number, entryId: string, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachmentsForPlanEntry(ctx, planId, entryId)); + return this._api(`get_attachments_for_plan_entry/${planId}/${entryId}`, options); } getAttachmentsForRun(runId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachmentsForRun(ctx, runId, filters)); + return pagination('attachments', filters, (filters) => { + return this._api(`get_attachments_for_run/${runId}`, { ...options, query: filters }); + }); } getAttachmentsForTest(testId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachmentsForTest(ctx, testId)); + return this._api(`get_attachments_for_test/${testId}`, options); } getAttachment(attachmentId: string, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getAttachment(ctx, attachmentId)); + return this._api(`get_attachment/${attachmentId}`, options); } deleteAttachment(attachmentId: string, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteAttachment(ctx, attachmentId)); + return this._api(`delete_attachment/${attachmentId}`, options); } getBdd(caseId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getBdd(ctx, caseId)); + return this._api(`get_bdd/${caseId}`, options); } addBdd(sectionId: number, payload: AddAttachment, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addBdd(ctx, sectionId, payload)); + return this._api(`add_bdd/${sectionId}`, { ...options, form: [['attachment', payload.value, payload.name]] }); } getCase(caseId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCase(ctx, caseId)); + return this._api(`get_case/${caseId}`, options); } getCases(projectId: number, filters?: CaseFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCases(ctx, projectId, filters)); + return pagination('cases', filters, (filters) => { + return this._api(`get_cases/${projectId}`, { ...options, query: filters }); + }); } getHistoryForCase(caseId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getHistoryForCase(ctx, caseId, filters)); + return pagination('history', filters, (filters) => { + return this._api(`get_history_for_case/${caseId}`, { ...options, query: filters }); + }); } addCase(sectionId: number, payload: AddCase, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addCase(ctx, sectionId, payload)); + return this._api(`add_case/${sectionId}`, { ...options, json: payload }); } copyCasesToSection(sectionId: number, payload: CopyCasesToSection, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.copyCasesToSection(ctx, sectionId, payload)); + return this._api(`copy_cases_to_section/${sectionId}`, { ...options, json: payload }); } updateCase(caseId: number, payload: UpdateCase, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateCase(ctx, caseId, payload)); + return this._api(`update_case/${caseId}`, { ...options, json: payload }); } updateCases(suiteId: number, payload: UpdateCases, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateCases(ctx, suiteId, payload)); + return this._api(`update_cases/${suiteId}`, { ...options, json: payload }); } moveCasesToSection(sectionId: number, payload: MoveCasesToSection, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.moveCasesToSection(ctx, sectionId, payload)); + return this._api(`move_cases_to_section/${sectionId}`, { ...options, json: payload }); } deleteCase(caseId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteCase(ctx, caseId)); + return this._api(`delete_case/${caseId}`, options); } deleteCases(suiteId: number, payload: DeleteCases, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteCases(ctx, suiteId, payload)); + return this._api(`delete_cases/${suiteId}`, { ...options, json: payload }); } getCaseFields(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCaseFields(ctx)); + return this._api('get_case_fields', options); } addCaseField(payload: AddCaseField, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addCaseField(ctx, payload)); + return this._api('add_case_field', { ...options, json: payload }); } getCaseTypes(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCaseTypes(ctx)); + return this._api('get_case_types', options); } getConfigs(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getConfigs(ctx, projectId)); + return this._api(`get_configs/${projectId}`, options); } addConfigGroup(projectId: number, payload: AddConfigGroup, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addConfigGroup(ctx, projectId, payload)); + return this._api(`add_config_group/${projectId}`, { ...options, json: payload }); } addConfig(configGroupId: number, payload: AddConfig, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addConfig(ctx, configGroupId, payload)); + return this._api(`add_config/${configGroupId}`, { ...options, json: payload }); } updateConfigGroup(configGroupId: number, payload: UpdateConfigGroup, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateConfigGroup(ctx, configGroupId, payload)); + return this._api(`update_config_group/${configGroupId}`, { ...options, json: payload }); } updateConfig(configId: number, payload: UpdateConfig, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateConfig(ctx, configId, payload)); + return this._api(`update_config/${configId}`, { ...options, json: payload }); } deleteConfigGroup(configGroupId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteConfigGroup(ctx, configGroupId)); + return this._api(`delete_config_group/${configGroupId}`, options); } deleteConfig(configId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteConfig(ctx, configId)); + return this._api(`delete_config/${configId}`, options); } getDataset(datasetId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getDataset(ctx, datasetId)); + return this._api(`get_dataset/${datasetId}`, options); } getDatasets(projectId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getDatasets(ctx, projectId, filters)); + return pagination('datasets', filters, (filters) => { + return this._api(`get_datasets/${projectId}`, { ...options, query: filters }); + }); } addDataset(projectId: number, payload: AddDataset, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addDataset(ctx, projectId, payload)); + return this._api(`add_dataset/${projectId}`, { ...options, json: payload }); } updateDataset(datasetId: number, payload: AddDataset, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateDataset(ctx, datasetId, payload)); + return this._api(`update_dataset/${datasetId}`, { ...options, json: payload }); } deleteDataset(datasetId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteDataset(ctx, datasetId)); + return this._api(`delete_dataset/${datasetId}`, options); } getGroup(groupId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getGroup(ctx, groupId)); + return this._api(`get_group/${groupId}`, options); } getGroups(filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getGroups(ctx, filters)); + return pagination('groups', filters, (filters) => { + return this._api('get_groups', { ...options, query: filters }); + }); } addGroup(payload: AddGroup, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addGroup(ctx, payload)); + return this._api('add_group', { ...options, json: payload }); } updateGroup(groupId: number, payload: AddGroup, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateGroup(ctx, groupId, payload)); + return this._api(`update_group/${groupId}`, { ...options, json: payload }); } deleteGroup(groupId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteGroup(ctx, groupId)); + return this._api(`delete_group/${groupId}`, options); } getMilestone(milestoneId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getMilestone(ctx, milestoneId)); + return this._api(`get_milestone/${milestoneId}`, options); } getMilestones(projectId: number, filters?: MilestoneFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getMilestones(ctx, projectId, filters)); + return pagination('milestones', filters, (filters) => { + return this._api(`get_milestones/${projectId}`, { ...options, query: filters }); + }); } addMilestone(projectId: number, payload: AddMilestone, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addMilestone(ctx, projectId, payload)); + return this._api(`add_milestone/${projectId}`, { ...options, json: payload }); } updateMilestone(milestoneId: number, payload: UpdateMilestone, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateMilestone(ctx, milestoneId, payload)); + return this._api(`update_milestone/${milestoneId}`, { ...options, json: payload }); } deleteMilestone(milestoneId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteMilestone(ctx, milestoneId)); + return this._api(`delete_milestone/${milestoneId}`, options); } getPlan(planId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getPlan(ctx, planId)); + return this._api(`get_plan/${planId}`, options); } getPlans(projectId: number, filters?: PlanFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getPlans(ctx, projectId, filters)); + return pagination('plans', filters, (filters) => { + return this._api(`get_plans/${projectId}`, { ...options, query: filters }); + }); } addPlan(projectId: number, payload: AddPlan, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addPlan(ctx, projectId, payload)); + return this._api(`add_plan/${projectId}`, { ...options, json: payload }); } addPlanEntry(planId: number, payload: AddPlanEntry, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addPlanEntry(ctx, planId, payload)); + return this._api(`add_plan_entry/${planId}`, { ...options, json: payload }); } addRunToPlanEntry(planId: number, entryId: string, payload: AddRunToPlanEntry, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addRunToPlanEntry(ctx, planId, entryId, payload)); + return this._api(`add_run_to_plan_entry/${planId}/${entryId}`, { ...options, json: payload }); } updatePlan(planId: number, payload: UpdatePlan, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updatePlan(ctx, planId, payload)); + return this._api(`update_plan/${planId}`, { ...options, json: payload }); } updatePlanEntry(planId: number, entryId: string, payload: UpdatePlanEntry, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updatePlanEntry(ctx, planId, entryId, payload)); + return this._api(`update_plan_entry/${planId}/${entryId}`, { ...options, json: payload }); } updateRunInPlanEntry(runId: number, payload: UpdateRunInPlanEntry, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateRunInPlanEntry(ctx, runId, payload)); + return this._api(`update_run_in_plan_entry/${runId}`, { ...options, json: payload }); } closePlan(planId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.closePlan(ctx, planId)); + return this._api(`close_plan/${planId}`, options); } deletePlan(planId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deletePlan(ctx, planId)); + return this._api(`delete_plan/${planId}`, options); } deletePlanEntry(planId: number, entryId: string, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deletePlanEntry(ctx, planId, entryId)); + return this._api(`delete_plan_entry/${planId}/${entryId}`, options); } deleteRunFromPlanEntry(runId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteRunFromPlanEntry(ctx, runId)); + return this._api(`delete_run_from_plan_entry/${runId}`, options); } getPriorities(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getPriorities(ctx)); + return this._api('get_priorities', options); } getProject(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getProject(ctx, projectId)); + return this._api(`get_project/${projectId}`, options); } getProjects(filters?: ProjectFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getProjects(ctx, filters)); + return pagination('projects', filters, (filters) => { + return this._api('get_projects', { ...options, query: filters }); + }); } addProject(payload: AddProject, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addProject(ctx, payload)); + return this._api('add_project', { ...options, json: payload }); } updateProject(projectId: number, payload: UpdateProject, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateProject(ctx, projectId, payload)); + return this._api(`update_project/${projectId}`, { ...options, json: payload }); } deleteProject(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteProject(ctx, projectId)); + return this._api(`delete_project/${projectId}`, options); } getReports(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getReports(ctx, projectId)); + return this._api(`get_reports/${projectId}`, options); } runReport(reportTemplateId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.runReport(ctx, reportTemplateId)); + return this._api(`run_report/${reportTemplateId}`, options); } getResults(testId: number, filters?: ResultFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getResults(ctx, testId, filters)); + return pagination('results', filters, (filters) => { + return this._api(`get_results/${testId}`, { ...options, query: filters }); + }); } getResultsForCase(runId: number, caseId: number, filters?: ResultFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getResultsForCase(ctx, runId, caseId, filters)); + return pagination('results', filters, (filters) => { + return this._api(`get_results_for_case/${runId}/${caseId}`, { ...options, query: filters }); + }); } getResultsForRun(runId: number, filters?: ResultForRunFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getResultsForRun(ctx, runId, filters)); + return pagination('results', filters, (filters) => { + return this._api(`get_results_for_run/${runId}`, { ...options, query: filters }); + }); } addResult(testId: number, payload: AddResult, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addResult(ctx, testId, payload)); + return this._api(`add_result/${testId}`, { ...options, json: payload }); } addResultForCase(runId: number, caseId: number, payload: AddResult, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addResultForCase(ctx, runId, caseId, payload)); + return this._api(`add_result_for_case/${runId}/${caseId}`, { ...options, json: payload }); } addResults(runId: number, payload: AddResults, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addResults(ctx, runId, payload)); + return this._api(`add_results/${runId}`, { ...options, json: payload }); } addResultsForCases(runId: number, payload: AddResultsForCases, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addResultsForCases(ctx, runId, payload)); + return this._api(`add_results_for_cases/${runId}`, { ...options, json: payload }); } getResultFields(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getResultFields(ctx)); + return this._api('get_result_fields', options); } getRoles(filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getRoles(ctx, filters)); + return pagination('roles', filters, (filters) => { + return this._api('get_roles', { ...options, query: filters }); + }); } getRun(runId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getRun(ctx, runId)); + return this._api(`get_run/${runId}`, options); } getRuns(projectId: number, filters?: RunFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getRuns(ctx, projectId, filters)); + return pagination('runs', filters, (filters) => { + return this._api(`get_runs/${projectId}`, { ...options, query: filters }); + }); } addRun(projectId: number, payload: AddRun, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addRun(ctx, projectId, payload)); + return this._api(`add_run/${projectId}`, { ...options, json: payload }); } updateRun(runId: number, payload: UpdateRun, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateRun(ctx, runId, payload)); + return this._api(`update_run/${runId}`, { ...options, json: payload }); } closeRun(runId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.closeRun(ctx, runId)); + return this._api(`close_run/${runId}`, options); } deleteRun(runId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteRun(ctx, runId)); + return this._api(`delete_run/${runId}`, options); } getSection(sectionId: number, options?: Signal): Promise
{ - return this.withCtx(options, (ctx) => methods.getSection(ctx, sectionId)); + return this._api(`get_section/${sectionId}`, options); } getSections(projectId: number, filters?: SectionFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSections(ctx, projectId, filters)); + return pagination('sections', filters, (filters) => { + return this._api(`get_sections/${projectId}`, { ...options, query: filters }); + }); } addSection(projectId: number, payload: AddSection, options?: Signal): Promise
{ - return this.withCtx(options, (ctx) => methods.addSection(ctx, projectId, payload)); + return this._api(`add_section/${projectId}`, { ...options, json: payload }); } moveSection(sectionId: number, payload: MoveSection, options?: Signal): Promise
{ - return this.withCtx(options, (ctx) => methods.moveSection(ctx, sectionId, payload)); + return this._api(`move_section/${sectionId}`, { ...options, json: payload }); } updateSection(sectionId: number, payload: UpdateSection, options?: Signal): Promise
{ - return this.withCtx(options, (ctx) => methods.updateSection(ctx, sectionId, payload)); + return this._api(`update_section/${sectionId}`, { ...options, json: payload }); } deleteSection(sectionId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteSection(ctx, sectionId)); + return this._api(`delete_section/${sectionId}`, options); } getSharedStep(stepId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSharedStep(ctx, stepId)); + return this._api(`get_shared_step/${stepId}`, options); } getSharedSteps(projectId: number, filters?: SharedStepFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSharedSteps(ctx, projectId, filters)); + return pagination('shared_steps', filters, (filters) => { + return this._api(`get_shared_steps/${projectId}`, { ...options, query: filters }); + }); } getSharedStepHistory(stepId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSharedStepHistory(ctx, stepId, filters)); + return pagination('step_history', filters, (filters) => { + return this._api(`get_shared_step_history/${stepId}`, { ...options, query: filters }); + }); } addSharedStep(projectId: number, payload: AddSharedStep, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addSharedStep(ctx, projectId, payload)); + return this._api(`add_shared_step/${projectId}`, { ...options, json: payload }); } updateSharedStep(stepId: number, payload: UpdateSharedStep, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateSharedStep(ctx, stepId, payload)); + return this._api(`update_shared_step/${stepId}`, { ...options, json: payload }); } deleteSharedStep(stepId: number, payload?: DeleteSharedStep, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteSharedStep(ctx, stepId, payload)); + return this._api(`delete_shared_step/${stepId}`, { ...options, json: payload }); } getStatuses(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getStatuses(ctx)); + return this._api('get_statuses', options); } getCaseStatuses(filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCaseStatuses(ctx, filters)); + return pagination('case_statuses', filters, (filters) => { + return this._api('get_case_statuses', { ...options, query: filters }); + }); } getSuite(suiteId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSuite(ctx, suiteId)); + return this._api(`get_suite/${suiteId}`, options); } - getSuites(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getSuites(ctx, projectId)); + getSuites(projectId: number, filters?: Pagination, options?: Signal): Promise { + return pagination('suites', filters, (filters) => { + return this._api(`get_suites/${projectId}`, { ...options, query: filters }); + }); } addSuite(projectId: number, payload: AddSuite, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addSuite(ctx, projectId, payload)); + return this._api(`add_suite/${projectId}`, { ...options, json: payload }); } updateSuite(suiteId: number, payload: UpdateSuite, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateSuite(ctx, suiteId, payload)); + return this._api(`update_suite/${suiteId}`, { ...options, json: payload }); } deleteSuite(suiteId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteSuite(ctx, suiteId)); + return this._api(`delete_suite/${suiteId}`, options); } getTemplates(projectId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getTemplates(ctx, projectId)); + return this._api(`get_templates/${projectId}`, options); } getTest(testId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getTest(ctx, testId)); + return this._api(`get_test/${testId}`, options); } getTests(runId: number, filters?: TestFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getTests(ctx, runId, filters)); + return pagination('tests', filters, (filters) => { + return this._api(`get_tests/${runId}`, { ...options, query: filters }); + }); } getUser(userId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getUser(ctx, userId)); + return this._api(`get_user/${userId}`, options); } getCurrentUser(options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getCurrentUser(ctx)); + return this._api(`get_current_user`, options); } getUserByEmail(email: string, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getUserByEmail(ctx, email)); + return this._api('get_user_by_email', { ...options, query: { email } }); } getUsers(filters?: UserFilters, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getUsers(ctx, filters)); + return pagination('users', filters, (filters) => { + return this._api('get_users', { ...options, query: filters }); + }); } addUser(payload: AddUser, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addUser(ctx, payload)); + return this._api('add_user', { ...options, json: payload }); } updateUser(userId: number, payload: AddUser, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateUser(ctx, userId, payload)); + return this._api(`update_user/${userId}`, { ...options, json: payload }); } getVariables(projectId: number, filters?: Pagination, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.getVariables(ctx, projectId, filters)); + return pagination('variables', filters, (filters) => { + return this._api(`get_variables/${projectId}`, { ...options, query: filters }); + }); } addVariable(projectId: number, payload: AddVariable, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.addVariable(ctx, projectId, payload)); + return this._api(`add_variable/${projectId}`, { ...options, json: payload }); } updateVariable(variableId: number, payload: AddVariable, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.updateVariable(ctx, variableId, payload)); + return this._api(`update_variable/${variableId}`, { ...options, json: payload }); } deleteVariable(variableId: number, options?: Signal): Promise { - return this.withCtx(options, (ctx) => methods.deleteVariable(ctx, variableId)); - } - - private withCtx(options: Signal | undefined, callback: (ctx: TestRailCtx) => Promise): Promise { - const ctxSignal = this.ctx.signal; - const optionsSignal = options?.signal; - - if (!optionsSignal) { - return callback(this.ctx); + return this._api(`delete_variable/${variableId}`, options); + } + + private async _api(path: string, options?: Pick): Promise { + const response = await this.send(path, { + method: path.startsWith('get_') ? 'GET' : 'POST', + query: options?.query, + json: options?.json, + form: options?.form, + signal: options?.signal, + }); + + const result: any = response.headers.get('Content-Type')?.includes('json') + ? await response.json().catch(() => ({})) + : await response.blob(); + + if (response.ok) { + return result; + } else { + throw new TestRailException( + result?.error || + `No additional error message received: ${response.status} ${response.statusText}`, + ); } - - if (!ctxSignal) { - return callback(Object.assign({}, this.ctx, { signal: options.signal })); - } - - if (ctxSignal.aborted || optionsSignal.aborted) { - return Promise.reject(ctxSignal.reason || options.signal.reason); - } - - // @ts-ignore - intentionally throws "ReferrerError" if "AbortController" is not available - const controller = new (this.ctx.implementations?.AbortController || AbortController)(); - const clearAbort = () => { ctxSignal.removeEventListener('abort', onAbort); optionsSignal.removeEventListener('abort', onAbort); }; - const onAbort = () => { clearAbort(); controller.abort(ctxSignal.reason || optionsSignal.reason); }; - ctxSignal.addEventListener('abort', onAbort); - optionsSignal.addEventListener('abort', onAbort); - - return callback(Object.assign({}, this.ctx, { signal: controller.signal })) - .then((r) => { clearAbort(); return r; }, (e) => { clearAbort(); throw e; }); } } diff --git a/src/TestRailConfig.ts b/src/TestRailConfig.ts new file mode 100644 index 0000000..3a60086 --- /dev/null +++ b/src/TestRailConfig.ts @@ -0,0 +1,5 @@ +export type TestRailConfig = { + readonly host?: string | undefined; + readonly username?: string | undefined; + readonly password?: string | undefined; +}; diff --git a/src/TestRailCtx.ts b/src/TestRailCtx.ts deleted file mode 100644 index 845cad8..0000000 --- a/src/TestRailCtx.ts +++ /dev/null @@ -1,12 +0,0 @@ -export type TestRailCtx = { - readonly baseURL?: string; - readonly username?: string; - readonly password?: string; - readonly signal?: AbortSignal; - readonly implementations?: { - readonly AbortController?: any - readonly Blob?: any; - readonly fetch?: any; - readonly FormData?: any; - }; -}; diff --git a/src/groups/attachments.ts b/src/groups/attachments.ts deleted file mode 100644 index a20bf4e..0000000 --- a/src/groups/attachments.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddAttachment, AttachmentForCase, AttachmentForPlan, AttachmentForPlanEntry, AttachmentForRun, AttachmentForTest, CreatedAttachment, Pagination } from '../payload'; - -export function addAttachmentToCase(ctx: TestRailCtx, caseId: number, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_attachment_to_case/${caseId}`, { form: { attachment: payload } }); -} - -export function addAttachmentToPlan(ctx: TestRailCtx, planId: number, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_attachment_to_plan/${planId}`, { form: { attachment: payload } }); -} - -export function addAttachmentToPlanEntry(ctx: TestRailCtx, planId: number, entryId: string, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_attachment_to_plan_entry/${planId}/${entryId}`, { form: { attachment: payload } }); -} - -export function addAttachmentToResult(ctx: TestRailCtx, resultId: number, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_attachment_to_result/${resultId}`, { form: { attachment: payload } }); -} - -export function addAttachmentToRun(ctx: TestRailCtx, runId: number, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_attachment_to_run/${runId}`, { form: { attachment: payload } }); -} - -export function getAttachmentsForCase(ctx: TestRailCtx, caseId: number, filters?: Pagination): Promise { - return pagination('attachments', filters, (filters) => { - return _api(ctx, 'GET', `get_attachments_for_case/${caseId}`, { query: filters }); - }); -} - -export function getAttachmentsForPlan(ctx: TestRailCtx, planId: number, filters?: Pagination): Promise { - return pagination('attachments', filters, (filters) => { - return _api(ctx, 'GET', `get_attachments_for_plan/${planId}`, { query: filters }); - }); -} - -export function getAttachmentsForPlanEntry(ctx: TestRailCtx, planId: number, entryId: string): Promise { - return _api(ctx, 'GET', `get_attachments_for_plan_entry/${planId}/${entryId}`); -} - -export function getAttachmentsForRun(ctx: TestRailCtx, runId: number, filters?: Pagination): Promise { - return pagination('attachments', filters, (filters) => { - return _api(ctx, 'GET', `get_attachments_for_run/${runId}`, { query: filters }); - }); -} - -export function getAttachmentsForTest(ctx: TestRailCtx, testId: number): Promise { - return _api(ctx, 'GET', `get_attachments_for_test/${testId}`); -} - -export function getAttachment(ctx: TestRailCtx, attachmentId: string): Promise { - return _api(ctx, 'GET', `get_attachment/${attachmentId}`); -} - -export function deleteAttachment(ctx: TestRailCtx, attachmentId: string): Promise { - return _api(ctx, 'POST', `delete_attachment/${attachmentId}`); -} diff --git a/src/groups/bdd.ts b/src/groups/bdd.ts deleted file mode 100644 index f8d3e55..0000000 --- a/src/groups/bdd.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { AddAttachment, Case } from '../payload'; - -export function getBdd(ctx: TestRailCtx, caseId: number): Promise { - return _api(ctx, 'GET', `get_bdd/${caseId}`); -} - -export function addBdd(ctx: TestRailCtx, sectionId: number, payload: AddAttachment): Promise { - return _api(ctx, 'POST', `add_bdd/${sectionId}`, { form: { attachment: payload }}); -} diff --git a/src/groups/case-fields.ts b/src/groups/case-fields.ts deleted file mode 100644 index 00224ce..0000000 --- a/src/groups/case-fields.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { AddCaseField, CaseField } from '../payload'; - -export function getCaseFields(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', 'get_case_fields'); -} - -export function addCaseField(ctx: TestRailCtx, payload: AddCaseField): Promise { - return _api(ctx, 'POST', 'add_case_field', { json: payload }); -} diff --git a/src/groups/case-types.ts b/src/groups/case-types.ts deleted file mode 100644 index ba427da..0000000 --- a/src/groups/case-types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { CaseType } from '../payload'; - -export function getCaseTypes(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', 'get_case_types'); -} diff --git a/src/groups/cases.ts b/src/groups/cases.ts deleted file mode 100644 index 7384ff6..0000000 --- a/src/groups/cases.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddCase, Case, CaseFilters, CaseHistory, CopyCasesToSection, DeleteCases, MoveCasesToSection, Pagination, UpdateCase, UpdateCases } from '../payload'; - -export function getCase(ctx: TestRailCtx, caseId: number): Promise { - return _api(ctx, 'GET', `get_case/${caseId}`); -} - -export function getCases(ctx: TestRailCtx, projectId: number, filters?: CaseFilters): Promise { - return pagination('cases', filters, (filters) => { - return _api(ctx, 'GET', `get_cases/${projectId}`, { query: filters }); - }); -} - -export function getHistoryForCase(ctx: TestRailCtx, caseId: number, filters?: Pagination): Promise { - return pagination('history', filters, (filters) => { - return _api(ctx, 'GET', `get_history_for_case/${caseId}`, { query: filters }); - }); -} - -export function addCase(ctx: TestRailCtx, sectionId: number, payload: AddCase): Promise { - return _api(ctx, 'POST', `add_case/${sectionId}`, { json: payload }); -} - -export function copyCasesToSection(ctx: TestRailCtx, sectionId: number, payload: CopyCasesToSection): Promise { - return _api(ctx, 'POST', `copy_cases_to_section/${sectionId}`, { json: payload }); -} - -export function updateCase(ctx: TestRailCtx, caseId: number, payload: UpdateCase): Promise { - return _api(ctx, 'POST', `update_case/${caseId}`, { json: payload }); -} - -export function updateCases(ctx: TestRailCtx, suiteId: number, payload: UpdateCases): Promise { - return _api(ctx, 'POST', `update_cases/${suiteId}`, { json: payload }); -} - -export function moveCasesToSection(ctx: TestRailCtx, sectionId: number, payload: MoveCasesToSection): Promise { - return _api(ctx, 'POST', `move_cases_to_section/${sectionId}`, { json: payload }); -} - -export function deleteCase(ctx: TestRailCtx, caseId: number): Promise { - return _api(ctx, 'POST', `delete_case/${caseId}`); -} - -export function deleteCases(ctx: TestRailCtx, suiteId: number, payload: DeleteCases): Promise { - return _api(ctx, 'POST', `delete_cases/${suiteId}`, { json: payload }); -} diff --git a/src/groups/configurations.ts b/src/groups/configurations.ts deleted file mode 100644 index f1d4a0b..0000000 --- a/src/groups/configurations.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { AddConfig, AddConfigGroup, Config, ConfigItem, UpdateConfig, UpdateConfigGroup } from '../payload'; - -export function getConfigs(ctx: TestRailCtx, projectId: number): Promise { - return _api(ctx, 'GET', `get_configs/${projectId}`); -} - -export function addConfigGroup(ctx: TestRailCtx, projectId: number, payload: AddConfigGroup): Promise { - return _api(ctx, 'POST', `add_config_group/${projectId}`, { json: payload }); -} - -export function addConfig(ctx: TestRailCtx, configGroupId: number, payload: AddConfig): Promise { - return _api(ctx, 'POST', `add_config/${configGroupId}`, { json: payload }); -} - -export function updateConfigGroup(ctx: TestRailCtx, configGroupId: number, payload: UpdateConfigGroup): Promise { - return _api(ctx, 'POST', `update_config_group/${configGroupId}`, { json: payload }); -} - -export function updateConfig(ctx: TestRailCtx, configId: number, payload: UpdateConfig): Promise { - return _api(ctx, 'POST', `update_config/${configId}`, { json: payload }); -} - -export function deleteConfigGroup(ctx: TestRailCtx, configGroupId: number): Promise { - return _api(ctx, 'POST', `delete_config_group/${configGroupId}`); -} - -export function deleteConfig(ctx: TestRailCtx, configId: number): Promise { - return _api(ctx, 'POST', `delete_config/${configId}`); -} diff --git a/src/groups/datasets.ts b/src/groups/datasets.ts deleted file mode 100644 index 27f049f..0000000 --- a/src/groups/datasets.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddDataset, Dataset, Group, Pagination } from '../payload'; - -export function getDataset(ctx: TestRailCtx, datasetId: number): Promise { - return _api(ctx, 'GET', `get_dataset/${datasetId}`); -} - -export function getDatasets(ctx: TestRailCtx, projectId: number, filters?: Pagination): Promise { - return pagination('datasets', filters, (filters) => { - return _api(ctx, 'GET', `get_datasets/${projectId}`, { query: filters }); - }); -} - -export function addDataset(ctx: TestRailCtx, projectId: number, payload: AddDataset): Promise { - return _api(ctx, 'POST', `add_dataset/${projectId}`, { json: payload }); -} - -export function updateDataset(ctx: TestRailCtx, datasetId: number, payload: AddDataset): Promise { - return _api(ctx, 'POST', `update_dataset/${datasetId}`, { json: payload }); -} - -export function deleteDataset(ctx: TestRailCtx, datasetId: number): Promise { - return _api(ctx, 'POST', `delete_dataset/${datasetId}`); -} diff --git a/src/groups/groups.ts b/src/groups/groups.ts deleted file mode 100644 index 987d598..0000000 --- a/src/groups/groups.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddGroup, Group, Pagination } from '../payload'; - -export function getGroup(ctx: TestRailCtx, groupId: number): Promise { - return _api(ctx, 'GET', `get_group/${groupId}`); -} - -export function getGroups(ctx: TestRailCtx, filters?: Pagination): Promise { - return pagination('groups', filters, (filters) => { - return _api(ctx, 'GET', 'get_groups', { query: filters }); - }); -} - -export function addGroup(ctx: TestRailCtx, payload: AddGroup): Promise { - return _api(ctx, 'POST', 'add_group', { json: payload }); -} - -export function updateGroup(ctx: TestRailCtx, groupId: number, payload: AddGroup): Promise { - return _api(ctx, 'POST', `update_group/${groupId}`, { json: payload }); -} - -export function deleteGroup(ctx: TestRailCtx, groupId: number): Promise { - return _api(ctx, 'POST', `delete_group/${groupId}`); -} diff --git a/src/groups/index.ts b/src/groups/index.ts deleted file mode 100644 index 049238a..0000000 --- a/src/groups/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -export * from './attachments.js'; -export * from './bdd.js'; -export * from './case-fields.js'; -export * from './case-types.js'; -export * from './cases.js'; -export * from './configurations.js'; -export * from './datasets.js'; -export * from './groups.js'; -export * from './milestones.js'; -export * from './plans.js'; -export * from './priorities.js'; -export * from './projects.js'; -export * from './reports.js'; -export * from './result-fields.js'; -export * from './results.js'; -export * from './roles.js'; -export * from './runs.js'; -export * from './sections.js'; -export * from './shared-steps.js'; -export * from './statuses.js'; -export * from './suites.js'; -export * from './templates.js'; -export * from './tests.js'; -export * from './users.js'; -export * from './variables.js'; - diff --git a/src/groups/milestones.ts b/src/groups/milestones.ts deleted file mode 100644 index 296a180..0000000 --- a/src/groups/milestones.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddMilestone, Milestone, MilestoneFilters, UpdateMilestone } from '../payload'; - -export function getMilestone(ctx: TestRailCtx, milestoneId: number): Promise { - return _api(ctx, 'GET', `get_milestone/${milestoneId}`); -} - -export function getMilestones(ctx: TestRailCtx, projectId: number, filters?: MilestoneFilters): Promise { - return pagination('milestones', filters, (filters) => { - return _api(ctx, 'GET', `get_milestones/${projectId}`, { query: filters }); - }); -} - -export function addMilestone(ctx: TestRailCtx, projectId: number, payload: AddMilestone): Promise { - return _api(ctx, 'POST', `add_milestone/${projectId}`, { json: payload }); -} - -export function updateMilestone(ctx: TestRailCtx, milestoneId: number, payload: UpdateMilestone): Promise { - return _api(ctx, 'POST', `update_milestone/${milestoneId}`, { json: payload }); -} - -export function deleteMilestone(ctx: TestRailCtx, milestoneId: number): Promise { - return _api(ctx, 'POST', `delete_milestone/${milestoneId}`); -} diff --git a/src/groups/plans.ts b/src/groups/plans.ts deleted file mode 100644 index 7a5a38a..0000000 --- a/src/groups/plans.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddPlan, AddPlanEntry, AddRunToPlanEntry, Plan, PlanEntry, PlanFilters, PlanItem, UpdatePlan, UpdatePlanEntry, UpdateRunInPlanEntry } from '../payload'; - -export function getPlan(ctx: TestRailCtx, planId: number): Promise { - return _api(ctx, 'GET', `get_plan/${planId}`); -} - -export function getPlans(ctx: TestRailCtx, projectId: number, filters?: PlanFilters): Promise { - return pagination('plans', filters, (filters) => { - return _api(ctx, 'GET', `get_plans/${projectId}`, { query: filters }); - }); -} - -export function addPlan(ctx: TestRailCtx, projectId: number, payload: AddPlan): Promise { - return _api(ctx, 'POST', `add_plan/${projectId}`, { json: payload }); -} - -export function addPlanEntry(ctx: TestRailCtx, planId: number, payload: AddPlanEntry): Promise { - return _api(ctx, 'POST', `add_plan_entry/${planId}`, { json: payload }); -} - -export function addRunToPlanEntry(ctx: TestRailCtx, planId: number, entryId: string, payload: AddRunToPlanEntry): Promise { - return _api(ctx, 'POST', `add_run_to_plan_entry/${planId}/${entryId}`, { json: payload }); -} - -export function updatePlan(ctx: TestRailCtx, planId: number, payload: UpdatePlan): Promise { - return _api(ctx, 'POST', `update_plan/${planId}`, { json: payload }); -} - -export function updatePlanEntry(ctx: TestRailCtx, planId: number, entryId: string, payload: UpdatePlanEntry): Promise { - return _api(ctx, 'POST', `update_plan_entry/${planId}/${entryId}`, { json: payload }); -} - -export function updateRunInPlanEntry(ctx: TestRailCtx, runId: number, payload: UpdateRunInPlanEntry): Promise { - return _api(ctx, 'POST', `update_run_in_plan_entry/${runId}`, { json: payload }); -} - -export function closePlan(ctx: TestRailCtx, planId: number): Promise { - return _api(ctx, 'POST', `close_plan/${planId}`); -} - -export function deletePlan(ctx: TestRailCtx, planId: number): Promise { - return _api(ctx, 'POST', `delete_plan/${planId}`); -} - -export function deletePlanEntry(ctx: TestRailCtx, planId: number, entryId: string): Promise { - return _api(ctx, 'POST', `delete_plan_entry/${planId}/${entryId}`); -} - -export function deleteRunFromPlanEntry(ctx: TestRailCtx, runId: number): Promise { - return _api(ctx, 'POST', `delete_run_from_plan_entry/${runId}`); -} diff --git a/src/groups/priorities.ts b/src/groups/priorities.ts deleted file mode 100644 index 909f495..0000000 --- a/src/groups/priorities.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { Priority } from '../payload'; - -export function getPriorities(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', 'get_priorities'); -} diff --git a/src/groups/projects.ts b/src/groups/projects.ts deleted file mode 100644 index 91f9165..0000000 --- a/src/groups/projects.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddProject, Project, ProjectFilters, UpdateProject } from '../payload'; - -export function getProject(ctx: TestRailCtx, projectId: number): Promise { - return _api(ctx, 'GET', `get_project/${projectId}`); -} - -export function getProjects(ctx: TestRailCtx, filters?: ProjectFilters): Promise { - return pagination('projects', filters, (filters) => { - return _api(ctx, 'GET', 'get_projects', { query: filters }); - }); -} - -export function addProject(ctx: TestRailCtx, payload: AddProject): Promise { - return _api(ctx, 'POST', 'add_project', { json: payload }); -} - -export function updateProject(ctx: TestRailCtx, projectId: number, payload: UpdateProject): Promise { - return _api(ctx, 'POST', `update_project/${projectId}`, { json: payload }); -} - -export function deleteProject(ctx: TestRailCtx, projectId: number): Promise { - return _api(ctx, 'POST', `delete_project/${projectId}`); -} diff --git a/src/groups/reports.ts b/src/groups/reports.ts deleted file mode 100644 index 16f2bec..0000000 --- a/src/groups/reports.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { Report, ReportUrls } from '../payload'; - -export function getReports(ctx: TestRailCtx, projectId: number): Promise { - return _api(ctx, 'GET', `get_reports/${projectId}`); -} - -export function runReport(ctx: TestRailCtx, reportTemplateId: number): Promise { - return _api(ctx, 'POST', `run_report/${reportTemplateId}`); -} diff --git a/src/groups/result-fields.ts b/src/groups/result-fields.ts deleted file mode 100644 index eea0578..0000000 --- a/src/groups/result-fields.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { ResultField } from '../payload'; - -export function getResultFields(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', 'get_result_fields'); -} diff --git a/src/groups/results.ts b/src/groups/results.ts deleted file mode 100644 index f8961fb..0000000 --- a/src/groups/results.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddResult, AddResults, AddResultsForCases, Result, ResultFilters, ResultForRunFilters } from '../payload'; - -export function getResults(ctx: TestRailCtx, testId: number, filters?: ResultFilters): Promise { - return pagination('results', filters, (filters) => { - return _api(ctx, 'GET', `get_results/${testId}`, { query: filters }); - }); -} - -export function getResultsForCase(ctx: TestRailCtx, runId: number, caseId: number, filters?: ResultFilters): Promise { - return pagination('results', filters, (filters) => { - return _api(ctx, 'GET', `get_results_for_case/${runId}/${caseId}`, { query: filters }); - }); -} - -export function getResultsForRun(ctx: TestRailCtx, runId: number, filters?: ResultForRunFilters): Promise { - return pagination('results', filters, (filters) => { - return _api(ctx, 'GET', `get_results_for_run/${runId}`, { query: filters }); - }); -} - -export function addResult(ctx: TestRailCtx, testId: number, payload: AddResult): Promise { - return _api(ctx, 'POST', `add_result/${testId}`, { json: payload }); -} - -export function addResultForCase(ctx: TestRailCtx, runId: number, caseId: number, payload: AddResult): Promise { - return _api(ctx, 'POST', `add_result_for_case/${runId}/${caseId}`, { json: payload }); -} - -export function addResults(ctx: TestRailCtx, runId: number, payload: AddResults): Promise { - return _api(ctx, 'POST', `add_results/${runId}`, { json: payload }); -} - -export function addResultsForCases(ctx: TestRailCtx, runId: number, payload: AddResultsForCases): Promise { - return _api(ctx, 'POST', `add_results_for_cases/${runId}`, { json: payload }); -} diff --git a/src/groups/roles.ts b/src/groups/roles.ts deleted file mode 100644 index d22c304..0000000 --- a/src/groups/roles.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { Pagination, Role } from '../payload'; - -export function getRoles(ctx: TestRailCtx, filters?: Pagination): Promise { - return pagination('roles', filters, (filters) => { - return _api(ctx, 'GET', 'get_roles', { query: filters }); - }); -} diff --git a/src/groups/runs.ts b/src/groups/runs.ts deleted file mode 100644 index 980e58f..0000000 --- a/src/groups/runs.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddRun, Run, RunFilters, UpdateRun } from '../payload'; - -export function getRun(ctx: TestRailCtx, runId: number): Promise { - return _api(ctx, 'GET', `get_run/${runId}`); -} - -export function getRuns(ctx: TestRailCtx, projectId: number, filters?: RunFilters): Promise { - return pagination('runs', filters, (filters) => { - return _api(ctx, 'GET', `get_runs/${projectId}`, { query: filters }); - }); -} - -export function addRun(ctx: TestRailCtx, projectId: number, payload: AddRun): Promise { - return _api(ctx, 'POST', `add_run/${projectId}`, { json: payload }); -} - -export function updateRun(ctx: TestRailCtx, runId: number, payload: UpdateRun): Promise { - return _api(ctx, 'POST', `update_run/${runId}`, { json: payload }); -} - -export function closeRun(ctx: TestRailCtx, runId: number): Promise { - return _api(ctx, 'POST', `close_run/${runId}`); -} - -export function deleteRun(ctx: TestRailCtx, runId: number): Promise { - return _api(ctx, 'POST', `delete_run/${runId}`); -} diff --git a/src/groups/sections.ts b/src/groups/sections.ts deleted file mode 100644 index 6cbbc55..0000000 --- a/src/groups/sections.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddSection, MoveSection, Section, SectionFilters, UpdateSection } from '../payload'; - -export function getSection(ctx: TestRailCtx, sectionId: number): Promise
{ - return _api(ctx, 'GET', `get_section/${sectionId}`); -} - -export function getSections(ctx: TestRailCtx, projectId: number, filters?: SectionFilters): Promise { - return pagination('sections', filters, (filters) => { - return _api(ctx, 'GET', `get_sections/${projectId}`, { query: filters }); - }); -} - -export function addSection(ctx: TestRailCtx, projectId: number, payload: AddSection): Promise
{ - return _api(ctx, 'POST', `add_section/${projectId}`, { json: payload }); -} - -export function moveSection(ctx: TestRailCtx, sectionId: number, payload: MoveSection): Promise
{ - return _api(ctx, 'POST', `move_section/${sectionId}`, { json: payload }); -} - -export function updateSection(ctx: TestRailCtx, sectionId: number, payload: UpdateSection): Promise
{ - return _api(ctx, 'POST', `update_section/${sectionId}`, { json: payload }); -} - -export function deleteSection(ctx: TestRailCtx, sectionId: number): Promise { - return _api(ctx, 'POST', `delete_section/${sectionId}`); -} diff --git a/src/groups/shared-steps.ts b/src/groups/shared-steps.ts deleted file mode 100644 index 408d9a1..0000000 --- a/src/groups/shared-steps.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddSharedStep, DeleteSharedStep, Pagination, SharedStep, SharedStepFilters, SharedStepHistory, UpdateSharedStep } from '../payload'; - -export function getSharedStep(ctx: TestRailCtx, stepId: number): Promise { - return _api(ctx, 'GET', `get_shared_step/${stepId}`); -} - -export function getSharedSteps(ctx: TestRailCtx, projectId: number, filters?: SharedStepFilters): Promise { - return pagination('shared_steps', filters, (filters) => { - return _api(ctx, 'GET', `get_shared_steps/${projectId}`, { query: filters }); - }); -} - -export function getSharedStepHistory(ctx: TestRailCtx, stepId: number, filters?: Pagination): Promise { - return pagination('step_history', filters, (filters) => { - return _api(ctx, 'GET', `get_shared_step_history/${stepId}`, { query: filters }); - }); -} - -export function addSharedStep(ctx: TestRailCtx, projectId: number, payload: AddSharedStep): Promise { - return _api(ctx, 'POST', `add_shared_step/${projectId}`, { json: payload }); -} - -export function updateSharedStep(ctx: TestRailCtx, stepId: number, payload: UpdateSharedStep): Promise { - return _api(ctx, 'POST', `update_shared_step/${stepId}`, { json: payload }); -} - -export function deleteSharedStep(ctx: TestRailCtx, stepId: number, payload?: DeleteSharedStep): Promise { - return _api(ctx, 'POST', `delete_shared_step/${stepId}`, { json: payload }); -} diff --git a/src/groups/statuses.ts b/src/groups/statuses.ts deleted file mode 100644 index 5e9cfa3..0000000 --- a/src/groups/statuses.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { CaseStatus, Pagination, Status } from '../payload'; - -export function getStatuses(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', 'get_statuses'); -} - -export function getCaseStatuses(ctx: TestRailCtx, filters?: Pagination): Promise { - return pagination('case_statuses', filters, (filters) => { - return _api(ctx, 'GET', 'get_case_statuses', { query: filters }); - }); -} diff --git a/src/groups/suites.ts b/src/groups/suites.ts deleted file mode 100644 index 7c054a6..0000000 --- a/src/groups/suites.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddSuite, Pagination, Suite, UpdateSuite } from '../payload'; - -export function getSuite(ctx: TestRailCtx, suiteId: number): Promise { - return _api(ctx, 'GET', `get_suite/${suiteId}`); -} - -export function getSuites(ctx: TestRailCtx, projectId: number, filters?: Pagination): Promise { - return pagination('suites', filters, (filters) => { - return _api(ctx, 'GET', `get_suites/${projectId}`, { query: filters }); - }); -} - -export function addSuite(ctx: TestRailCtx, projectId: number, payload: AddSuite): Promise { - return _api(ctx, 'POST', `add_suite/${projectId}`, { json: payload }); -} - -export function updateSuite(ctx: TestRailCtx, suiteId: number, payload: UpdateSuite): Promise { - return _api(ctx, 'POST', `update_suite/${suiteId}`, { json: payload }); -} - -export function deleteSuite(ctx: TestRailCtx, suiteId: number): Promise { - return _api(ctx, 'POST', `delete_suite/${suiteId}`); -} diff --git a/src/groups/templates.ts b/src/groups/templates.ts deleted file mode 100644 index 70aba05..0000000 --- a/src/groups/templates.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { _api } from '../internal/request'; -import type { Template } from '../payload'; - -export function getTemplates(ctx: TestRailCtx, projectId: number): Promise { - return _api(ctx, 'GET', `get_templates/${projectId}`); -} diff --git a/src/groups/tests.ts b/src/groups/tests.ts deleted file mode 100644 index a02d921..0000000 --- a/src/groups/tests.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { Test, TestFilters } from '../payload'; - -export function getTest(ctx: TestRailCtx, testId: number): Promise { - return _api(ctx, 'GET', `get_test/${testId}`); -} - -export function getTests(ctx: TestRailCtx, runId: number, filters?: TestFilters): Promise { - return pagination('tests', filters, (filters) => { - return _api(ctx, 'GET', `get_tests/${runId}`, { query: filters }); - }); -} diff --git a/src/groups/users.ts b/src/groups/users.ts deleted file mode 100644 index f832f24..0000000 --- a/src/groups/users.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddUser, User, UserFilters } from '../payload'; - -export function getUser(ctx: TestRailCtx, userId: number): Promise { - return _api(ctx, 'GET', `get_user/${userId}`); -} - -export function getCurrentUser(ctx: TestRailCtx): Promise { - return _api(ctx, 'GET', `get_current_user`); -} - -export function getUserByEmail(ctx: TestRailCtx, email: string): Promise { - return _api(ctx, 'GET', 'get_user_by_email', { query: { email } }); -} - -export function getUsers(ctx: TestRailCtx, filters?: UserFilters): Promise { - return pagination('users', filters, (filters) => { - return _api(ctx, 'GET', 'get_users', { query: filters }); - }); -} - -export function addUser(ctx: TestRailCtx, payload: AddUser): Promise { - return _api(ctx, 'POST', 'add_user', { json: payload }); -} - -export function updateUser(ctx: TestRailCtx, userId: number, payload: AddUser): Promise { - return _api(ctx, 'POST', `update_user/${userId}`, { json: payload }); -} diff --git a/src/groups/variables.ts b/src/groups/variables.ts deleted file mode 100644 index ba0303a..0000000 --- a/src/groups/variables.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { TestRailCtx } from '../TestRailCtx'; -import { pagination } from '../internal/pagination'; -import { _api } from '../internal/request'; -import type { AddVariable, Pagination, Variable } from '../payload'; - -export function getVariables(ctx: TestRailCtx, projectId: number, filters?: Pagination): Promise { - return pagination('variables', filters, (filters) => { - return _api(ctx, 'GET', `get_variables/${projectId}`, { query: filters }); - }); -} - -export function addVariable(ctx: TestRailCtx, projectId: number, payload: AddVariable): Promise { - return _api(ctx, 'POST', `add_variable/${projectId}`, { json: payload }); -} - -export function updateVariable(ctx: TestRailCtx, variableId: number, payload: AddVariable): Promise { - return _api(ctx, 'POST', `update_variable/${variableId}`, { json: payload }); -} - -export function deleteVariable(ctx: TestRailCtx, variableId: number): Promise { - return _api(ctx, 'POST', `delete_variable/${variableId}`); -} diff --git a/src/internal/request.ts b/src/internal/request.ts index 1667ce7..cf6af86 100644 --- a/src/internal/request.ts +++ b/src/internal/request.ts @@ -1,113 +1,68 @@ -import type { TestRailCtx } from '../TestRailCtx.js'; -import { TestRailException } from '../TestRailException'; +import type { TestRailConfig } from '../TestRailConfig.ts'; -declare var FormData: any; -declare type FormData = any; +export type RequestOptions = { + method?: string | undefined; + query?: Record | undefined; + json?: unknown | undefined; + form?: [name: string, value: Blob | string, fileName?: string][] | undefined; + signal?: AbortSignal | undefined; +}; -export async function _api(ctx: TestRailCtx, method: string, path: string, { query, json, form }: { query?: object | undefined; json?: object | undefined; form?: object } = {}): Promise { - const headers: any = {}; - const url = ctx.baseURL + path + qs(query); +export type Executor = (path: string, options: RequestOptions) => Promise; - // Add authentication header - if (ctx.username && ctx.password) { - headers.Authorization = `Basic ${base64(`${ctx.username}:${ctx.password}`)}`; - } +export function createExecutor(config?: TestRailConfig): Executor { + const baseURL = config?.host || ''; - // TestRail requires 'Content-Type: application/json' for all requests except those containing form data - if (!form) { - headers['Content-Type'] = 'application/json'; + let auth: string; + if (config?.username && config.password) { + auth = 'Basic ' + btoa(`${config.username}:${config.password}`); } - // Determine body & request type - let body; - - if (json) { - body = JSON.stringify(json); - } else if (form) { - // @ts-ignore - intentionally throws "ReferrerError" if "FormData" is not available - body = new (ctx.implementations?.FormData || FormData)(); - for (const [key, value] of Object.entries(form)) { - if (value.name && value.value) { - appendToFormData(ctx, body, key, value.value, value.name); - } else { - appendToFormData(ctx, body, key, value); - } - } - } + let paused: Promise | null = null; - while (true) { - // @ts-ignore - intentionally throws "ReferrerError" if "fetch" is not available - const response = await (ctx.implementations?.fetch || fetch)(url, { method, body, headers, signal: ctx.signal }); + return async function (path, options) { + const url = baseURL + path + toQueryString(options.query); + const method = options.method ?? 'GET'; + const headers: Record = {}; + const body = toBody(options); + const signal = options.signal ?? null; - // Content-Type based response - const result = response.headers.get('Content-Type')?.includes('json') - ? await response.json().catch(() => ({})) - : await response.blob(); + const contentType = options.form ? undefined : 'application/json'; + if (contentType) headers['Content-Type'] = contentType; - // Retry on 429 Too Many Requests - if (response.status === 429) { - const retryAfter = parseInt(response.headers.get('Retry-After') || '1') * 1000; - await sleep(retryAfter, ctx.signal); - continue; - } + if (auth) headers['Authorization'] = auth; - // Retry on 409 Conflict - Daily Maintenance - if (response.status === 409) { - await sleep(10 * 1000, ctx.signal); - continue; - } + let attempts = 0; - if (response.ok) { - return result; - } else { - throw new TestRailException(result.error || `No additional error message received: ${response.status} ${response.statusText}`); - } - } -} + while (true) { + if (paused) await withAbort(paused, signal); -function sleep(timeout: number, signal?: AbortSignal): Promise { - if (signal?.aborted) { - return Promise.reject(signal.reason); - } + const response = await fetch(url, { method, headers, body, signal }); - return new Promise((resolve, reject) => { - const timerId = setTimeout( - () => { - resolve(); - signal?.removeEventListener('abort', onAbort); - }, - timeout - ); - - signal?.addEventListener('abort', onAbort, { once: true }); + // 409 - Daily Maintenance + // 429 - Too Many Requests + if (response.status === 409 || response.status === 429) { + if (!paused) { + const retryAfter = response.headers.get('Retry-After'); + const delay = retryAfter + ? (+retryAfter || 0) * 1000 + : Math.min(1000 * 2 ** attempts++, 60_000) + Math.random() * 1000; - function onAbort() { - clearTimeout(timerId); - reject(signal?.reason); - } - }); -} + paused = new Promise((resolve) => setTimeout(resolve, delay)).then(() => { + paused = null; + }); + } -function base64(string: string) { - if (typeof btoa !== 'undefined') { - return btoa(string); - } else { - return Buffer.from(string).toString('base64'); - } -} + await response.blob().catch(() => { }); + continue; + } -function appendToFormData(ctx: TestRailCtx, formData: FormData, name: string, value: string | Blob, filename?: string) { - try { - formData.append(name, value, filename); - } catch { - // @ts-ignore - intentionally throws "ReferrerError" if "Blob" is not available - const BlobConstructor = ctx.implementations?.Blob || Blob; - const blob = value instanceof BlobConstructor ? value : new BlobConstructor([value]); - formData.append(name, blob, filename); - } + return response; + } + }; } -export function qs(object?: Record): string { +export function toQueryString(object?: Record): string { if (!object) { return ''; } @@ -128,3 +83,47 @@ export function qs(object?: Record): string { return qs; } + +function toBody(options: Pick): string | FormData | null { + if (options.json) { + return JSON.stringify(options.json); + } + + if (options.form) { + const body = new FormData(); + for (const [name, content, filename] of options.form) { + const blob = content instanceof Blob ? content : new Blob([content]); + body.append(name, blob, filename); + } + return body; + } + + return null; +} + +function withAbort(promise: Promise, signal?: AbortSignal | null): Promise { + if (!signal) return promise; + + return new Promise((resolve, reject) => { + if (signal.aborted) { + reject(signal.reason); + return; + } + + const onAbort = () => reject(signal.reason); + signal.addEventListener('abort', onAbort, { once: true }); + + const cleanup = () => signal.removeEventListener('abort', onAbort); + + promise.then( + (value) => { + cleanup(); + resolve(value); + }, + (err) => { + cleanup(); + reject(err); + }, + ); + }); +} diff --git a/src/payload/index.ts b/src/payload/index.ts index f6104a5..9ce3c3c 100644 --- a/src/payload/index.ts +++ b/src/payload/index.ts @@ -1,7 +1,2 @@ -import type * as Request from './request'; -import type * as Response from './response'; - -export * from './request'; -export * from './response'; - -export type { Request, Response }; +export * from './request/index.ts'; +export * from './response/index.ts'; diff --git a/src/payload/request/AddAttachment.ts b/src/payload/request/AddAttachment.ts index 5694255..beced67 100644 --- a/src/payload/request/AddAttachment.ts +++ b/src/payload/request/AddAttachment.ts @@ -1,9 +1,4 @@ -import type { Readable } from 'stream'; - -export type AddAttachment = - | Blob - | Readable - | { - name: string; - value: string | Blob | Readable; - }; +export type AddAttachment = { + name: string; + value: string | Blob; +}; diff --git a/src/payload/request/AddCase.ts b/src/payload/request/AddCase.ts index d07495f..1f6313e 100644 --- a/src/payload/request/AddCase.ts +++ b/src/payload/request/AddCase.ts @@ -1,9 +1,9 @@ -export interface AddCase extends Record { - title?: string; - template_id?: number; - type_id?: number; - priority_id?: number; - estimate?: string; - milestone_id?: number; - refs?: string; -} +export type AddCase = Record & { + title?: string | undefined; + template_id?: number | undefined; + type_id?: number | undefined; + priority_id?: number | undefined; + estimate?: string | undefined; + milestone_id?: number | undefined; + refs?: string | undefined; +}; diff --git a/src/payload/request/AddCaseField.ts b/src/payload/request/AddCaseField.ts index af66b5b..806ed2f 100644 --- a/src/payload/request/AddCaseField.ts +++ b/src/payload/request/AddCaseField.ts @@ -1,31 +1,31 @@ -export interface AddCaseField extends Record { - type?: string; - name?: string; - label?: string; - description?: string; - include_all?: boolean; - template_ids?: number[]; - configs?: AddCaseField.CaseFieldConfig[]; -} +export type AddCaseField = Record & { + type?: string | undefined; + name?: string | undefined; + label?: string | undefined; + description?: string | undefined; + include_all?: boolean | undefined; + template_ids?: number[] | undefined; + configs?: AddCaseField.CaseFieldConfig[] | undefined; +}; export namespace AddCaseField { - export interface CaseFieldConfig extends Record { - context?: Context; - options?: Options; - } + export type CaseFieldConfig = Record & { + context?: Context | undefined; + options?: Options | undefined; + }; - export interface Context extends Record { - is_global?: boolean; - project_ids?: number[]; - } + export type Context = Record & { + is_global?: boolean | undefined; + project_ids?: number[] | undefined; + }; - export interface Options extends Record { - default_value?: string; - format?: string; - has_actual?: boolean; - has_expected?: boolean; - is_required?: boolean; - items?: string; - rows?: string; - } + export type Options = Record & { + default_value?: string | undefined; + format?: string | undefined; + has_actual?: boolean | undefined; + has_expected?: boolean | undefined; + is_required?: boolean | undefined; + items?: string | undefined; + rows?: string | undefined; + }; } diff --git a/src/payload/request/AddConfig.ts b/src/payload/request/AddConfig.ts index 6293250..02dc7b3 100644 --- a/src/payload/request/AddConfig.ts +++ b/src/payload/request/AddConfig.ts @@ -1,3 +1,3 @@ -import type { AddConfigGroup } from './AddConfigGroup'; +import type { AddConfigGroup } from './AddConfigGroup.ts'; export type AddConfig = AddConfigGroup; diff --git a/src/payload/request/AddConfigGroup.ts b/src/payload/request/AddConfigGroup.ts index 0cdcc6b..6fd47a8 100644 --- a/src/payload/request/AddConfigGroup.ts +++ b/src/payload/request/AddConfigGroup.ts @@ -1,3 +1,3 @@ -export interface AddConfigGroup extends Record { - name?: string; -} +export type AddConfigGroup = Record & { + name?: string | undefined; +}; diff --git a/src/payload/request/AddDataset.ts b/src/payload/request/AddDataset.ts index ea29bea..899ab8d 100644 --- a/src/payload/request/AddDataset.ts +++ b/src/payload/request/AddDataset.ts @@ -1,13 +1,13 @@ -export interface AddDataset extends Record { - id?: string; - name?: number; - variables?: AddDataset.Variable[]; -} +export type AddDataset = Record & { + id?: string | undefined; + name?: string | undefined; + variables?: AddDataset.Variable[] | undefined; +}; export namespace AddDataset { - export interface Variable extends Record { - id?: number; - name?: string; - variable?: string; - } + export type Variable = Record & { + id?: number | undefined; + name?: string | undefined; + variable?: string | undefined; + }; } diff --git a/src/payload/request/AddGroup.ts b/src/payload/request/AddGroup.ts index 7b1c579..3a2a5cb 100644 --- a/src/payload/request/AddGroup.ts +++ b/src/payload/request/AddGroup.ts @@ -1,4 +1,4 @@ -export interface AddGroup extends Record { - name?: string; - user_ids?: number[]; -} +export type AddGroup = Record & { + name?: string | undefined; + user_ids?: number[] | undefined; +}; diff --git a/src/payload/request/AddMilestone.ts b/src/payload/request/AddMilestone.ts index c6ee06a..573db04 100644 --- a/src/payload/request/AddMilestone.ts +++ b/src/payload/request/AddMilestone.ts @@ -1,8 +1,8 @@ -export interface AddMilestone extends Record { - name?: string; - description?: string; - due_on?: number; - parent_id?: number; - refs?: string; - start_on?: number; -} +export type AddMilestone = Record & { + name?: string | undefined; + description?: string | undefined; + due_on?: number | undefined; + parent_id?: number | undefined; + refs?: string | undefined; + start_on?: number | undefined; +}; diff --git a/src/payload/request/AddPlan.ts b/src/payload/request/AddPlan.ts index 155ee40..73946e5 100644 --- a/src/payload/request/AddPlan.ts +++ b/src/payload/request/AddPlan.ts @@ -1,6 +1,6 @@ -import type { AddPlanEntry } from './AddPlanEntry'; -import type { UpdatePlan } from './UpdatePlan'; +import type { AddPlanEntry } from './AddPlanEntry.ts'; +import type { UpdatePlan } from './UpdatePlan.ts'; -export interface AddPlan extends UpdatePlan { - entries?: AddPlanEntry[]; -} +export type AddPlan = UpdatePlan & { + entries?: AddPlanEntry[] | undefined; +}; diff --git a/src/payload/request/AddPlanEntry.ts b/src/payload/request/AddPlanEntry.ts index 236e04a..876c37c 100644 --- a/src/payload/request/AddPlanEntry.ts +++ b/src/payload/request/AddPlanEntry.ts @@ -1,13 +1,13 @@ -import type { AddRunToPlanEntry } from './AddRunToPlanEntry'; +import type { AddRunToPlanEntry } from './AddRunToPlanEntry.ts'; -export interface AddPlanEntry extends Record { - suite_id?: number; - name?: string; - description?: string; - assignedto_id?: number; - include_all?: boolean; - case_ids?: number[]; - config_ids?: number[]; - refs?: string; - runs?: AddRunToPlanEntry[]; -} +export type AddPlanEntry = Record & { + suite_id?: number | undefined; + name?: string | undefined; + description?: string | undefined; + assignedto_id?: number | undefined; + include_all?: boolean | undefined; + case_ids?: number[] | undefined; + config_ids?: number[] | undefined; + refs?: string | undefined; + runs?: AddRunToPlanEntry[] | undefined; +}; diff --git a/src/payload/request/AddProject.ts b/src/payload/request/AddProject.ts index ae6ffb5..7425677 100644 --- a/src/payload/request/AddProject.ts +++ b/src/payload/request/AddProject.ts @@ -1,6 +1,6 @@ -export interface AddProject extends Record { - name?: string; - announcement?: string; - show_announcement?: boolean; - suite_mode?: number; -} +export type AddProject = Record & { + name?: string | undefined; + announcement?: string | undefined; + show_announcement?: boolean | undefined; + suite_mode?: number | undefined; +}; diff --git a/src/payload/request/AddResult.ts b/src/payload/request/AddResult.ts index e93ecf1..d0a211c 100644 --- a/src/payload/request/AddResult.ts +++ b/src/payload/request/AddResult.ts @@ -1,8 +1,8 @@ -export interface AddResult extends Record { - status_id?: number; - comment?: string; - version?: string; - elapsed?: string; - defects?: string; - assignedto_id?: number; -} +export type AddResult = Record & { + status_id?: number | undefined; + comment?: string | undefined; + version?: string | undefined; + elapsed?: string | undefined; + defects?: string | undefined; + assignedto_id?: number | undefined; +}; diff --git a/src/payload/request/AddResultForCase.ts b/src/payload/request/AddResultForCase.ts index 0100c14..9cfbbaa 100644 --- a/src/payload/request/AddResultForCase.ts +++ b/src/payload/request/AddResultForCase.ts @@ -1,5 +1,5 @@ -import type { AddResult } from './AddResult'; +import type { AddResult } from './AddResult.ts'; -export interface AddResultForCase extends AddResult { - case_id?: number; -} +export type AddResultForCase = AddResult & { + case_id?: number | undefined; +}; diff --git a/src/payload/request/AddResultForTest.ts b/src/payload/request/AddResultForTest.ts index 05b3951..f8da6ce 100644 --- a/src/payload/request/AddResultForTest.ts +++ b/src/payload/request/AddResultForTest.ts @@ -1,5 +1,5 @@ -import type { AddResult } from './AddResult'; +import type { AddResult } from './AddResult.ts'; -export interface AddResultForTest extends AddResult { - test_id?: number; -} +export type AddResultForTest = AddResult & { + test_id?: number | undefined; +}; diff --git a/src/payload/request/AddResults.ts b/src/payload/request/AddResults.ts index b6a419a..2009edd 100644 --- a/src/payload/request/AddResults.ts +++ b/src/payload/request/AddResults.ts @@ -1,5 +1,5 @@ -import type { AddResultForTest } from './AddResultForTest'; +import type { AddResultForTest } from './AddResultForTest.ts'; -export interface AddResults extends Record { - results?: AddResultForTest[]; -} +export type AddResults = Record & { + results?: AddResultForTest[] | undefined; +}; diff --git a/src/payload/request/AddResultsForCases.ts b/src/payload/request/AddResultsForCases.ts index 1b8845d..5df3614 100644 --- a/src/payload/request/AddResultsForCases.ts +++ b/src/payload/request/AddResultsForCases.ts @@ -1,5 +1,5 @@ -import type { AddResultForCase } from './AddResultForCase'; +import type { AddResultForCase } from './AddResultForCase.ts'; -export interface AddResultsForCases extends Record { - results?: AddResultForCase[]; -} +export type AddResultsForCases = Record & { + results?: AddResultForCase[] | undefined; +}; diff --git a/src/payload/request/AddRun.ts b/src/payload/request/AddRun.ts index e45570e..0156734 100644 --- a/src/payload/request/AddRun.ts +++ b/src/payload/request/AddRun.ts @@ -1,6 +1,6 @@ -import type { UpdateRun } from './UpdateRun'; +import type { UpdateRun } from './UpdateRun.ts'; -export interface AddRun extends UpdateRun { - suite_id?: number; - assignedto_id?: number; -} +export type AddRun = UpdateRun & { + suite_id?: number | undefined; + assignedto_id?: number | undefined; +}; diff --git a/src/payload/request/AddRunToPlanEntry.ts b/src/payload/request/AddRunToPlanEntry.ts index 99cb456..f2436da 100644 --- a/src/payload/request/AddRunToPlanEntry.ts +++ b/src/payload/request/AddRunToPlanEntry.ts @@ -1,8 +1,8 @@ -export interface AddRunToPlanEntry extends Record { - config_ids?: number[]; - description?: string; - assignedto_id?: number; - include_all?: boolean; - case_ids?: number[]; - refs?: string; -} +export type AddRunToPlanEntry = Record & { + config_ids?: number[] | undefined; + description?: string | undefined; + assignedto_id?: number | undefined; + include_all?: boolean | undefined; + case_ids?: number[] | undefined; + refs?: string | undefined; +}; diff --git a/src/payload/request/AddSection.ts b/src/payload/request/AddSection.ts index 151544b..9ac9de2 100644 --- a/src/payload/request/AddSection.ts +++ b/src/payload/request/AddSection.ts @@ -1,6 +1,6 @@ -import type { UpdateSection } from './UpdateSection'; +import type { UpdateSection } from './UpdateSection.ts'; -export interface AddSection extends UpdateSection { - parent_id?: number; - suite_id?: number; -} +export type AddSection = UpdateSection & { + parent_id?: number | undefined; + suite_id?: number | undefined; +}; diff --git a/src/payload/request/AddSharedStep.ts b/src/payload/request/AddSharedStep.ts index 303b8ae..e18bf6f 100644 --- a/src/payload/request/AddSharedStep.ts +++ b/src/payload/request/AddSharedStep.ts @@ -1,9 +1,11 @@ -export interface AddSharedStep extends Record { - title?: string; - custom_steps_separated?: { - content?: string; - expected?: string; - additional_info?: string; - refs?: string; - }[]; -} +export type AddSharedStep = Record & { + title?: string | undefined; + custom_steps_separated?: + | { + content?: string | undefined; + expected?: string | undefined; + additional_info?: string | undefined; + refs?: string; + }[] + | undefined; +}; diff --git a/src/payload/request/AddSuite.ts b/src/payload/request/AddSuite.ts index e16cc08..0db0f9b 100644 --- a/src/payload/request/AddSuite.ts +++ b/src/payload/request/AddSuite.ts @@ -1,4 +1,4 @@ -export interface AddSuite extends Record { - name?: string; - description?: string; -} +export type AddSuite = Record & { + name?: string | undefined; + description?: string | undefined; +}; diff --git a/src/payload/request/AddUser.ts b/src/payload/request/AddUser.ts index 79b9d1b..cecb885 100644 --- a/src/payload/request/AddUser.ts +++ b/src/payload/request/AddUser.ts @@ -1,11 +1,11 @@ -export interface AddUser extends Record { - assigned_projects?: number[]; - email?: string; - email_notifications?: boolean; - is_admin?: boolean; - group_ids?: number[]; - mfa_required?: boolean; - name: string; - role_id: number; - sso_enabled: boolean; -} +export type AddUser = Record & { + assigned_projects?: number[] | undefined; + email?: string | undefined; + email_notifications?: boolean | undefined; + is_admin?: boolean | undefined; + group_ids?: number[] | undefined; + mfa_required?: boolean | undefined; + name?: string | undefined; + role_id?: number | undefined; + sso_enabled?: boolean | undefined; +}; diff --git a/src/payload/request/AddVariable.ts b/src/payload/request/AddVariable.ts index cd9dd11..566136d 100644 --- a/src/payload/request/AddVariable.ts +++ b/src/payload/request/AddVariable.ts @@ -1,4 +1,4 @@ -export interface AddVariable extends Record { - id?: string; - name?: number; -} +export type AddVariable = Record & { + id?: string | undefined; + name?: string | undefined; +}; diff --git a/src/payload/request/CaseFilters.ts b/src/payload/request/CaseFilters.ts index 63590d5..d583540 100644 --- a/src/payload/request/CaseFilters.ts +++ b/src/payload/request/CaseFilters.ts @@ -1,18 +1,19 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface CaseFilters extends Pagination, Record { - suite_id?: number; - created_after?: number; - created_before?: number; - created_by?: number | number[]; - filter?: string; - milestone_id?: number | number[]; - priority_id?: number | number[]; - refs?: string; - section_id?: number; - template_id?: number | number[]; - type_id?: number | number[]; - updated_after?: number; - updated_before?: number; - updated_by?: number | number[]; -} +export type CaseFilters = Pagination & + Record & { + suite_id?: number | undefined; + created_after?: number | undefined; + created_before?: number | undefined; + created_by?: number | number[] | undefined; + filter?: string | undefined; + milestone_id?: number | number[] | undefined; + priority_id?: number | number[] | undefined; + refs?: string | undefined; + section_id?: number | undefined; + template_id?: number | number[] | undefined; + type_id?: number | number[] | undefined; + updated_after?: number | undefined; + updated_before?: number | undefined; + updated_by?: number | number[] | undefined; + }; diff --git a/src/payload/request/CopyCasesToSection.ts b/src/payload/request/CopyCasesToSection.ts index 09eacbc..689a4b3 100644 --- a/src/payload/request/CopyCasesToSection.ts +++ b/src/payload/request/CopyCasesToSection.ts @@ -1,3 +1,3 @@ -export interface CopyCasesToSection extends Record { - case_ids?: number[]; -} +export type CopyCasesToSection = Record & { + case_ids?: number[] | undefined; +}; diff --git a/src/payload/request/DeleteCases.ts b/src/payload/request/DeleteCases.ts index 5d04437..a23bbdd 100644 --- a/src/payload/request/DeleteCases.ts +++ b/src/payload/request/DeleteCases.ts @@ -1,3 +1,3 @@ -export interface DeleteCases extends Record { - case_ids?: number[]; -} +export type DeleteCases = Record & { + case_ids?: number[] | undefined; +}; diff --git a/src/payload/request/DeleteSharedStep.ts b/src/payload/request/DeleteSharedStep.ts index 4b7abac..33bf1ab 100644 --- a/src/payload/request/DeleteSharedStep.ts +++ b/src/payload/request/DeleteSharedStep.ts @@ -1,3 +1,3 @@ -export interface DeleteSharedStep extends Record { - keep_in_cases: boolean; -} +export type DeleteSharedStep = Record & { + keep_in_cases?: boolean | undefined; +}; diff --git a/src/payload/request/MilestoneFilters.ts b/src/payload/request/MilestoneFilters.ts index b5eddf6..21afd01 100644 --- a/src/payload/request/MilestoneFilters.ts +++ b/src/payload/request/MilestoneFilters.ts @@ -1,6 +1,7 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface MilestoneFilters extends Pagination, Record { - is_completed?: boolean; - is_started?: boolean; -} +export type MilestoneFilters = Pagination & + Record & { + is_completed?: boolean | undefined; + is_started?: boolean | undefined; + }; diff --git a/src/payload/request/MoveCasesToSection.ts b/src/payload/request/MoveCasesToSection.ts index cf5d71b..62e4c62 100644 --- a/src/payload/request/MoveCasesToSection.ts +++ b/src/payload/request/MoveCasesToSection.ts @@ -1,3 +1,3 @@ -export interface MoveCasesToSection extends Record { - case_ids?: number[]; -} +export type MoveCasesToSection = Record & { + case_ids?: number[] | undefined; +}; diff --git a/src/payload/request/MoveSection.ts b/src/payload/request/MoveSection.ts index 21448bf..4944d12 100644 --- a/src/payload/request/MoveSection.ts +++ b/src/payload/request/MoveSection.ts @@ -1,4 +1,4 @@ -export interface MoveSection extends Record { - parent_id?: number; - after_id?: number; -} +export type MoveSection = Record & { + parent_id?: number | undefined; + after_id?: number | undefined; +}; diff --git a/src/payload/request/Pagination.ts b/src/payload/request/Pagination.ts index 1f952b6..55d7846 100644 --- a/src/payload/request/Pagination.ts +++ b/src/payload/request/Pagination.ts @@ -1,4 +1,4 @@ -export interface Pagination extends Record { - limit?: number; - offset?: number; -} +export type Pagination = Record & { + limit?: number | undefined; + offset?: number | undefined; +}; diff --git a/src/payload/request/PlanFilters.ts b/src/payload/request/PlanFilters.ts index 5bb9823..06b167c 100644 --- a/src/payload/request/PlanFilters.ts +++ b/src/payload/request/PlanFilters.ts @@ -1,9 +1,10 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface PlanFilters extends Pagination, Record { - created_after?: number; - created_before?: number; - created_by?: number | number[]; - is_completed?: boolean; - milestone_id?: number | number[]; -} +export type PlanFilters = Pagination & + Record & { + created_after?: number | undefined; + created_before?: number | undefined; + created_by?: number | number[] | undefined; + is_completed?: boolean | undefined; + milestone_id?: number | number[] | undefined; + }; diff --git a/src/payload/request/ProjectFilters.ts b/src/payload/request/ProjectFilters.ts index 10ed50f..1fca96d 100644 --- a/src/payload/request/ProjectFilters.ts +++ b/src/payload/request/ProjectFilters.ts @@ -1,5 +1,6 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface ProjectFilters extends Pagination, Record { - is_completed?: boolean; -} +export type ProjectFilters = Pagination & + Record & { + is_completed?: boolean | undefined; + }; diff --git a/src/payload/request/ResultFilters.ts b/src/payload/request/ResultFilters.ts index 59c47db..b8bccb4 100644 --- a/src/payload/request/ResultFilters.ts +++ b/src/payload/request/ResultFilters.ts @@ -1,6 +1,7 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface ResultFilters extends Pagination, Record { - defects?: string; - status_id?: number | number[]; -} +export type ResultFilters = Pagination & + Record & { + defects?: string | undefined; + status_id?: number | number[] | undefined; + }; diff --git a/src/payload/request/ResultForRunFilters.ts b/src/payload/request/ResultForRunFilters.ts index b7cc56d..c6c9478 100644 --- a/src/payload/request/ResultForRunFilters.ts +++ b/src/payload/request/ResultForRunFilters.ts @@ -1,9 +1,10 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface ResultForRunFilters extends Pagination, Record { - created_after?: number; - created_before?: number; - created_by?: number | number[]; - defects?: string; - status_id?: number | number[]; -} +export type ResultForRunFilters = Pagination & + Record & { + created_after?: number | undefined; + created_before?: number | undefined; + created_by?: number | number[] | undefined; + defects?: string | undefined; + status_id?: number | number[] | undefined; + }; diff --git a/src/payload/request/RunFilters.ts b/src/payload/request/RunFilters.ts index 09fb5ca..ff94cc9 100644 --- a/src/payload/request/RunFilters.ts +++ b/src/payload/request/RunFilters.ts @@ -1,11 +1,12 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface RunFilters extends Pagination, Record { - created_after?: number; - created_before?: number; - created_by?: number | number[]; - is_completed?: boolean; - milestone_id?: number | number[]; - refs?: string; - suite_id?: number | number[]; -} +export type RunFilters = Pagination & + Record & { + created_after?: number | undefined; + created_before?: number | undefined; + created_by?: number | number[] | undefined; + is_completed?: boolean | undefined; + milestone_id?: number | number[] | undefined; + refs?: string | undefined; + suite_id?: number | number[] | undefined; + }; diff --git a/src/payload/request/SectionFilters.ts b/src/payload/request/SectionFilters.ts index 44e76ea..d0a89ab 100644 --- a/src/payload/request/SectionFilters.ts +++ b/src/payload/request/SectionFilters.ts @@ -1,5 +1,6 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface SectionFilters extends Pagination, Record { - suite_id?: number; -} +export type SectionFilters = Pagination & + Record & { + suite_id?: number | undefined; + }; diff --git a/src/payload/request/SharedStepFilters.ts b/src/payload/request/SharedStepFilters.ts index 9406040..889f79c 100644 --- a/src/payload/request/SharedStepFilters.ts +++ b/src/payload/request/SharedStepFilters.ts @@ -1,10 +1,11 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface SharedStepFilters extends Pagination, Record { - created_after?: number; - created_before?: number; - created_by?: number | number[]; - updated_after?: number; - updated_before?: number; - refs?: string; -} +export type SharedStepFilters = Pagination & + Record & { + created_after?: number | undefined; + created_before?: number | undefined; + created_by?: number | number[] | undefined; + updated_after?: number | undefined; + updated_before?: number | undefined; + refs?: string | undefined; + }; diff --git a/src/payload/request/TestFilters.ts b/src/payload/request/TestFilters.ts index 74235b5..0fdc030 100644 --- a/src/payload/request/TestFilters.ts +++ b/src/payload/request/TestFilters.ts @@ -1,5 +1,6 @@ -import type { Pagination } from './Pagination'; +import type { Pagination } from './Pagination.ts'; -export interface TestFilters extends Pagination, Record { - status_id?: number | number[]; -} +export type TestFilters = Pagination & + Record & { + status_id?: number | number[] | undefined; + }; diff --git a/src/payload/request/UpdateCase.ts b/src/payload/request/UpdateCase.ts index 32653e3..a8438c8 100644 --- a/src/payload/request/UpdateCase.ts +++ b/src/payload/request/UpdateCase.ts @@ -1,5 +1,5 @@ -import type { AddCase } from './AddCase'; +import type { AddCase } from './AddCase.ts'; -export interface UpdateCase extends AddCase { - section_id?: number; -} +export type UpdateCase = AddCase & { + section_id?: number | undefined; +}; diff --git a/src/payload/request/UpdateCases.ts b/src/payload/request/UpdateCases.ts index 5585c5c..ef7857f 100644 --- a/src/payload/request/UpdateCases.ts +++ b/src/payload/request/UpdateCases.ts @@ -1,5 +1,5 @@ -import type { UpdateCase } from './UpdateCase'; +import type { UpdateCase } from './UpdateCase.ts'; -export interface UpdateCases extends UpdateCase { - case_ids?: number[]; -} +export type UpdateCases = UpdateCase & { + case_ids?: number[] | undefined; +}; diff --git a/src/payload/request/UpdateConfig.ts b/src/payload/request/UpdateConfig.ts index 3537017..c0917a5 100644 --- a/src/payload/request/UpdateConfig.ts +++ b/src/payload/request/UpdateConfig.ts @@ -1,3 +1,3 @@ -import type { AddConfigGroup } from './AddConfigGroup'; +import type { AddConfigGroup } from './AddConfigGroup.ts'; export type UpdateConfig = AddConfigGroup; diff --git a/src/payload/request/UpdateConfigGroup.ts b/src/payload/request/UpdateConfigGroup.ts index d3e27f3..6ad709a 100644 --- a/src/payload/request/UpdateConfigGroup.ts +++ b/src/payload/request/UpdateConfigGroup.ts @@ -1,3 +1,3 @@ -import type { AddConfigGroup } from './AddConfigGroup'; +import type { AddConfigGroup } from './AddConfigGroup.ts'; export type UpdateConfigGroup = AddConfigGroup; diff --git a/src/payload/request/UpdateMilestone.ts b/src/payload/request/UpdateMilestone.ts index f18aaa4..729296b 100644 --- a/src/payload/request/UpdateMilestone.ts +++ b/src/payload/request/UpdateMilestone.ts @@ -1,6 +1,6 @@ -import type { AddMilestone } from './AddMilestone'; +import type { AddMilestone } from './AddMilestone.ts'; -export interface UpdateMilestone extends AddMilestone { - is_completed?: boolean; - is_started?: boolean; -} +export type UpdateMilestone = AddMilestone & { + is_completed?: boolean | undefined; + is_started?: boolean | undefined; +}; diff --git a/src/payload/request/UpdatePlan.ts b/src/payload/request/UpdatePlan.ts index 19ead71..5154bba 100644 --- a/src/payload/request/UpdatePlan.ts +++ b/src/payload/request/UpdatePlan.ts @@ -1,5 +1,5 @@ -export interface UpdatePlan extends Record { - name?: string; - description?: string; - milestone_id?: number; -} +export type UpdatePlan = Record & { + name?: string | undefined; + description?: string | undefined; + milestone_id?: number | undefined; +}; diff --git a/src/payload/request/UpdatePlanEntry.ts b/src/payload/request/UpdatePlanEntry.ts index 41a6833..33a8557 100644 --- a/src/payload/request/UpdatePlanEntry.ts +++ b/src/payload/request/UpdatePlanEntry.ts @@ -1,8 +1,8 @@ -export interface UpdatePlanEntry extends Record { - name?: string; - description?: string; - assignedto_id?: number; - include_all?: boolean; - case_ids?: number[]; - refs?: string; -} +export type UpdatePlanEntry = Record & { + name?: string | undefined; + description?: string | undefined; + assignedto_id?: number | undefined; + include_all?: boolean | undefined; + case_ids?: number[] | undefined; + refs?: string | undefined; +}; diff --git a/src/payload/request/UpdateProject.ts b/src/payload/request/UpdateProject.ts index 2a896ce..db47826 100644 --- a/src/payload/request/UpdateProject.ts +++ b/src/payload/request/UpdateProject.ts @@ -1,3 +1,3 @@ -import type { AddProject } from './AddProject'; +import type { AddProject } from './AddProject.ts'; export type UpdateProject = AddProject; diff --git a/src/payload/request/UpdateRun.ts b/src/payload/request/UpdateRun.ts index 980e3d1..7cf03f3 100644 --- a/src/payload/request/UpdateRun.ts +++ b/src/payload/request/UpdateRun.ts @@ -1,8 +1,8 @@ -export interface UpdateRun extends Record { - name?: string; - description?: string; - milestone_id?: number; - include_all?: boolean; - case_ids?: number[]; - refs?: string; -} +export type UpdateRun = Record & { + name?: string | undefined; + description?: string | undefined; + milestone_id?: number | undefined; + include_all?: boolean | undefined; + case_ids?: number[] | undefined; + refs?: string | undefined; +}; diff --git a/src/payload/request/UpdateRunInPlanEntry.ts b/src/payload/request/UpdateRunInPlanEntry.ts index 2b1ecaf..a0b56be 100644 --- a/src/payload/request/UpdateRunInPlanEntry.ts +++ b/src/payload/request/UpdateRunInPlanEntry.ts @@ -1,7 +1,7 @@ -export interface UpdateRunInPlanEntry extends Record { - description?: string; - assignedto_id?: number; - include_all?: boolean; - case_ids?: number[]; - refs?: string; -} +export type UpdateRunInPlanEntry = Record & { + description?: string | undefined; + assignedto_id?: number | undefined; + include_all?: boolean | undefined; + case_ids?: number[] | undefined; + refs?: string | undefined; +}; diff --git a/src/payload/request/UpdateSection.ts b/src/payload/request/UpdateSection.ts index 9c90459..63b252a 100644 --- a/src/payload/request/UpdateSection.ts +++ b/src/payload/request/UpdateSection.ts @@ -1,4 +1,4 @@ -export interface UpdateSection extends Record { - description?: string; - name?: string; -} +export type UpdateSection = Record & { + description?: string | undefined; + name?: string | undefined; +}; diff --git a/src/payload/request/UpdateSharedStep.ts b/src/payload/request/UpdateSharedStep.ts index eba9595..10255b4 100644 --- a/src/payload/request/UpdateSharedStep.ts +++ b/src/payload/request/UpdateSharedStep.ts @@ -1,3 +1,3 @@ -import type { AddSharedStep } from './AddSharedStep'; +import type { AddSharedStep } from './AddSharedStep.ts'; export type UpdateSharedStep = AddSharedStep; diff --git a/src/payload/request/UpdateSuite.ts b/src/payload/request/UpdateSuite.ts index e068e5c..7b3a336 100644 --- a/src/payload/request/UpdateSuite.ts +++ b/src/payload/request/UpdateSuite.ts @@ -1,3 +1,3 @@ -import type { AddSuite } from './AddSuite'; +import type { AddSuite } from './AddSuite.ts'; export type UpdateSuite = AddSuite; diff --git a/src/payload/request/UserFilters.ts b/src/payload/request/UserFilters.ts index 0b799b5..ccebf14 100644 --- a/src/payload/request/UserFilters.ts +++ b/src/payload/request/UserFilters.ts @@ -1,5 +1,6 @@ -import type { Pagination } from "./Pagination"; +import type { Pagination } from './Pagination.ts'; -export interface UserFilters extends Pagination, Record { - project_id?: number; -} +export type UserFilters = Pagination & + Record & { + project_id?: number | undefined; + }; diff --git a/src/payload/request/index.ts b/src/payload/request/index.ts index 23594e6..23fd862 100644 --- a/src/payload/request/index.ts +++ b/src/payload/request/index.ts @@ -1,53 +1,53 @@ -export * from './AddAttachment'; -export * from './AddCase'; -export * from './AddCaseField'; -export * from './AddConfig'; -export * from './AddConfigGroup'; -export * from './AddDataset'; -export * from './AddGroup'; -export * from './AddMilestone'; -export * from './AddPlan'; -export * from './AddPlanEntry'; -export * from './AddProject'; -export * from './AddResult'; -export * from './AddResultForCase'; -export * from './AddResultForTest'; -export * from './AddResults'; -export * from './AddResultsForCases'; -export * from './AddRun'; -export * from './AddRunToPlanEntry'; -export * from './AddSection'; -export * from './AddSharedStep'; -export * from './AddSuite'; -export * from './AddUser'; -export * from './AddVariable'; -export * from './CaseFilters'; -export * from './CopyCasesToSection'; -export * from './DeleteCases'; -export * from './DeleteSharedStep'; -export * from './MilestoneFilters'; -export * from './MoveCasesToSection'; -export * from './MoveSection'; -export * from './Pagination'; -export * from './PlanFilters'; -export * from './ProjectFilters'; -export * from './ResultFilters'; -export * from './ResultForRunFilters'; -export * from './RunFilters'; -export * from './SectionFilters'; -export * from './SharedStepFilters'; -export * from './TestFilters'; -export * from './UpdateCase'; -export * from './UpdateCases'; -export * from './UpdateConfig'; -export * from './UpdateConfigGroup'; -export * from './UpdateMilestone'; -export * from './UpdatePlan'; -export * from './UpdatePlanEntry'; -export * from './UpdateProject'; -export * from './UpdateRun'; -export * from './UpdateRunInPlanEntry'; -export * from './UpdateSection'; -export * from './UpdateSharedStep'; -export * from './UpdateSuite'; -export * from './UserFilters'; +export * from './AddAttachment.ts'; +export * from './AddCase.ts'; +export * from './AddCaseField.ts'; +export * from './AddConfig.ts'; +export * from './AddConfigGroup.ts'; +export * from './AddDataset.ts'; +export * from './AddGroup.ts'; +export * from './AddMilestone.ts'; +export * from './AddPlan.ts'; +export * from './AddPlanEntry.ts'; +export * from './AddProject.ts'; +export * from './AddResult.ts'; +export * from './AddResultForCase.ts'; +export * from './AddResultForTest.ts'; +export * from './AddResults.ts'; +export * from './AddResultsForCases.ts'; +export * from './AddRun.ts'; +export * from './AddRunToPlanEntry.ts'; +export * from './AddSection.ts'; +export * from './AddSharedStep.ts'; +export * from './AddSuite.ts'; +export * from './AddUser.ts'; +export * from './AddVariable.ts'; +export * from './CaseFilters.ts'; +export * from './CopyCasesToSection.ts'; +export * from './DeleteCases.ts'; +export * from './DeleteSharedStep.ts'; +export * from './MilestoneFilters.ts'; +export * from './MoveCasesToSection.ts'; +export * from './MoveSection.ts'; +export * from './Pagination.ts'; +export * from './PlanFilters.ts'; +export * from './ProjectFilters.ts'; +export * from './ResultFilters.ts'; +export * from './ResultForRunFilters.ts'; +export * from './RunFilters.ts'; +export * from './SectionFilters.ts'; +export * from './SharedStepFilters.ts'; +export * from './TestFilters.ts'; +export * from './UpdateCase.ts'; +export * from './UpdateCases.ts'; +export * from './UpdateConfig.ts'; +export * from './UpdateConfigGroup.ts'; +export * from './UpdateMilestone.ts'; +export * from './UpdatePlan.ts'; +export * from './UpdatePlanEntry.ts'; +export * from './UpdateProject.ts'; +export * from './UpdateRun.ts'; +export * from './UpdateRunInPlanEntry.ts'; +export * from './UpdateSection.ts'; +export * from './UpdateSharedStep.ts'; +export * from './UpdateSuite.ts'; +export * from './UserFilters.ts'; diff --git a/src/payload/response/AttachmentForCase.ts b/src/payload/response/AttachmentForCase.ts index 70c9810..4dcf824 100644 --- a/src/payload/response/AttachmentForCase.ts +++ b/src/payload/response/AttachmentForCase.ts @@ -1,4 +1,4 @@ -import type { Attachment } from './Attachment'; +import type { Attachment } from './Attachment.ts'; export interface AttachmentForCase extends Attachment { entity_type: 'case'; diff --git a/src/payload/response/AttachmentForPlan.ts b/src/payload/response/AttachmentForPlan.ts index 2f46294..7b598ed 100644 --- a/src/payload/response/AttachmentForPlan.ts +++ b/src/payload/response/AttachmentForPlan.ts @@ -1,4 +1,4 @@ -import type { Attachment } from './Attachment'; +import type { Attachment } from './Attachment.ts'; export interface AttachmentForPlan extends Attachment { entity_type: 'plan'; diff --git a/src/payload/response/AttachmentForPlanEntry.ts b/src/payload/response/AttachmentForPlanEntry.ts index 1acce44..1074c2b 100644 --- a/src/payload/response/AttachmentForPlanEntry.ts +++ b/src/payload/response/AttachmentForPlanEntry.ts @@ -1,4 +1,4 @@ -import type { Attachment } from './Attachment'; +import type { Attachment } from './Attachment.ts'; export interface AttachmentForPlanEntry extends Attachment { entity_type: 'entry'; diff --git a/src/payload/response/AttachmentForRun.ts b/src/payload/response/AttachmentForRun.ts index 8926455..45259eb 100644 --- a/src/payload/response/AttachmentForRun.ts +++ b/src/payload/response/AttachmentForRun.ts @@ -1,4 +1,4 @@ -import type { Attachment } from './Attachment'; +import type { Attachment } from './Attachment.ts'; export interface AttachmentForRun extends Attachment { entity_type: 'run'; diff --git a/src/payload/response/AttachmentForTest.ts b/src/payload/response/AttachmentForTest.ts index d537bb1..c9bfc57 100644 --- a/src/payload/response/AttachmentForTest.ts +++ b/src/payload/response/AttachmentForTest.ts @@ -1,4 +1,4 @@ -import type { Attachment } from './Attachment'; +import type { Attachment } from './Attachment.ts'; export interface AttachmentForTest extends Attachment { entity_type: 'test_change'; diff --git a/src/payload/response/CaseField.ts b/src/payload/response/CaseField.ts index 80cda26..142121c 100644 --- a/src/payload/response/CaseField.ts +++ b/src/payload/response/CaseField.ts @@ -1,4 +1,4 @@ -import type { Context } from './Context'; +import type { Context } from './Context.ts'; export interface CaseField extends Record { configs: CaseField.CaseFieldConfig[]; diff --git a/src/payload/response/CaseHistory.ts b/src/payload/response/CaseHistory.ts index caf2261..b65ebe5 100644 --- a/src/payload/response/CaseHistory.ts +++ b/src/payload/response/CaseHistory.ts @@ -1,4 +1,4 @@ -import type { Option } from './Option'; +import type { Option } from './Option.ts'; export interface CaseHistory extends Record { changes: CaseHistory.Change[]; diff --git a/src/payload/response/Config.ts b/src/payload/response/Config.ts index 01ea518..5e5554b 100644 --- a/src/payload/response/Config.ts +++ b/src/payload/response/Config.ts @@ -1,4 +1,4 @@ -import type { ConfigItem } from './ConfigItem'; +import type { ConfigItem } from './ConfigItem.ts'; export interface Config extends Record { configs: ConfigItem[]; diff --git a/src/payload/response/Dataset.ts b/src/payload/response/Dataset.ts index 80bdbe0..153c0fc 100644 --- a/src/payload/response/Dataset.ts +++ b/src/payload/response/Dataset.ts @@ -1,4 +1,4 @@ -import type { Variable } from './Variables'; +import type { Variable } from './Variables.ts'; export interface Dataset extends Record { id: number; diff --git a/src/payload/response/FieldConfig.ts b/src/payload/response/FieldConfig.ts index 486c9f6..836133f 100644 --- a/src/payload/response/FieldConfig.ts +++ b/src/payload/response/FieldConfig.ts @@ -1,5 +1,5 @@ -import type { Context } from './Context'; -import type { Option } from './Option'; +import type { Context } from './Context.ts'; +import type { Option } from './Option.ts'; export interface FieldConfig extends Record { context: Context; diff --git a/src/payload/response/Plan.ts b/src/payload/response/Plan.ts index 92f540e..f1ba394 100644 --- a/src/payload/response/Plan.ts +++ b/src/payload/response/Plan.ts @@ -1,4 +1,4 @@ -import type { PlanEntry } from './PlanEntry'; +import type { PlanEntry } from './PlanEntry.ts'; export interface Plan extends Record { assignedto_id?: number; diff --git a/src/payload/response/PlanEntry.ts b/src/payload/response/PlanEntry.ts index f4d03af..871a53d 100644 --- a/src/payload/response/PlanEntry.ts +++ b/src/payload/response/PlanEntry.ts @@ -1,4 +1,4 @@ -import type { PlanEntryRun } from './PlanEntryRun'; +import type { PlanEntryRun } from './PlanEntryRun.ts'; export interface PlanEntry extends Record { description?: string; diff --git a/src/payload/response/ResultField.ts b/src/payload/response/ResultField.ts index be1791b..f241f96 100644 --- a/src/payload/response/ResultField.ts +++ b/src/payload/response/ResultField.ts @@ -1,4 +1,4 @@ -import type { FieldConfig } from './FieldConfig'; +import type { FieldConfig } from './FieldConfig.ts'; export interface ResultField extends Record { configs: FieldConfig[]; diff --git a/src/payload/response/SharedStepHistory.ts b/src/payload/response/SharedStepHistory.ts index 54eac81..c7bcac7 100644 --- a/src/payload/response/SharedStepHistory.ts +++ b/src/payload/response/SharedStepHistory.ts @@ -1,4 +1,4 @@ -import type { SharedStep } from './SharedStep'; +import type { SharedStep } from './SharedStep.ts'; export interface SharedStepHistory extends Record { custom_steps_separated: SharedStep['custom_steps_separated']; diff --git a/src/payload/response/index.ts b/src/payload/response/index.ts index 4060631..8e0e725 100644 --- a/src/payload/response/index.ts +++ b/src/payload/response/index.ts @@ -1,41 +1,41 @@ -export * from './Attachment'; -export * from './AttachmentForCase'; -export * from './AttachmentForPlan'; -export * from './AttachmentForPlanEntry'; -export * from './AttachmentForRun'; -export * from './AttachmentForTest'; -export * from './Case'; -export * from './CaseField'; -export * from './CaseHistory'; -export * from './CaseStatus'; -export * from './CaseType'; -export * from './Config'; -export * from './ConfigItem'; -export * from './Context'; -export * from './CreatedAttachment'; -export * from './Dataset'; -export * from './FieldConfig'; -export * from './Group'; -export * from './Milestone'; -export * from './Option'; -export * from './Plan'; -export * from './PlanEntry'; -export * from './PlanEntryRun'; -export * from './PlanItem'; -export * from './Priority'; -export * from './Project'; -export * from './Report'; -export * from './ReportUrls'; -export * from './Result'; -export * from './ResultField'; -export * from './Role'; -export * from './Run'; -export * from './Section'; -export * from './SharedStep'; -export * from './SharedStepHistory'; -export * from './Status'; -export * from './Suite'; -export * from './Template'; -export * from './Test'; -export * from './User'; -export * from './Variables'; +export * from './Attachment.ts'; +export * from './AttachmentForCase.ts'; +export * from './AttachmentForPlan.ts'; +export * from './AttachmentForPlanEntry.ts'; +export * from './AttachmentForRun.ts'; +export * from './AttachmentForTest.ts'; +export * from './Case.ts'; +export * from './CaseField.ts'; +export * from './CaseHistory.ts'; +export * from './CaseStatus.ts'; +export * from './CaseType.ts'; +export * from './Config.ts'; +export * from './ConfigItem.ts'; +export * from './Context.ts'; +export * from './CreatedAttachment.ts'; +export * from './Dataset.ts'; +export * from './FieldConfig.ts'; +export * from './Group.ts'; +export * from './Milestone.ts'; +export * from './Option.ts'; +export * from './Plan.ts'; +export * from './PlanEntry.ts'; +export * from './PlanEntryRun.ts'; +export * from './PlanItem.ts'; +export * from './Priority.ts'; +export * from './Project.ts'; +export * from './Report.ts'; +export * from './ReportUrls.ts'; +export * from './Result.ts'; +export * from './ResultField.ts'; +export * from './Role.ts'; +export * from './Run.ts'; +export * from './Section.ts'; +export * from './SharedStep.ts'; +export * from './SharedStepHistory.ts'; +export * from './Status.ts'; +export * from './Suite.ts'; +export * from './Template.ts'; +export * from './Test.ts'; +export * from './User.ts'; +export * from './Variables.ts'; diff --git a/test/_helper.ts b/test/_helper.ts index 3913882..3ae5ecf 100644 --- a/test/_helper.ts +++ b/test/_helper.ts @@ -1,14 +1,22 @@ -import chai from 'chai'; +/// + +import * as chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import fs from 'fs'; import { globSync } from 'glob'; import { mock as tsMock } from 'intermock'; import nock, { type RequestBodyMatcher } from 'nock'; -import TestRail from '..'; +import fs from 'node:fs'; +import { TestRail } from '../src/TestRail.ts'; +export { toQueryString as qs } from '../src/internal/request.ts'; -export { qs } from '../src/internal/request'; +chai.should(); +chai.use(chaiAsPromised); -chai.use(chaiAsPromised).should(); +declare global { + interface Promise { + should: Chai.Assertion; + } +} const tsFiles: [string, string][] = globSync('./src/**/*.ts') .map((file) => [file, fs.readFileSync(file, { encoding: 'utf-8' })]); @@ -20,10 +28,10 @@ export const BAD_REQUEST = 400; export const TO_MANY_REQUEST = 429; export const CONFLICT = 409; export const prefix = '/index.php?/api/v2/'; -export const host = 'https://dlenroc.testrail.com'; +export const baseURL = 'https://dlenroc.testrail.com'; export const username = 'Username'; export const password = 'Password/Token'; -export const api = new TestRail({ host, username, password }); +export const api = new TestRail({ host: baseURL, username, password }); export function on(path: string, requestBody?: RequestBodyMatcher | any) { const options = { @@ -34,7 +42,7 @@ export function on(path: string, requestBody?: RequestBodyMatcher | any) { }, }; - const scope = nock(host, options); + const scope = nock(baseURL, options); let interceptor = path.startsWith('get') ? scope.get(prefix + path, requestBody) diff --git a/test/attachments.ts b/test/attachments.ts index 1bf0433..48f7dc1 100644 --- a/test/attachments.ts +++ b/test/attachments.ts @@ -1,15 +1,16 @@ import { faker } from '@faker-js/faker'; -import type { AddAttachment, Attachment, AttachmentForCase, AttachmentForPlan, AttachmentForPlanEntry, AttachmentForRun, AttachmentForTest, CreatedAttachment } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddAttachment, Attachment, AttachmentForCase, AttachmentForPlan, AttachmentForPlanEntry, AttachmentForRun, AttachmentForTest, CreatedAttachment } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Attachments', () => { - const planId = faker.datatype.number(); - const entryId = faker.datatype.uuid(); - const resultId = faker.datatype.number(); - const runId = faker.datatype.number(); - const caseId = faker.datatype.number(); - const testId = faker.datatype.number(); - const attachmentId = faker.datatype.uuid(); + const planId = faker.number.int(); + const entryId = faker.string.uuid(); + const resultId = faker.number.int(); + const runId = faker.number.int(); + const caseId = faker.number.int(); + const testId = faker.number.int(); + const attachmentId = faker.string.uuid(); const createdAttachment: CreatedAttachment = jsonFor('CreatedAttachment'); const attachmentForCase: AttachmentForCase = jsonFor('AttachmentForCase'); const attachmentsForCase = [attachmentForCase]; @@ -25,7 +26,7 @@ describe('Attachments', () => { const hasAttachment = /form-data; name="attachment"/m; const addAttachmentPayload: AddAttachment = { name: 'attachment.txt', - value: faker.random.words(), + value: faker.word.words(), }; it('add attachment to plan', async () => { diff --git a/test/bdd.ts b/test/bdd.ts index f5b6a3c..0a6e281 100644 --- a/test/bdd.ts +++ b/test/bdd.ts @@ -1,11 +1,12 @@ import { faker } from '@faker-js/faker'; -import type { AddAttachment, Case } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddAttachment, Case } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('BDD', () => { - const caseId = faker.datatype.number(); - const sectionId = faker.datatype.number(); - const bddFeature = faker.random.words(); + const caseId = faker.number.int(); + const sectionId = faker.number.int(); + const bddFeature = faker.word.words(); const testCase: Case = jsonFor('Case'); const hasAttachment = /form-data; name="attachment"/m; const addFeaturePayload: AddAttachment = { diff --git a/test/caseFields.ts b/test/caseFields.ts index f8b5b3e..5542c96 100644 --- a/test/caseFields.ts +++ b/test/caseFields.ts @@ -1,5 +1,6 @@ -import type { AddCaseField, CaseField } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddCaseField, CaseField } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Case Fields', () => { const caseField: CaseField = jsonFor('CaseField'); diff --git a/test/caseTypes.ts b/test/caseTypes.ts index 43df0a5..7a58485 100644 --- a/test/caseTypes.ts +++ b/test/caseTypes.ts @@ -1,5 +1,6 @@ -import type { CaseType } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { CaseType } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Case Types', () => { const caseType: CaseType = jsonFor('CaseType'); diff --git a/test/cases.ts b/test/cases.ts index 44a6162..92b4268 100644 --- a/test/cases.ts +++ b/test/cases.ts @@ -1,12 +1,13 @@ import { faker } from '@faker-js/faker'; -import type { AddCase, Case, CaseFilters, CaseHistory, DeleteCases, UpdateCase, UpdateCases } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddCase, Case, CaseFilters, CaseHistory, DeleteCases, UpdateCase, UpdateCases } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Cases', () => { - const caseId = faker.datatype.number(); - const projectId = faker.datatype.number(); - const sectionId = faker.datatype.number(); - const suiteId = faker.datatype.number(); + const caseId = faker.number.int(); + const projectId = faker.number.int(); + const sectionId = faker.number.int(); + const suiteId = faker.number.int(); const testCase: Case = jsonFor('Case'); const testCases = [testCase]; const caseFilters: CaseFilters = jsonFor('CaseFilters'); diff --git a/test/configurations.ts b/test/configurations.ts index bb4e0fe..22f7a4f 100644 --- a/test/configurations.ts +++ b/test/configurations.ts @@ -1,11 +1,12 @@ import { faker } from '@faker-js/faker'; -import type { AddConfig, AddConfigGroup, Config, ConfigItem, UpdateConfig, UpdateConfigGroup } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddConfig, AddConfigGroup, Config, ConfigItem, UpdateConfig, UpdateConfigGroup } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Configurations', () => { - const projectId = faker.datatype.number(); - const configGroupId = faker.datatype.number(); - const configId = faker.datatype.number(); + const projectId = faker.number.int(); + const configGroupId = faker.number.int(); + const configId = faker.number.int(); const config: Config = jsonFor('Config'); const configItem: ConfigItem = jsonFor('ConfigItem'); const configs = [config]; diff --git a/test/dataset.ts b/test/dataset.ts index 8267241..13a4a70 100644 --- a/test/dataset.ts +++ b/test/dataset.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddDataset, Dataset } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddDataset, Dataset } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Dataset', () => { - const projectId = faker.datatype.number(); - const datasetId = faker.datatype.number(); + const projectId = faker.number.int(); + const datasetId = faker.number.int(); const dataset: Dataset = jsonFor('Dataset'); const datasets: Dataset[] = [dataset]; const addOrUpdateDatesetPayload: AddDataset = jsonFor('AddDataset'); diff --git a/test/errors.ts b/test/errors.ts index cf107dd..1fb975f 100644 --- a/test/errors.ts +++ b/test/errors.ts @@ -1,5 +1,6 @@ -import { Exception } from '..'; -import { api, BAD_REQUEST, OK, on, TO_MANY_REQUEST } from './_helper'; +import { describe, it } from 'node:test'; +import { TestRailException } from '../src/TestRailException.ts'; +import { api, BAD_REQUEST, OK, on, TO_MANY_REQUEST } from './_helper.ts'; describe('Errors', () => { const success = { success: true }; @@ -12,7 +13,7 @@ describe('Errors', () => { await api .getCurrentUser() - .should.be.rejectedWith(Exception, customError); + .should.be.rejectedWith(TestRailException, customError); }); it('error without message', async () => { @@ -21,7 +22,7 @@ describe('Errors', () => { await api .getCurrentUser() - .should.be.rejectedWith(Exception, defaultError); + .should.be.rejectedWith(TestRailException, defaultError); }); it('429 Too Many Requests - with `Retry-After` header', async () => { diff --git a/test/groups.ts b/test/groups.ts index 8189d47..e106af0 100644 --- a/test/groups.ts +++ b/test/groups.ts @@ -1,9 +1,10 @@ import { faker } from '@faker-js/faker'; -import type { AddGroup, Group } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddGroup, Group } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Groups', () => { - const groupId = faker.datatype.number(); + const groupId = faker.number.int(); const group: Group = jsonFor('Group'); const groups: Group[] = [group]; const addOrUpdateGroupPayload: AddGroup = jsonFor('AddGroup'); diff --git a/test/milestones.ts b/test/milestones.ts index 88ade68..f38f7ac 100644 --- a/test/milestones.ts +++ b/test/milestones.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddMilestone, Milestone, MilestoneFilters, UpdateMilestone } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddMilestone, Milestone, MilestoneFilters, UpdateMilestone } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Milestones', () => { - const milestoneId = faker.datatype.number(); - const projectId = faker.datatype.number(); + const milestoneId = faker.number.int(); + const projectId = faker.number.int(); const milestone: Milestone = jsonFor('Milestone'); const milestones = [milestone]; const milestoneFilters: MilestoneFilters = jsonFor('MilestoneFilters'); diff --git a/test/pagination.ts b/test/pagination.ts index 0d57d79..4553dc0 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -1,9 +1,10 @@ import { faker } from '@faker-js/faker'; -import type { Case } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { Case } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Pagination', () => { - const projectId = faker.datatype.number(); + const projectId = faker.number.int(); const testCase: Case = jsonFor('Case'); const testCases = Array(1000) .fill(null) @@ -11,7 +12,7 @@ describe('Pagination', () => { describe('Common', async () => { it('no paginate: "limit" passed', async () => { - const limit = faker.datatype.number(); + const limit = faker.number.int(); on(`get_cases/${projectId}&limit=${limit}`) .reply(OK); @@ -20,7 +21,7 @@ describe('Pagination', () => { }); it('no paginate: "offset" passed', async () => { - const offset = faker.datatype.number(); + const offset = faker.number.int(); on(`get_cases/${projectId}&offset=${offset}`) .reply(OK); diff --git a/test/plans.ts b/test/plans.ts index 308c03a..b839f02 100644 --- a/test/plans.ts +++ b/test/plans.ts @@ -1,12 +1,13 @@ import { faker } from '@faker-js/faker'; -import type { AddPlan, AddPlanEntry, AddRunToPlanEntry, Plan, PlanEntry, PlanFilters, PlanItem, UpdatePlan, UpdatePlanEntry, UpdateRunInPlanEntry } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddPlan, AddPlanEntry, AddRunToPlanEntry, Plan, PlanEntry, PlanFilters, PlanItem, UpdatePlan, UpdatePlanEntry, UpdateRunInPlanEntry } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Plans', () => { - const planId = faker.datatype.number(); - const projectId = faker.datatype.number(); - const entryId = faker.datatype.uuid(); - const runId = faker.datatype.number(); + const planId = faker.number.int(); + const projectId = faker.number.int(); + const entryId = faker.string.uuid(); + const runId = faker.number.int(); const plan: Plan = jsonFor('Plan'); const planItem: PlanItem = jsonFor('PlanItem'); const plans = [planItem]; diff --git a/test/priorities.ts b/test/priorities.ts index 8026361..c9c3aff 100644 --- a/test/priorities.ts +++ b/test/priorities.ts @@ -1,5 +1,6 @@ -import type { Priority } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { Priority } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Priorities', () => { const priority: Priority = jsonFor('Priority'); diff --git a/test/projects.ts b/test/projects.ts index b05e2ae..89d345d 100644 --- a/test/projects.ts +++ b/test/projects.ts @@ -1,9 +1,10 @@ import { faker } from '@faker-js/faker'; -import type { AddProject, Project, ProjectFilters, UpdateProject } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddProject, Project, ProjectFilters, UpdateProject } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Projects', () => { - const projectId = faker.datatype.number(); + const projectId = faker.number.int(); const project: Project = jsonFor('Project'); const projects = [project]; const projectFilters: ProjectFilters = jsonFor('ProjectFilters'); diff --git a/test/reports.ts b/test/reports.ts index 68dadfc..842ac00 100644 --- a/test/reports.ts +++ b/test/reports.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { Report, ReportUrls } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { Report, ReportUrls } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Reports', () => { - const projectId = faker.datatype.number(); - const reportTemplateId = faker.datatype.number(); + const projectId = faker.number.int(); + const reportTemplateId = faker.number.int(); const report: Report = jsonFor('Report'); const reports = [report]; const reportUrls: ReportUrls = jsonFor('ReportUrls'); diff --git a/test/resultFields.ts b/test/resultFields.ts index cdd1731..902b331 100644 --- a/test/resultFields.ts +++ b/test/resultFields.ts @@ -1,5 +1,6 @@ -import type { ResultField } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { ResultField } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Result Fields', () => { const field: ResultField = jsonFor('ResultField'); diff --git a/test/results.ts b/test/results.ts index ebe7e73..e34c8aa 100644 --- a/test/results.ts +++ b/test/results.ts @@ -1,11 +1,12 @@ import { faker } from '@faker-js/faker'; -import type { AddResult, AddResults, AddResultsForCases, Result, ResultFilters, ResultForRunFilters } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddResult, AddResults, AddResultsForCases, Result, ResultFilters, ResultForRunFilters } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Results', () => { - const testId = faker.datatype.number(); - const runId = faker.datatype.number(); - const caseId = faker.datatype.number(); + const testId = faker.number.int(); + const runId = faker.number.int(); + const caseId = faker.number.int(); const result: Result = jsonFor('Result'); const results = [result]; const resultFilters: ResultFilters = jsonFor('ResultFilters'); diff --git a/test/roles.ts b/test/roles.ts index d727d42..5185ea0 100644 --- a/test/roles.ts +++ b/test/roles.ts @@ -1,5 +1,6 @@ -import type { Role } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { Role } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Roles', () => { const role: Role = jsonFor('Role'); diff --git a/test/runs.ts b/test/runs.ts index f3faa23..d99c10e 100644 --- a/test/runs.ts +++ b/test/runs.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddRun, Run, RunFilters, UpdateRun } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddRun, Run, RunFilters, UpdateRun } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Runs', () => { - const runId = faker.datatype.number(); - const projectId = faker.datatype.number(); + const runId = faker.number.int(); + const projectId = faker.number.int(); const run: Run = jsonFor('Run'); const runs = [run]; const runFilters: RunFilters = jsonFor('RunFilters'); diff --git a/test/sections.ts b/test/sections.ts index 22b84e6..235fc00 100644 --- a/test/sections.ts +++ b/test/sections.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddSection, Section, SectionFilters, UpdateSection } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddSection, Section, SectionFilters, UpdateSection } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Sections', () => { - const sectionId = faker.datatype.number(); - const projectId = faker.datatype.number(); + const sectionId = faker.number.int(); + const projectId = faker.number.int(); const section: Section = jsonFor('Section'); const sections = [section]; const sectionFilters: SectionFilters = jsonFor('SectionFilters'); diff --git a/test/sharedStep.ts b/test/sharedStep.ts index e30d5dd..8399bef 100644 --- a/test/sharedStep.ts +++ b/test/sharedStep.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddSharedStep, SharedStep, SharedStepHistory, UpdateSharedStep } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddSharedStep, SharedStep, SharedStepHistory, UpdateSharedStep } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Shared Steps', () => { - const sharedStepId = faker.datatype.number(); - const projectId = faker.datatype.number(); + const sharedStepId = faker.number.int(); + const projectId = faker.number.int(); const sharedStep: SharedStep = jsonFor('SharedStep'); const sharedStepHistory: SharedStepHistory = jsonFor('CaseHistory'); const sharedStepHistories = [sharedStepHistory]; diff --git a/test/statuses.ts b/test/statuses.ts index 0c097ba..f33849a 100644 --- a/test/statuses.ts +++ b/test/statuses.ts @@ -1,5 +1,6 @@ -import type { CaseStatus, Status } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { CaseStatus, Status } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Statuses', () => { const status: Status = jsonFor('Status'); diff --git a/test/suites.ts b/test/suites.ts index 7d05362..029354f 100644 --- a/test/suites.ts +++ b/test/suites.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddSuite, Suite, UpdateSuite } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddSuite, Suite, UpdateSuite } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Suites', () => { - const suiteId = faker.datatype.number(); - const projectId = faker.datatype.number(); + const suiteId = faker.number.int(); + const projectId = faker.number.int(); const suite: Suite = jsonFor('Suite'); const suites = [suite]; const addSuitePayload: AddSuite = jsonFor('AddSuite'); diff --git a/test/templates.ts b/test/templates.ts index 7f5dbdd..c5ef76e 100644 --- a/test/templates.ts +++ b/test/templates.ts @@ -1,9 +1,10 @@ import { faker } from '@faker-js/faker'; -import type { Template } from '..'; -import { api, jsonFor, OK, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { Template } from '../src/TestRail.ts'; +import { api, jsonFor, OK, on } from './_helper.ts'; describe('Templates', () => { - const templateId = faker.datatype.number(); + const templateId = faker.number.int(); const template: Template = jsonFor('Template'); const templates = [template]; diff --git a/test/tests.ts b/test/tests.ts index 7f1f0f8..c3661e6 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { Test, TestFilters } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { Test, TestFilters } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Tests', () => { - const testId = faker.datatype.number(); - const runId = faker.datatype.number(); + const testId = faker.number.int(); + const runId = faker.number.int(); const test: Test = jsonFor('Test'); const tests: Test[] = [test]; const testsFilters: TestFilters = jsonFor('TestFilters'); diff --git a/test/users.ts b/test/users.ts index 83b4897..b8c37fc 100644 --- a/test/users.ts +++ b/test/users.ts @@ -1,9 +1,10 @@ import { faker } from '@faker-js/faker'; -import type { AddUser, User, UserFilters } from '..'; -import { OK, api, jsonFor, on, qs } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddUser, User, UserFilters } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on, qs } from './_helper.ts'; describe('Users', () => { - const userId = faker.datatype.number(); + const userId = faker.number.int(); const email = faker.internet.email(); const user: User = jsonFor('User'); const users: User[] = [user]; diff --git a/test/variables.ts b/test/variables.ts index 7f39896..9574612 100644 --- a/test/variables.ts +++ b/test/variables.ts @@ -1,10 +1,11 @@ import { faker } from '@faker-js/faker'; -import type { AddVariable, Variable } from '..'; -import { OK, api, jsonFor, on } from './_helper'; +import { describe, it } from 'node:test'; +import type { AddVariable, Variable } from '../src/TestRail.ts'; +import { OK, api, jsonFor, on } from './_helper.ts'; describe('Variables', () => { - const projectId = faker.datatype.number(); - const variableId = faker.datatype.number(); + const projectId = faker.number.int(); + const variableId = faker.number.int(); const variable: Variable = jsonFor('Variable'); const variables: Variable[] = [variable]; const addOrUpdateVariablePayload: AddVariable = jsonFor('AddVariable'); diff --git a/tsconfig.json b/tsconfig.json index 97d3987..54c2165 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,9 @@ { + "extends": "@tsconfig/strictest", "compilerOptions": { - "outDir": "./dist", - "target": "ES2018", - "lib": [ - "ES2018" - ], - "sourceMap": true, - "removeComments": true, - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "forceConsistentCasingInFileNames": true, - "esModuleInterop": true, - "moduleResolution": "Node" + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, } }