@skyramp/testbot-core 0.12.0-v3.46 → 0.12.0-v3.50
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/LICENSE.md +1 -0
- package/README.md +20 -0
- package/assets/gen-reference/INDEX.md +24 -0
- package/assets/gen-reference/java/ContractTest.java +113 -0
- package/assets/gen-reference/javascript/contract_test.spec.js +95 -0
- package/assets/gen-reference/javascript/integration_test.spec.js +72 -0
- package/assets/gen-reference/python/contract_test.py +104 -0
- package/assets/gen-reference/python/integration_test.py +72 -0
- package/assets/gen-reference/typescript/contract_test.spec.ts +94 -0
- package/assets/gen-reference/typescript/integration_test.spec.ts +71 -0
- package/dist/VERSION.json +1 -0
- package/dist/main.js +367 -367
- package/dist/post.js +216 -216
- package/package.json +18 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
© Skyramp Inc. All rights reserved. Use is subject to the Skyramp Terms of Service: https://docs.skyramp.dev/terms-of-service
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Testbot
|
|
2
|
+
|
|
3
|
+
The engine of [Skyramp Testbot](https://testbot.skyramp.dev), a GitHub App for
|
|
4
|
+
autonomous validation for your software applications.
|
|
5
|
+
|
|
6
|
+
You do not install this package yourself. The Skyramp Testbot action
|
|
7
|
+
(`skyramp/testbot@v1`) downloads it from npm at the start of each run, checks
|
|
8
|
+
its integrity against the registry, and runs it.
|
|
9
|
+
|
|
10
|
+
## Compatibility
|
|
11
|
+
|
|
12
|
+
- This engine needs `skyramp/testbot` v1.0.0 or later.
|
|
13
|
+
- The action runs only an engine that declares `skyramp.launcherContract` in
|
|
14
|
+
its `package.json`. Versions published before 0.12.0 do not declare it, so
|
|
15
|
+
the action does not run them.
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
The inputs, examples and setup steps are in the
|
|
20
|
+
[Skyramp Testbot README](https://github.com/skyramp/testbot#readme).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Skyramp codegen reference corpus (backend)
|
|
2
|
+
|
|
3
|
+
Canonical examples of Skyramp-generated backend tests, one contract + one
|
|
4
|
+
integration per language. Read the file matching your target language to learn
|
|
5
|
+
the idiom, then write tests in the same shape. These are references, not
|
|
6
|
+
templates — adapt data and assertions to the case at hand.
|
|
7
|
+
|
|
8
|
+
| language | contract | integration |
|
|
9
|
+
|------------|--------------------------------|-----------------------------------|
|
|
10
|
+
| python | python/contract_test.py | python/integration_test.py |
|
|
11
|
+
| typescript | typescript/contract_test.spec.ts | typescript/integration_test.spec.ts |
|
|
12
|
+
| javascript | javascript/contract_test.spec.js | javascript/integration_test.spec.js |
|
|
13
|
+
| java | java/ContractTest.java | (same send_request idiom as contract) |
|
|
14
|
+
|
|
15
|
+
Idioms every example shows:
|
|
16
|
+
- Base URL from `get_base_url("SKYRAMP_TEST_BASE_URL", <fallback>)` (py) /
|
|
17
|
+
`getBaseUrl(...)` (ts/js) — never a hard-coded host.
|
|
18
|
+
- Auth from `SKYRAMP_TEST_TOKEN` as a Bearer header.
|
|
19
|
+
- Requests via the Skyramp client `send_request` / `sendRequest`, NOT the raw
|
|
20
|
+
HTTP library.
|
|
21
|
+
- Response correlation across a flow via `get_response_value` /
|
|
22
|
+
`getResponseValue` + `data_override` / `dataOverride` (see integration).
|
|
23
|
+
- Contract tests assert status AND schema (`check_schema`) AND field presence,
|
|
24
|
+
and clean up created resources (the DELETE fixture).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Generated by Skyramp v1.2.0+34673f84 on 2026-07-07 23:25:02.652287 -0700 PDT m=+0.380477042
|
|
2
|
+
// Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
|
|
3
|
+
// --api-schema examples/v2/gen_reference/openapi.json \
|
|
4
|
+
// --framework junit \
|
|
5
|
+
// --language java \
|
|
6
|
+
// --method POST \
|
|
7
|
+
// --optional-fields \
|
|
8
|
+
// --output-dir examples/v2/gen_reference/java/junit \
|
|
9
|
+
// --overwrite
|
|
10
|
+
|
|
11
|
+
import java.util.*;
|
|
12
|
+
|
|
13
|
+
import static org.junit.jupiter.api.Assertions.*;
|
|
14
|
+
import org.junit.jupiter.api.Test;
|
|
15
|
+
import org.junit.jupiter.api.AfterAll;
|
|
16
|
+
import org.junit.jupiter.api.TestInstance;
|
|
17
|
+
|
|
18
|
+
import static dev.skyramp.api.Skyramp.*;
|
|
19
|
+
import dev.skyramp.api.SkyrampClient;
|
|
20
|
+
import dev.skyramp.exception.SkyrampException;
|
|
21
|
+
import dev.skyramp.model.*;
|
|
22
|
+
|
|
23
|
+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
24
|
+
public final class ProductsPostProviderContractTest {
|
|
25
|
+
// URL for test requests
|
|
26
|
+
String URL = getBaseUrl("SKYRAMP_TEST_BASE_URL", "https://demoshop.skyramp.dev");
|
|
27
|
+
String product_id = "product_id";
|
|
28
|
+
|
|
29
|
+
public Map<String, String> getHeader() throws SkyrampException {
|
|
30
|
+
// Definition of authentication header
|
|
31
|
+
String token = System.getenv("SKYRAMP_TEST_TOKEN");
|
|
32
|
+
Map<String, String> headers = Map.of();
|
|
33
|
+
if (token != null && !token.isEmpty()) {
|
|
34
|
+
headers = Map.of("Authorization", "Bearer " + token);
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@AfterAll
|
|
40
|
+
public void afterAll() throws SkyrampException {
|
|
41
|
+
// Invocation of Skyramp Client
|
|
42
|
+
var client = new SkyrampClient();
|
|
43
|
+
// Definition of authentication header
|
|
44
|
+
var headers = getHeader();
|
|
45
|
+
|
|
46
|
+
// Execute Request
|
|
47
|
+
var productsProductIdDeleteResponse = client.sendRequest(RequestV2.builder()
|
|
48
|
+
.url(URL)
|
|
49
|
+
.path("/api/v1/products/{product_id}")
|
|
50
|
+
.method("DELETE")
|
|
51
|
+
.headers(headers)
|
|
52
|
+
.pathParams(asMap("product_id", product_id))
|
|
53
|
+
.build());
|
|
54
|
+
|
|
55
|
+
// Generated Assertions
|
|
56
|
+
assertTrue(checkStatusCode(productsProductIdDeleteResponse, "204"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// contract test for /api/v1/products POST
|
|
60
|
+
@Test
|
|
61
|
+
public void testProductsPost() throws SkyrampException {
|
|
62
|
+
// Invocation of Skyramp Client
|
|
63
|
+
var client = new SkyrampClient();
|
|
64
|
+
// Definition of authentication header
|
|
65
|
+
var headers = getHeader();
|
|
66
|
+
|
|
67
|
+
// Request Body
|
|
68
|
+
String productsPostRequestBody = """
|
|
69
|
+
{
|
|
70
|
+
"category": "Toys",
|
|
71
|
+
"description": "Bear Soft Toy",
|
|
72
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
73
|
+
"in_stock": true,
|
|
74
|
+
"name": "bigbear",
|
|
75
|
+
"price": 9.99
|
|
76
|
+
}
|
|
77
|
+
""";
|
|
78
|
+
|
|
79
|
+
// Expected Response Body
|
|
80
|
+
String expectedProductsPostResponseBody = """
|
|
81
|
+
{
|
|
82
|
+
"category": "Toys",
|
|
83
|
+
"created_at": "2025-02-25T10:54:22-05:00",
|
|
84
|
+
"description": "Bear Soft Toy",
|
|
85
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
86
|
+
"in_stock": true,
|
|
87
|
+
"name": "bigbear",
|
|
88
|
+
"price": 9.99,
|
|
89
|
+
"product_id": 1,
|
|
90
|
+
"updated_at": "2025-02-25T10:54:22-05:00"
|
|
91
|
+
}
|
|
92
|
+
""";
|
|
93
|
+
|
|
94
|
+
// Execute Request
|
|
95
|
+
var productsPostResponse = client.sendRequest(RequestV2.builder()
|
|
96
|
+
.url(URL)
|
|
97
|
+
.path("/api/v1/products")
|
|
98
|
+
.method("POST")
|
|
99
|
+
.body(productsPostRequestBody)
|
|
100
|
+
.headers(headers)
|
|
101
|
+
.build());
|
|
102
|
+
|
|
103
|
+
// Generated Assertions
|
|
104
|
+
assertTrue(checkStatusCode(productsPostResponse, "201"));
|
|
105
|
+
assertTrue(checkSchema(productsPostResponse, expectedProductsPostResponseBody));
|
|
106
|
+
assertNotNull(getValue(productsPostResponse, "category"));
|
|
107
|
+
assertNotNull(getValue(productsPostResponse, "created_at"));
|
|
108
|
+
assertNotNull(getValue(productsPostResponse, "description"));
|
|
109
|
+
|
|
110
|
+
// Update global path param values
|
|
111
|
+
product_id = String.valueOf(getValue(productsPostResponse, "product_id"));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Generated by Skyramp v1.2.0+34673f84 on 2026-07-07 23:25:01.85961 -0700 PDT m=+0.283146501
|
|
2
|
+
// Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
|
|
3
|
+
// --api-schema examples/v2/gen_reference/openapi.json \
|
|
4
|
+
// --framework playwright \
|
|
5
|
+
// --language javascript \
|
|
6
|
+
// --method POST \
|
|
7
|
+
// --optional-fields \
|
|
8
|
+
// --output-dir examples/v2/gen_reference/javascript/playwright \
|
|
9
|
+
// --overwrite
|
|
10
|
+
|
|
11
|
+
// Import of required libraries
|
|
12
|
+
const { test, SkyrampClient, checkSchema, getBaseUrl, getValue, getResponseValue } = require('@skyramp/skyramp');
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
|
|
15
|
+
// URL for test requests
|
|
16
|
+
const URL = getBaseUrl("SKYRAMP_TEST_BASE_URL", "https://demoshop.skyramp.dev");
|
|
17
|
+
let product_id = "product_id";
|
|
18
|
+
|
|
19
|
+
function getHeader() {
|
|
20
|
+
// Definition of authentication header
|
|
21
|
+
const headers = {};
|
|
22
|
+
if (process.env.SKYRAMP_TEST_TOKEN && process.env.SKYRAMP_TEST_TOKEN != "") {
|
|
23
|
+
headers["Authorization"] = "Bearer " + process.env.SKYRAMP_TEST_TOKEN;
|
|
24
|
+
}
|
|
25
|
+
return headers;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
test.afterAll(async () => {
|
|
29
|
+
// Invocation of Skyramp Client
|
|
30
|
+
const client = new SkyrampClient();
|
|
31
|
+
// Definition of authentication header
|
|
32
|
+
const headers = getHeader();
|
|
33
|
+
|
|
34
|
+
// Execute Request
|
|
35
|
+
const productsProductIdDeleteResponse = await client.sendRequest({
|
|
36
|
+
url: URL,
|
|
37
|
+
path: "/api/v1/products/{product_id}",
|
|
38
|
+
method: "DELETE",
|
|
39
|
+
headers: headers,
|
|
40
|
+
pathParams: {"product_id": product_id}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Generated Assertions
|
|
44
|
+
assert.strictEqual(productsProductIdDeleteResponse.statusCode, 204, 'status code');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// contract test for /api/v1/products POST
|
|
48
|
+
test('testProductsPost', async () => {
|
|
49
|
+
// Invocation of Skyramp Client
|
|
50
|
+
const client = new SkyrampClient();
|
|
51
|
+
// Definition of authentication header
|
|
52
|
+
const headers = getHeader();
|
|
53
|
+
|
|
54
|
+
// Request Body
|
|
55
|
+
const productsPostRequestBody = `{
|
|
56
|
+
"category": "Toys",
|
|
57
|
+
"description": "Bear Soft Toy",
|
|
58
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
59
|
+
"in_stock": true,
|
|
60
|
+
"name": "bigbear",
|
|
61
|
+
"price": 9.99
|
|
62
|
+
}`;
|
|
63
|
+
|
|
64
|
+
// Expected Response Body
|
|
65
|
+
const expectedProductsPostResponseBody = `{
|
|
66
|
+
"category": "Toys",
|
|
67
|
+
"created_at": "2025-02-25T10:54:22-05:00",
|
|
68
|
+
"description": "Bear Soft Toy",
|
|
69
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
70
|
+
"in_stock": true,
|
|
71
|
+
"name": "bigbear",
|
|
72
|
+
"price": 9.99,
|
|
73
|
+
"product_id": 1,
|
|
74
|
+
"updated_at": "2025-02-25T10:54:22-05:00"
|
|
75
|
+
}`;
|
|
76
|
+
|
|
77
|
+
// Execute Request
|
|
78
|
+
const productsPostResponse = await client.sendRequest({
|
|
79
|
+
url: URL,
|
|
80
|
+
path: "/api/v1/products",
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: productsPostRequestBody,
|
|
83
|
+
headers: headers
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Generated Assertions
|
|
87
|
+
assert.strictEqual(productsPostResponse.statusCode, 201, 'status code');
|
|
88
|
+
assert.ok(checkSchema(productsPostResponse, expectedProductsPostResponseBody), 'schema should match');
|
|
89
|
+
assert.notStrictEqual(getResponseValue(productsPostResponse, "category"), null, 'value should not be null');
|
|
90
|
+
assert.notStrictEqual(getResponseValue(productsPostResponse, "created_at"), null, 'value should not be null');
|
|
91
|
+
assert.notStrictEqual(getResponseValue(productsPostResponse, "description"), null, 'value should not be null');
|
|
92
|
+
|
|
93
|
+
// Update global path param values
|
|
94
|
+
product_id = getResponseValue(productsPostResponse, "product_id");
|
|
95
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Generated by Skyramp v1.2.0+2a92d199 on 2026-06-22 23:35:13.929106 -0700 PDT m=+0.359576251
|
|
2
|
+
// Command: skyramp generate integration rest \
|
|
3
|
+
// --framework playwright \
|
|
4
|
+
// --language javascript \
|
|
5
|
+
// --output /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/integration/demoshop1/integration_test.spec.js \
|
|
6
|
+
// --overwrite \
|
|
7
|
+
// --trace /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/datasets/demoshop1/skyramp-traces.json
|
|
8
|
+
|
|
9
|
+
// Import of required libraries
|
|
10
|
+
const { test, SkyrampClient, getBaseUrl, getValue, getResponseValue } = require('@skyramp/skyramp');
|
|
11
|
+
const assert = require('assert');
|
|
12
|
+
|
|
13
|
+
// URL for test requests
|
|
14
|
+
const URL_api = getBaseUrl("SKYRAMP_TEST_BASE_URL", "https://api.example.com");
|
|
15
|
+
|
|
16
|
+
test('testIntegration', async () => {
|
|
17
|
+
test.setTimeout(64000);
|
|
18
|
+
|
|
19
|
+
// Invocation of Skyramp Client
|
|
20
|
+
const client = new SkyrampClient();
|
|
21
|
+
// Definition of authentication header
|
|
22
|
+
const headers = {};
|
|
23
|
+
if (process.env.SKYRAMP_TEST_TOKEN && process.env.SKYRAMP_TEST_TOKEN != "") {
|
|
24
|
+
headers["Authorization"] = "Bearer " + process.env.SKYRAMP_TEST_TOKEN;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Request Body
|
|
28
|
+
const productsPostRequestBody = `{
|
|
29
|
+
"category": "Software Tools",
|
|
30
|
+
"description": "Professional API testing tool for developers and QA teams",
|
|
31
|
+
"image_url": "https://www.skyramp.dev/images/skyramp-tester.png",
|
|
32
|
+
"in_stock": true,
|
|
33
|
+
"name": "Skyramp Tester",
|
|
34
|
+
"price": 999
|
|
35
|
+
}`;
|
|
36
|
+
|
|
37
|
+
// Execute Request
|
|
38
|
+
const productsPostResponse = await client.sendRequest({
|
|
39
|
+
url: URL_api,
|
|
40
|
+
path: "/api/v1/products",
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: productsPostRequestBody,
|
|
43
|
+
headers: headers
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Generated Assertions
|
|
47
|
+
assert.strictEqual(productsPostResponse.statusCode, 201, 'status code');
|
|
48
|
+
|
|
49
|
+
// Request Body
|
|
50
|
+
const ordersPostRequestBody = `{
|
|
51
|
+
"customer_email": "test@skyramp.dev",
|
|
52
|
+
"items": [
|
|
53
|
+
{
|
|
54
|
+
"product_id": 1,
|
|
55
|
+
"quantity": 1
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}`;
|
|
59
|
+
|
|
60
|
+
// Execute Request
|
|
61
|
+
const ordersPostResponse = await client.sendRequest({
|
|
62
|
+
url: URL_api,
|
|
63
|
+
path: "/api/v1/orders",
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: ordersPostRequestBody,
|
|
66
|
+
headers: headers,
|
|
67
|
+
dataOverride: {"items.0.product_id": getResponseValue(productsPostResponse, "product_id")}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Generated Assertions
|
|
71
|
+
assert.strictEqual(ordersPostResponse.statusCode, 201, 'status code');
|
|
72
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Generated by Skyramp v1.2.0+34673f84 on 2026-07-07 23:24:59.486999 -0700 PDT m=+0.594249001
|
|
2
|
+
# Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
|
|
3
|
+
# --api-schema examples/v2/gen_reference/openapi.json \
|
|
4
|
+
# --framework pytest \
|
|
5
|
+
# --language python \
|
|
6
|
+
# --method POST \
|
|
7
|
+
# --optional-fields \
|
|
8
|
+
# --output-dir examples/v2/gen_reference/python/pytest \
|
|
9
|
+
# --overwrite
|
|
10
|
+
|
|
11
|
+
# Import of required libraries
|
|
12
|
+
import os
|
|
13
|
+
import pytest
|
|
14
|
+
import skyramp
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# URL for test requests
|
|
18
|
+
URL = skyramp.get_base_url("SKYRAMP_TEST_BASE_URL", "https://demoshop.skyramp.dev")
|
|
19
|
+
product_id = "product_id"
|
|
20
|
+
|
|
21
|
+
def get_header():
|
|
22
|
+
# Definition of authentication header
|
|
23
|
+
headers = {}
|
|
24
|
+
if os.getenv("SKYRAMP_TEST_TOKEN") is not None:
|
|
25
|
+
headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN")
|
|
26
|
+
return headers
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture(autouse=True)
|
|
30
|
+
def after_all():
|
|
31
|
+
yield
|
|
32
|
+
|
|
33
|
+
# Invocation of Skyramp Client
|
|
34
|
+
client = skyramp.Client()
|
|
35
|
+
# Definition of authentication header
|
|
36
|
+
headers = get_header()
|
|
37
|
+
|
|
38
|
+
# Execute Request
|
|
39
|
+
products_product_id_DELETE_response = client.send_request(
|
|
40
|
+
url=URL,
|
|
41
|
+
path="/api/v1/products/{product_id}",
|
|
42
|
+
method="DELETE",
|
|
43
|
+
headers=headers,
|
|
44
|
+
path_params={"product_id": product_id}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Generated Assertions
|
|
48
|
+
assert products_product_id_DELETE_response.status_code == 204
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# contract test for /api/v1/products POST
|
|
52
|
+
def test_products_post():
|
|
53
|
+
# Invocation of Skyramp Client
|
|
54
|
+
client = skyramp.Client()
|
|
55
|
+
# Definition of authentication header
|
|
56
|
+
headers = get_header()
|
|
57
|
+
|
|
58
|
+
# Request Body
|
|
59
|
+
products_POST_request_body = r'''{
|
|
60
|
+
"category": "Toys",
|
|
61
|
+
"description": "Bear Soft Toy",
|
|
62
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
63
|
+
"in_stock": true,
|
|
64
|
+
"name": "bigbear",
|
|
65
|
+
"price": 9.99
|
|
66
|
+
}'''
|
|
67
|
+
|
|
68
|
+
# Expected Response Body
|
|
69
|
+
expected_products_POST_response_body = r'''{
|
|
70
|
+
"category": "Toys",
|
|
71
|
+
"created_at": "2025-02-25T10:54:22-05:00",
|
|
72
|
+
"description": "Bear Soft Toy",
|
|
73
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
74
|
+
"in_stock": true,
|
|
75
|
+
"name": "bigbear",
|
|
76
|
+
"price": 9.99,
|
|
77
|
+
"product_id": 1,
|
|
78
|
+
"updated_at": "2025-02-25T10:54:22-05:00"
|
|
79
|
+
}'''
|
|
80
|
+
|
|
81
|
+
# Execute Request
|
|
82
|
+
products_POST_response = client.send_request(
|
|
83
|
+
url=URL,
|
|
84
|
+
path="/api/v1/products",
|
|
85
|
+
method="POST",
|
|
86
|
+
body=products_POST_request_body,
|
|
87
|
+
headers=headers
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Generated Assertions
|
|
91
|
+
assert products_POST_response.status_code == 201
|
|
92
|
+
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
|
|
93
|
+
assert skyramp.get_response_value(products_POST_response, "category") is not None
|
|
94
|
+
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
|
|
95
|
+
assert skyramp.get_response_value(products_POST_response, "description") is not None
|
|
96
|
+
|
|
97
|
+
# Update global path param values
|
|
98
|
+
global product_id
|
|
99
|
+
product_id = skyramp.get_response_value(products_POST_response, "product_id")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
test_products_post()
|
|
104
|
+
after_all()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Generated by Skyramp v1.2.0+2a92d199 on 2026-06-22 23:35:12.352163 -0700 PDT m=+0.310230667
|
|
2
|
+
# Command: skyramp generate integration rest \
|
|
3
|
+
# --output /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/integration/demoshop1/integration_test.py \
|
|
4
|
+
# --overwrite \
|
|
5
|
+
# --trace /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/datasets/demoshop1/skyramp-traces.json
|
|
6
|
+
|
|
7
|
+
# Import of required libraries
|
|
8
|
+
import skyramp
|
|
9
|
+
import os
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# URL for test requests
|
|
14
|
+
URL_api = skyramp.get_base_url("SKYRAMP_TEST_BASE_URL", "https://api.example.com")
|
|
15
|
+
|
|
16
|
+
def test_integration():
|
|
17
|
+
# Invocation of Skyramp Client
|
|
18
|
+
client = skyramp.Client()
|
|
19
|
+
# Definition of authentication header
|
|
20
|
+
headers = {}
|
|
21
|
+
if os.getenv("SKYRAMP_TEST_TOKEN") is not None:
|
|
22
|
+
headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN")
|
|
23
|
+
|
|
24
|
+
# Request Body
|
|
25
|
+
products_POST_request_body = r'''{
|
|
26
|
+
"category": "Software Tools",
|
|
27
|
+
"description": "Professional API testing tool for developers and QA teams",
|
|
28
|
+
"image_url": "https://www.skyramp.dev/images/skyramp-tester.png",
|
|
29
|
+
"in_stock": true,
|
|
30
|
+
"name": "Skyramp Tester",
|
|
31
|
+
"price": 999
|
|
32
|
+
}'''
|
|
33
|
+
|
|
34
|
+
# Execute Request
|
|
35
|
+
products_POST_response = client.send_request(
|
|
36
|
+
url=URL_api,
|
|
37
|
+
path="/api/v1/products",
|
|
38
|
+
method="POST",
|
|
39
|
+
body=products_POST_request_body,
|
|
40
|
+
headers=headers
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Generated Assertions
|
|
44
|
+
assert products_POST_response.status_code == 201
|
|
45
|
+
|
|
46
|
+
# Request Body
|
|
47
|
+
orders_POST_request_body = r'''{
|
|
48
|
+
"customer_email": "test@skyramp.dev",
|
|
49
|
+
"items": [
|
|
50
|
+
{
|
|
51
|
+
"product_id": 1,
|
|
52
|
+
"quantity": 1
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}'''
|
|
56
|
+
|
|
57
|
+
# Execute Request
|
|
58
|
+
orders_POST_response = client.send_request(
|
|
59
|
+
url=URL_api,
|
|
60
|
+
path="/api/v1/orders",
|
|
61
|
+
method="POST",
|
|
62
|
+
body=orders_POST_request_body,
|
|
63
|
+
headers=headers,
|
|
64
|
+
data_override={"items.0.product_id": skyramp.get_response_value(products_POST_response, "product_id")}
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Generated Assertions
|
|
68
|
+
assert orders_POST_response.status_code == 201
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
test_integration()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Generated by Skyramp v1.2.0+34673f84 on 2026-07-07 23:25:01.094237 -0700 PDT m=+0.320419542
|
|
2
|
+
// Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
|
|
3
|
+
// --api-schema examples/v2/gen_reference/openapi.json \
|
|
4
|
+
// --framework playwright \
|
|
5
|
+
// --language typescript \
|
|
6
|
+
// --method POST \
|
|
7
|
+
// --optional-fields \
|
|
8
|
+
// --output-dir examples/v2/gen_reference/typescript/playwright \
|
|
9
|
+
// --overwrite
|
|
10
|
+
|
|
11
|
+
// Import of required libraries
|
|
12
|
+
import { test, expect, SkyrampClient, checkSchema, getBaseUrl, getValue, getResponseValue } from '@skyramp/skyramp';
|
|
13
|
+
|
|
14
|
+
// URL for test requests
|
|
15
|
+
const URL = getBaseUrl("SKYRAMP_TEST_BASE_URL", "https://demoshop.skyramp.dev");
|
|
16
|
+
let product_id = "product_id";
|
|
17
|
+
|
|
18
|
+
function getHeader() {
|
|
19
|
+
// Definition of authentication header
|
|
20
|
+
const headers: Record<string, string> = {};
|
|
21
|
+
if (process.env.SKYRAMP_TEST_TOKEN && process.env.SKYRAMP_TEST_TOKEN != "") {
|
|
22
|
+
headers["Authorization"] = "Bearer " + process.env.SKYRAMP_TEST_TOKEN;
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test.afterAll(async () => {
|
|
28
|
+
// Invocation of Skyramp Client
|
|
29
|
+
const client = new SkyrampClient();
|
|
30
|
+
// Definition of authentication header
|
|
31
|
+
const headers = getHeader();
|
|
32
|
+
|
|
33
|
+
// Execute Request
|
|
34
|
+
const productsProductIdDeleteResponse = await client.sendRequest({
|
|
35
|
+
url: URL,
|
|
36
|
+
path: "/api/v1/products/{product_id}",
|
|
37
|
+
method: "DELETE",
|
|
38
|
+
headers: headers,
|
|
39
|
+
pathParams: {"product_id": product_id}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Generated Assertions
|
|
43
|
+
expect(productsProductIdDeleteResponse.statusCode, 'status code').toBe(204);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// contract test for /api/v1/products POST
|
|
47
|
+
test('testProductsPost', async () => {
|
|
48
|
+
// Invocation of Skyramp Client
|
|
49
|
+
const client = new SkyrampClient();
|
|
50
|
+
// Definition of authentication header
|
|
51
|
+
const headers = getHeader();
|
|
52
|
+
|
|
53
|
+
// Request Body
|
|
54
|
+
const productsPostRequestBody: string = `{
|
|
55
|
+
"category": "Toys",
|
|
56
|
+
"description": "Bear Soft Toy",
|
|
57
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
58
|
+
"in_stock": true,
|
|
59
|
+
"name": "bigbear",
|
|
60
|
+
"price": 9.99
|
|
61
|
+
}`;
|
|
62
|
+
|
|
63
|
+
// Expected Response Body
|
|
64
|
+
const expectedProductsPostResponseBody: string = `{
|
|
65
|
+
"category": "Toys",
|
|
66
|
+
"created_at": "2025-02-25T10:54:22-05:00",
|
|
67
|
+
"description": "Bear Soft Toy",
|
|
68
|
+
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
|
|
69
|
+
"in_stock": true,
|
|
70
|
+
"name": "bigbear",
|
|
71
|
+
"price": 9.99,
|
|
72
|
+
"product_id": 1,
|
|
73
|
+
"updated_at": "2025-02-25T10:54:22-05:00"
|
|
74
|
+
}`;
|
|
75
|
+
|
|
76
|
+
// Execute Request
|
|
77
|
+
const productsPostResponse = await client.sendRequest({
|
|
78
|
+
url: URL,
|
|
79
|
+
path: "/api/v1/products",
|
|
80
|
+
method: "POST",
|
|
81
|
+
body: productsPostRequestBody,
|
|
82
|
+
headers: headers
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Generated Assertions
|
|
86
|
+
expect(productsPostResponse.statusCode, 'status code').toBe(201);
|
|
87
|
+
expect(checkSchema(productsPostResponse, expectedProductsPostResponseBody), 'schema').toBeTruthy();
|
|
88
|
+
expect(getResponseValue(productsPostResponse, "category"), 'value').not.toBeNull();
|
|
89
|
+
expect(getResponseValue(productsPostResponse, "created_at"), 'value').not.toBeNull();
|
|
90
|
+
expect(getResponseValue(productsPostResponse, "description"), 'value').not.toBeNull();
|
|
91
|
+
|
|
92
|
+
// Update global path param values
|
|
93
|
+
product_id = getResponseValue(productsPostResponse, "product_id");
|
|
94
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Generated by Skyramp v1.2.0+2a92d199 on 2026-06-22 23:35:13.098753 -0700 PDT m=+0.340207543
|
|
2
|
+
// Command: skyramp generate integration rest \
|
|
3
|
+
// --framework playwright \
|
|
4
|
+
// --language typescript \
|
|
5
|
+
// --output /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/integration/demoshop1/integration_test.spec.ts \
|
|
6
|
+
// --overwrite \
|
|
7
|
+
// --trace /Users/kisuhlee/git/skyramp/examples/v2/gen_reference/traces/datasets/demoshop1/skyramp-traces.json
|
|
8
|
+
|
|
9
|
+
// Import of required libraries
|
|
10
|
+
import { test, expect, SkyrampClient, getBaseUrl, getValue, getResponseValue } from '@skyramp/skyramp';
|
|
11
|
+
|
|
12
|
+
// URL for test requests
|
|
13
|
+
const URL_api = getBaseUrl("SKYRAMP_TEST_BASE_URL", "https://api.example.com");
|
|
14
|
+
|
|
15
|
+
test('testIntegration', async () => {
|
|
16
|
+
test.setTimeout(64000);
|
|
17
|
+
|
|
18
|
+
// Invocation of Skyramp Client
|
|
19
|
+
const client = new SkyrampClient();
|
|
20
|
+
// Definition of authentication header
|
|
21
|
+
const headers: Record<string, string> = {};
|
|
22
|
+
if (process.env.SKYRAMP_TEST_TOKEN && process.env.SKYRAMP_TEST_TOKEN != "") {
|
|
23
|
+
headers["Authorization"] = "Bearer " + process.env.SKYRAMP_TEST_TOKEN;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Request Body
|
|
27
|
+
const productsPostRequestBody: string = `{
|
|
28
|
+
"category": "Software Tools",
|
|
29
|
+
"description": "Professional API testing tool for developers and QA teams",
|
|
30
|
+
"image_url": "https://www.skyramp.dev/images/skyramp-tester.png",
|
|
31
|
+
"in_stock": true,
|
|
32
|
+
"name": "Skyramp Tester",
|
|
33
|
+
"price": 999
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
// Execute Request
|
|
37
|
+
const productsPostResponse = await client.sendRequest({
|
|
38
|
+
url: URL_api,
|
|
39
|
+
path: "/api/v1/products",
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: productsPostRequestBody,
|
|
42
|
+
headers: headers
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Generated Assertions
|
|
46
|
+
expect(productsPostResponse.statusCode, 'status code').toBe(201);
|
|
47
|
+
|
|
48
|
+
// Request Body
|
|
49
|
+
const ordersPostRequestBody: string = `{
|
|
50
|
+
"customer_email": "test@skyramp.dev",
|
|
51
|
+
"items": [
|
|
52
|
+
{
|
|
53
|
+
"product_id": 1,
|
|
54
|
+
"quantity": 1
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}`;
|
|
58
|
+
|
|
59
|
+
// Execute Request
|
|
60
|
+
const ordersPostResponse = await client.sendRequest({
|
|
61
|
+
url: URL_api,
|
|
62
|
+
path: "/api/v1/orders",
|
|
63
|
+
method: "POST",
|
|
64
|
+
body: ordersPostRequestBody,
|
|
65
|
+
headers: headers,
|
|
66
|
+
dataOverride: {"items.0.product_id": getResponseValue(productsPostResponse, "product_id")}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Generated Assertions
|
|
70
|
+
expect(ordersPostResponse.statusCode, 'status code').toBe(201);
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"0.12.0-v3.50","commit":"607f59717009d16d3d51c1795734ad1c443df596"}
|