-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(int): split type and behavior tests
- Loading branch information
1 parent
8271f60
commit 85e5c99
Showing
10 changed files
with
107 additions
and
79 deletions.
There are no files selected for viewing
File renamed without changes.
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,25 @@ | ||
import { type StrictResponse } from "msw"; | ||
import { createOpenApiHttp } from "openapi-msw"; | ||
import { describe, expectTypeOf, test } from "vitest"; | ||
import type { paths } from "./fixtures/no-content.api.js"; | ||
|
||
describe("Given an OpenAPI schema endpoint with no-content", () => { | ||
const http = createOpenApiHttp<paths>({ baseUrl: "*" }); | ||
|
||
test("When an endpoint is mocked, Then responses with content cannot be returned", async () => { | ||
type Endpoint = typeof http.delete<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const response = resolver.returns.extract<Response>(); | ||
|
||
response.not.toEqualTypeOf<StrictResponse<{ id: number }>>(); | ||
}); | ||
|
||
test("When an endpoint is mocked, Then responses must be strict responses", async () => { | ||
type Endpoint = typeof http.delete<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const response = resolver.returns.extract<Response>(); | ||
|
||
response.not.toEqualTypeOf<Response>(); | ||
response.toEqualTypeOf<StrictResponse<null>>(); | ||
}); | ||
}); |
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
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,23 @@ | ||
import { createOpenApiHttp } from "openapi-msw"; | ||
import { describe, expectTypeOf, test } from "vitest"; | ||
import type { paths } from "./fixtures/path-fragments.api.js"; | ||
|
||
describe("Given an OpenAPI schema endpoint that contains path fragments", () => { | ||
const http = createOpenApiHttp<paths>({ baseUrl: "*" }); | ||
|
||
test("When an endpoint is mocked, Then the path fragments are strict-typed", () => { | ||
type Endpoint = typeof http.get<"/resource/{id}/{name}">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const params = resolver.parameter(0).toHaveProperty("params"); | ||
|
||
params.toEqualTypeOf<{ id: string; name: string }>(); | ||
}); | ||
|
||
test("When a endpoint contains no path fragments, Then no params are provided", () => { | ||
type Endpoint = typeof http.get<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const params = resolver.parameter(0).toHaveProperty("params"); | ||
|
||
params.toEqualTypeOf<never>(); | ||
}); | ||
}); |
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
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,34 @@ | ||
import { type StrictRequest } from "msw"; | ||
import { createOpenApiHttp } from "openapi-msw"; | ||
import { describe, expectTypeOf, test } from "vitest"; | ||
import type { paths } from "./fixtures/request-body.api.js"; | ||
|
||
describe("Given an OpenAPI schema endpoint with request content", () => { | ||
const http = createOpenApiHttp<paths>({ baseUrl: "*" }); | ||
|
||
test("When a request is expected to contain content, Then the content is strict-typed", () => { | ||
type Endpoint = typeof http.post<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const request = resolver.parameter(0).toHaveProperty("request"); | ||
|
||
request.toEqualTypeOf<StrictRequest<{ name: string; value: number }>>(); | ||
}); | ||
|
||
test("When a request content is optional, Then the content is strict-typed with optional", () => { | ||
type Endpoint = typeof http.patch<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const request = resolver.parameter(0).toHaveProperty("request"); | ||
|
||
request.toEqualTypeOf< | ||
StrictRequest<{ name: string; value: number } | undefined> | ||
>(); | ||
}); | ||
|
||
test("When a request is not expected to contain content, Then the content is undefined", () => { | ||
type Endpoint = typeof http.get<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const request = resolver.parameter(0).toHaveProperty("request"); | ||
|
||
request.toEqualTypeOf<StrictRequest<undefined>>(); | ||
}); | ||
}); |
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
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,19 @@ | ||
import { type StrictResponse } from "msw"; | ||
import { createOpenApiHttp } from "openapi-msw"; | ||
import { describe, expectTypeOf, test } from "vitest"; | ||
import type { paths } from "./fixtures/response-content.api.js"; | ||
|
||
describe("Given an OpenAPI schema endpoint with response content", () => { | ||
const http = createOpenApiHttp<paths>({ baseUrl: "*" }); | ||
|
||
test("When a JSON endpoint is mocked, Then responses must be a strict content response", async () => { | ||
type Endpoint = typeof http.get<"/resource">; | ||
const resolver = expectTypeOf<Endpoint>().parameter(1); | ||
const response = resolver.returns.extract<Response>(); | ||
|
||
response.not.toEqualTypeOf<Response>(); | ||
response.toEqualTypeOf< | ||
StrictResponse<{ id: string; name: string; value: number }> | ||
>(); | ||
}); | ||
}); |
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
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