@schmock/openapi 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crud-detector.d.ts +35 -0
- package/dist/crud-detector.d.ts.map +1 -0
- package/dist/crud-detector.js +153 -0
- package/dist/generators.d.ts +14 -0
- package/dist/generators.d.ts.map +1 -0
- package/dist/generators.js +158 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +221 -0
- package/dist/normalizer.d.ts +14 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +194 -0
- package/dist/parser.d.ts +32 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +282 -0
- package/dist/plugin.d.ts +32 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +129 -0
- package/dist/seed.d.ts +15 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +41 -0
- package/package.json +45 -0
- package/src/__fixtures__/faker-stress-test.openapi.yaml +1030 -0
- package/src/__fixtures__/openapi31.json +34 -0
- package/src/__fixtures__/petstore-openapi3.json +168 -0
- package/src/__fixtures__/petstore-swagger2.json +141 -0
- package/src/__fixtures__/scalar-galaxy.yaml +1314 -0
- package/src/__fixtures__/stripe-fixtures3.json +6542 -0
- package/src/__fixtures__/stripe-spec3.yaml +161621 -0
- package/src/__fixtures__/train-travel.yaml +1264 -0
- package/src/crud-detector.test.ts +150 -0
- package/src/crud-detector.ts +194 -0
- package/src/generators.test.ts +214 -0
- package/src/generators.ts +212 -0
- package/src/index.ts +4 -0
- package/src/normalizer.test.ts +253 -0
- package/src/normalizer.ts +233 -0
- package/src/parser.test.ts +181 -0
- package/src/parser.ts +389 -0
- package/src/plugin.test.ts +205 -0
- package/src/plugin.ts +185 -0
- package/src/seed.ts +62 -0
- package/src/steps/openapi-crud.steps.ts +132 -0
- package/src/steps/openapi-parsing.steps.ts +111 -0
- package/src/steps/openapi-seed.steps.ts +94 -0
- package/src/stress.test.ts +2814 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { describeFeature, loadFeature } from "@amiceli/vitest-cucumber";
|
|
3
|
+
import { schmock } from "@schmock/core";
|
|
4
|
+
import { expect } from "vitest";
|
|
5
|
+
import { openapi } from "../plugin";
|
|
6
|
+
|
|
7
|
+
const feature = await loadFeature("../../features/openapi-seed.feature");
|
|
8
|
+
const fixturesDir = resolve(import.meta.dirname, "../__fixtures__");
|
|
9
|
+
|
|
10
|
+
describeFeature(feature, ({ Scenario }) => {
|
|
11
|
+
let mock: Schmock.CallableMockInstance;
|
|
12
|
+
let response: Schmock.Response;
|
|
13
|
+
|
|
14
|
+
Scenario("Seed with inline objects", ({ Given, When, Then }) => {
|
|
15
|
+
Given("a mock with Petstore spec and inline seed data", async () => {
|
|
16
|
+
mock = schmock({ state: {} });
|
|
17
|
+
mock.pipe(
|
|
18
|
+
await openapi({
|
|
19
|
+
spec: `${fixturesDir}/petstore-swagger2.json`,
|
|
20
|
+
seed: {
|
|
21
|
+
pets: [
|
|
22
|
+
{ petId: 1, name: "Buddy" },
|
|
23
|
+
{ petId: 2, name: "Max" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
When("I list all pets", async () => {
|
|
31
|
+
response = await mock.handle("GET", "/pets");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
Then("the list contains {int} items", (_, count: number) => {
|
|
35
|
+
expect(response.body).toHaveLength(count);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
Scenario("Seed with auto-generated data", ({ Given, When, Then }) => {
|
|
40
|
+
Given(
|
|
41
|
+
"a mock with Petstore spec and auto-generated seed of 5 pets",
|
|
42
|
+
async () => {
|
|
43
|
+
mock = schmock({ state: {} });
|
|
44
|
+
mock.pipe(
|
|
45
|
+
await openapi({
|
|
46
|
+
spec: `${fixturesDir}/petstore-swagger2.json`,
|
|
47
|
+
seed: {
|
|
48
|
+
pets: { count: 5 },
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
When("I list all seeded pets", async () => {
|
|
56
|
+
response = await mock.handle("GET", "/pets");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
Then("the seeded list contains {int} items", (_, count: number) => {
|
|
60
|
+
expect(response.body).toHaveLength(count);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
Scenario(
|
|
65
|
+
"Auto-increment IDs continue after seed",
|
|
66
|
+
({ Given, When, Then }) => {
|
|
67
|
+
Given("a mock with Petstore spec and inline seed data", async () => {
|
|
68
|
+
mock = schmock({ state: {} });
|
|
69
|
+
mock.pipe(
|
|
70
|
+
await openapi({
|
|
71
|
+
spec: `${fixturesDir}/petstore-swagger2.json`,
|
|
72
|
+
seed: {
|
|
73
|
+
pets: [
|
|
74
|
+
{ petId: 1, name: "Buddy" },
|
|
75
|
+
{ petId: 2, name: "Max" },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
When("I create a new pet named {string}", async (_, name: string) => {
|
|
83
|
+
response = await mock.handle("POST", "/pets", {
|
|
84
|
+
body: { name },
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
Then("the new pet ID is greater than existing seed IDs", () => {
|
|
89
|
+
const body = response.body as Record<string, unknown>;
|
|
90
|
+
expect(body.petId).toBeGreaterThan(2);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
});
|