Skip to content

Commit

Permalink
Add unsafeNewRequest(unknown): unknown
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Jan Macku <[email protected]>
  • Loading branch information
phracek and jamacku committed Apr 9, 2024
1 parent 8b522d6 commit de5d272
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class TestingFarmAPI {
);
}

async unsafeNewRequest(request: unknown): Promise<unknown> {
return await this.link.post('requests', request);
}

async requestDetails(requestId: string): Promise<Request>;
async requestDetails(requestId: string, strict: boolean): Promise<unknown>;
async requestDetails(requestId: string, strict?: boolean): Promise<unknown> {
Expand Down
17 changes: 17 additions & 0 deletions test/integration/new-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."}]`
);
});
});

0 comments on commit de5d272

Please sign in to comment.