specmatic 0.70.6 → 0.70.7
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/README.md +19 -1
- package/dist/index.js +12 -0
- package/dist/kafka/index.js +63 -7
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/kafka/index.ts +67 -5
package/README.md
CHANGED
|
@@ -90,7 +90,25 @@ Start kafka stub. Requires an OpenAPI kafka spec in specmatic.json
|
|
|
90
90
|
`stopKafkaStub(stub: KafkaStub)` <br />
|
|
91
91
|
Stop a running kafka stub
|
|
92
92
|
|
|
93
|
-
`
|
|
93
|
+
`setKafkaStubExpectations(stub: KafkaStub, expecations: any): Promise<void>` <br />
|
|
94
|
+
Set expected message count on Kafka for each topic. Expecations are of the format
|
|
95
|
+
```
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
"topic": "product-queries",
|
|
99
|
+
"count": 2
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"topic": "test-topic",
|
|
103
|
+
"count": 2
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`verifyKafkaStub(stub: KafkaStub): Promise<Boolean>` <br />
|
|
109
|
+
Verify all expecations set on Kafka
|
|
110
|
+
|
|
111
|
+
`verifyKafkaStubMessage(stub: KafkaStub, topic: string, value: string): Promise<Boolean>` <br />
|
|
94
112
|
Verify kafka message. This is invoked in tests to check on kafka side if a message expected to by pushed by a BFF api is recieved by Kafka. The Kafka stub starts a verification end point for this purpose which is invoked internally by this api.
|
|
95
113
|
|
|
96
114
|
## IDE Support
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "setExpectations", {
|
|
|
15
15
|
return _core.setExpectations;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "setKafkaStubExpectations", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _kafka.setKafkaStubExpectations;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "showTestResults", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function get() {
|
|
@@ -57,5 +63,11 @@ Object.defineProperty(exports, "verifyKafkaStub", {
|
|
|
57
63
|
return _kafka.verifyKafkaStub;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
66
|
+
Object.defineProperty(exports, "verifyKafkaStubMessage", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function get() {
|
|
69
|
+
return _kafka.verifyKafkaStubMessage;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
60
72
|
var _core = require("./core");
|
|
61
73
|
var _kafka = require("./kafka");
|
package/dist/kafka/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.verifyKafkaStub = exports.stopKafkaStub = exports.startKafkaStub = exports.KafkaStub = void 0;
|
|
6
|
+
exports.verifyKafkaStubMessage = exports.verifyKafkaStub = exports.stopKafkaStub = exports.startKafkaStub = exports.setKafkaStubExpectations = exports.KafkaStub = void 0;
|
|
7
7
|
var _runner = require("../common/runner");
|
|
8
8
|
var _logger = _interopRequireDefault(require("../common/logger"));
|
|
9
9
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
@@ -79,9 +79,65 @@ var stopKafkaStub = /*#__PURE__*/function () {
|
|
|
79
79
|
};
|
|
80
80
|
}();
|
|
81
81
|
exports.stopKafkaStub = stopKafkaStub;
|
|
82
|
-
var
|
|
83
|
-
var
|
|
82
|
+
var setKafkaStubExpectations = (stub, expecations) => {
|
|
83
|
+
var exectationsUrl = "http://localhost:".concat(stub.apiPort, "/_expectations");
|
|
84
|
+
_logger.default.info("Kafka Set Expectations: Url is ".concat(exectationsUrl));
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
(0, _nodeFetch.default)("".concat(exectationsUrl), {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: {
|
|
89
|
+
Accept: 'application/json',
|
|
90
|
+
'Content-Type': 'application/json'
|
|
91
|
+
},
|
|
92
|
+
body: JSON.stringify(expecations)
|
|
93
|
+
}).then(response => {
|
|
94
|
+
if (response.status != 200) {
|
|
95
|
+
_logger.default.error("Kafka Set Expectations: Failed with status code ".concat(response.status));
|
|
96
|
+
reject();
|
|
97
|
+
} else {
|
|
98
|
+
return response.text();
|
|
99
|
+
}
|
|
100
|
+
}).then(data => {
|
|
101
|
+
_logger.default.debug("Kafka Set Expectations: Finished ".concat(JSON.stringify(data)));
|
|
102
|
+
resolve();
|
|
103
|
+
}).catch(err => {
|
|
104
|
+
_logger.default.error("Kafka Set Expectations: Failed with error ".concat(err));
|
|
105
|
+
reject();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
exports.setKafkaStubExpectations = setKafkaStubExpectations;
|
|
110
|
+
var verifyKafkaStub = stub => {
|
|
111
|
+
var verificationUrl = "http://localhost:".concat(stub.apiPort, "/_expectations/verifications");
|
|
84
112
|
_logger.default.info("Kafka Verification: Url is ".concat(verificationUrl));
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
(0, _nodeFetch.default)("".concat(verificationUrl), {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers: {
|
|
117
|
+
Accept: 'application/json',
|
|
118
|
+
'Content-Type': 'application/json'
|
|
119
|
+
}
|
|
120
|
+
}).then(response => {
|
|
121
|
+
if (response.status != 200) {
|
|
122
|
+
_logger.default.error("Kafka Verification: Failed with status code ".concat(response.status));
|
|
123
|
+
reject();
|
|
124
|
+
} else {
|
|
125
|
+
return response.json();
|
|
126
|
+
}
|
|
127
|
+
}).then(data => {
|
|
128
|
+
_logger.default.debug("Kafka Verification: Finished ".concat(JSON.stringify(data)));
|
|
129
|
+
if (!data.success) _logger.default.info("Kafka Verification: Errors\n".concat(JSON.stringify(data)));
|
|
130
|
+
resolve(data.success);
|
|
131
|
+
}).catch(err => {
|
|
132
|
+
_logger.default.error("Kafka Verify Message: Failed with error ".concat(err));
|
|
133
|
+
reject();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
exports.verifyKafkaStub = verifyKafkaStub;
|
|
138
|
+
var verifyKafkaStubMessage = (stub, topic, value) => {
|
|
139
|
+
var verificationUrl = "http://localhost:".concat(stub.apiPort, "/_verifications");
|
|
140
|
+
_logger.default.info("Kafka Verify Message: Url is ".concat(verificationUrl));
|
|
85
141
|
return new Promise((resolve, reject) => {
|
|
86
142
|
(0, _nodeFetch.default)("".concat(verificationUrl), {
|
|
87
143
|
method: 'POST',
|
|
@@ -95,18 +151,18 @@ var verifyKafkaStub = (stub, topic, value) => {
|
|
|
95
151
|
})
|
|
96
152
|
}).then(response => {
|
|
97
153
|
if (response.status != 200) {
|
|
98
|
-
_logger.default.error("Kafka
|
|
154
|
+
_logger.default.error("Kafka Verify Message: Failed with status code ".concat(response.status));
|
|
99
155
|
reject();
|
|
100
156
|
} else {
|
|
101
157
|
return response.json();
|
|
102
158
|
}
|
|
103
159
|
}).then(data => {
|
|
104
|
-
_logger.default.debug("Kafka
|
|
160
|
+
_logger.default.debug("Kafka Verify Message: Finished ".concat(JSON.stringify(data)));
|
|
105
161
|
resolve(data.received);
|
|
106
162
|
}).catch(err => {
|
|
107
|
-
_logger.default.error("Kafka
|
|
163
|
+
_logger.default.error("Kafka Verify Message: Failed with error ".concat(err));
|
|
108
164
|
reject();
|
|
109
165
|
});
|
|
110
166
|
});
|
|
111
167
|
};
|
|
112
|
-
exports.
|
|
168
|
+
exports.verifyKafkaStubMessage = verifyKafkaStubMessage;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { startStub, stopStub, test, setExpectations, printJarVersion, showTestResults } from './core';
|
|
2
|
-
export { startKafkaStub, stopKafkaStub, verifyKafkaStub } from './kafka';
|
|
2
|
+
export { startKafkaStub, stopKafkaStub, verifyKafkaStubMessage, verifyKafkaStub, setKafkaStubExpectations } from './kafka';
|
package/src/kafka/index.ts
CHANGED
|
@@ -72,8 +72,39 @@ const stopKafkaStub = async (stub: KafkaStub) => {
|
|
|
72
72
|
logger.info(`Kafka Stub: Stopped at port=${stub.port}, apiPort=${stub.apiPort}`);
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
const
|
|
76
|
-
const
|
|
75
|
+
const setKafkaStubExpectations = (stub: KafkaStub, expecations: any): Promise<void> => {
|
|
76
|
+
const exectationsUrl = `http://localhost:${stub.apiPort}/_expectations`;
|
|
77
|
+
logger.info(`Kafka Set Expectations: Url is ${exectationsUrl}`);
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
fetch(`${exectationsUrl}`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: 'application/json',
|
|
83
|
+
'Content-Type': 'application/json',
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify(expecations),
|
|
86
|
+
})
|
|
87
|
+
.then(response => {
|
|
88
|
+
if (response.status != 200) {
|
|
89
|
+
logger.error(`Kafka Set Expectations: Failed with status code ${response.status}`);
|
|
90
|
+
reject();
|
|
91
|
+
} else {
|
|
92
|
+
return response.text();
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
.then(data => {
|
|
96
|
+
logger.debug(`Kafka Set Expectations: Finished ${JSON.stringify(data)}`);
|
|
97
|
+
resolve();
|
|
98
|
+
})
|
|
99
|
+
.catch(err => {
|
|
100
|
+
logger.error(`Kafka Set Expectations: Failed with error ${err}`);
|
|
101
|
+
reject();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const verifyKafkaStub = (stub: KafkaStub): Promise<Boolean> => {
|
|
107
|
+
const verificationUrl = `http://localhost:${stub.apiPort}/_expectations/verifications`;
|
|
77
108
|
logger.info(`Kafka Verification: Url is ${verificationUrl}`);
|
|
78
109
|
return new Promise((resolve, reject) => {
|
|
79
110
|
fetch(`${verificationUrl}`, {
|
|
@@ -82,7 +113,6 @@ const verifyKafkaStub = (stub: KafkaStub, topic: string, value: string) => {
|
|
|
82
113
|
Accept: 'application/json',
|
|
83
114
|
'Content-Type': 'application/json',
|
|
84
115
|
},
|
|
85
|
-
body: JSON.stringify({ topic: topic, value: value }),
|
|
86
116
|
})
|
|
87
117
|
.then(response => {
|
|
88
118
|
if (response.status != 200) {
|
|
@@ -94,13 +124,45 @@ const verifyKafkaStub = (stub: KafkaStub, topic: string, value: string) => {
|
|
|
94
124
|
})
|
|
95
125
|
.then(data => {
|
|
96
126
|
logger.debug(`Kafka Verification: Finished ${JSON.stringify(data)}`);
|
|
127
|
+
if (!data.success) logger.info(`Kafka Verification: Errors\n${JSON.stringify(data)}`);
|
|
128
|
+
resolve(data.success);
|
|
129
|
+
})
|
|
130
|
+
.catch(err => {
|
|
131
|
+
logger.error(`Kafka Verify Message: Failed with error ${err}`);
|
|
132
|
+
reject();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const verifyKafkaStubMessage = (stub: KafkaStub, topic: string, value: string): Promise<Boolean> => {
|
|
138
|
+
const verificationUrl = `http://localhost:${stub.apiPort}/_verifications`;
|
|
139
|
+
logger.info(`Kafka Verify Message: Url is ${verificationUrl}`);
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
fetch(`${verificationUrl}`, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: {
|
|
144
|
+
Accept: 'application/json',
|
|
145
|
+
'Content-Type': 'application/json',
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify({ topic: topic, value: value }),
|
|
148
|
+
})
|
|
149
|
+
.then(response => {
|
|
150
|
+
if (response.status != 200) {
|
|
151
|
+
logger.error(`Kafka Verify Message: Failed with status code ${response.status}`);
|
|
152
|
+
reject();
|
|
153
|
+
} else {
|
|
154
|
+
return response.json();
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
.then(data => {
|
|
158
|
+
logger.debug(`Kafka Verify Message: Finished ${JSON.stringify(data)}`);
|
|
97
159
|
resolve(data.received);
|
|
98
160
|
})
|
|
99
161
|
.catch(err => {
|
|
100
|
-
logger.error(`Kafka
|
|
162
|
+
logger.error(`Kafka Verify Message: Failed with error ${err}`);
|
|
101
163
|
reject();
|
|
102
164
|
});
|
|
103
165
|
});
|
|
104
166
|
};
|
|
105
167
|
|
|
106
|
-
export { startKafkaStub, stopKafkaStub, verifyKafkaStub };
|
|
168
|
+
export { startKafkaStub, stopKafkaStub, verifyKafkaStubMessage, verifyKafkaStub, setKafkaStubExpectations };
|