From de5d2726e060ef52f7aaa7a7f6304084b2d2cc7e Mon Sep 17 00:00:00 2001 From: Petr Hracek Date: Tue, 9 Apr 2024 11:19:00 +0200 Subject: [PATCH] Add `unsafeNewRequest(unknown): unknown` * Add `unsafeNewRequest(unknown)` to allow for unsafe requests for TF * The request object is passed directly to TF. No parsing is performed Signed-off-by: Petr "Stone" Hracek Co-authored-by: Jan Macku --- README.md | 1 + src/index.ts | 4 ++++ test/integration/new-request.test.ts | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index f00f6c4..47a3ccb 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ const request = { /* https://api.dev.testing-farm.io/redoc#operation/request_a_n const response: NewRequestResponse = await api.newRequest(request); const response: unknown = await api.newRequest(request, false); +const response: unknown = await api.unsafeNewRequest(request /* unknown type */); ``` ### Test Request Details diff --git a/src/index.ts b/src/index.ts index 5531b97..c9eb4b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,6 +78,10 @@ export default class TestingFarmAPI { ); } + async unsafeNewRequest(request: unknown): Promise { + return await this.link.post('requests', request); + } + async requestDetails(requestId: string): Promise; async requestDetails(requestId: string, strict: boolean): Promise; async requestDetails(requestId: string, strict?: boolean): Promise { diff --git a/test/integration/new-request.test.ts b/test/integration/new-request.test.ts index 570e933..44f91da 100644 --- a/test/integration/new-request.test.ts +++ b/test/integration/new-request.test.ts @@ -22,4 +22,21 @@ describe('Test Testing Farm POST /requests', () => { `[Error: {"message":"Test section is empty or test type is wrong."}]` ); }); + test('unsafe request', async () => { + const api = new TestingFarmAPI('https://api.dev.testing-farm.io/v0.1'); + + const response = api.unsafeNewRequest({ + api_key: 'api_key', + test: {}, + environments: [ + { + hardware: '{"something":"foobar"}', + }, + ], + }); + + await expect(response).rejects.toThrowErrorMatchingInlineSnapshot( + `[Error: {"message":"Test section is empty or test type is wrong."}]` + ); + }); });