-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
swagger: "2.0" | ||
info: | ||
version: 1.0.0 | ||
title: WithDefaults Test API | ||
description: An Openapi for testing client default parameters | ||
host: localhost | ||
basePath: /api/v1 | ||
schemes: | ||
- https | ||
|
||
securityDefinitions: | ||
bearerToken: | ||
type: apiKey | ||
name: Authorization | ||
in: header | ||
x-auth-scheme: bearer | ||
|
||
security: | ||
- Bearer: [] | ||
|
||
paths: | ||
/test-1: | ||
get: | ||
operationId: "test1" | ||
security: | ||
- bearerToken: [] | ||
parameters: | ||
- name: "qo" | ||
in: "query" | ||
required: true | ||
type: "string" | ||
|
||
responses: | ||
"200": | ||
description: "Will send `Authenticated`" | ||
"403": | ||
description: "You do not have necessary permissions for the resource" | ||
|
||
/test-2: | ||
post: | ||
operationId: "test2" | ||
security: | ||
- bearerToken: [] | ||
parameters: | ||
- name: "body" | ||
in: body | ||
required: true | ||
schema: | ||
$ref: "#/definitions/NewModel" | ||
|
||
responses: | ||
"200": | ||
description: "Will send `Authenticated`" | ||
"403": | ||
description: "You do not have necessary permissions for the resource" | ||
|
||
definitions: | ||
NewModel: | ||
title: NewModel | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
name: | ||
type: string | ||
required: | ||
- id | ||
- name | ||
responses: | ||
|
||
parameters: | ||
|
||
consumes: | ||
- application/json | ||
produces: | ||
- application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import nodeFetch from "node-fetch"; | ||
|
||
import * as E from "fp-ts/Either"; | ||
|
||
import config from "../../config"; | ||
import { createClient } from "../../generated/testapiWithDefaults/client"; | ||
|
||
// @ts-ignore because leaked-handles doesn't ship type defintions | ||
import * as leaked from "leaked-handles"; | ||
leaked.set({ debugSockets: true }); | ||
|
||
// Use same config as | ||
const { skipClient } = config; | ||
const { isSpecEnabled, mockPort } = config.specs.testapiWithDefaults; | ||
|
||
// if there's no need for this suite in this particular run, just skip it | ||
const describeSuite = skipClient || !isSpecEnabled ? describe.skip : describe; | ||
|
||
describeSuite("Http client generated from Test API spec", () => { | ||
it("should be a valid module", async () => { | ||
expect(createClient).toBeDefined(); | ||
expect(createClient).toEqual(expect.any(Function)); | ||
}); | ||
|
||
it("should make a call, with default parameters", async () => { | ||
const client = createClient<"bearerToken">({ | ||
baseUrl: `http://localhost:${mockPort}`, | ||
fetchApi: (nodeFetch as any) as typeof fetch, | ||
basePath: "", | ||
// cast op to any to make it compile | ||
withDefaults: op => params => op({ ...params, bearerToken: "abc123" }) | ||
}); | ||
|
||
expect(client.test1).toEqual(expect.any(Function)); | ||
|
||
const result = await client.test1({ | ||
qo: "acb123" | ||
}); | ||
expect(result).toMatchObject(E.right({ status: 200 })); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters