@cuppet/core 2.0.0 → 2.0.2
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/features/app/hooks.js
CHANGED
|
@@ -102,7 +102,7 @@ Before(async function (testCase) {
|
|
|
102
102
|
|
|
103
103
|
// executed after every test
|
|
104
104
|
After(async function (testCase) {
|
|
105
|
-
if (testCase.result
|
|
105
|
+
if (testCase.result?.status !== Status.PASSED) {
|
|
106
106
|
console.log(`Scenario: '${testCase.pickle.name}' - has failed...\r\n`);
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -50,9 +50,9 @@ class KafkaManager {
|
|
|
50
50
|
*/
|
|
51
51
|
async initialize() {
|
|
52
52
|
try {
|
|
53
|
-
// Create Kafka instance
|
|
53
|
+
// Create Kafka instance (no actual connection yet)
|
|
54
54
|
this.kafka = new Kafka(this.options);
|
|
55
|
-
console.log(
|
|
55
|
+
console.log('Kafka client instance created successfully.');
|
|
56
56
|
this.isInitialized = true;
|
|
57
57
|
} catch (error) {
|
|
58
58
|
throw new Error(`Failed to initialize Kafka client: ${error.message}`);
|
|
@@ -68,9 +68,16 @@ class KafkaManager {
|
|
|
68
68
|
if (!this.isInitialized) {
|
|
69
69
|
throw new Error('Kafka client not initialized. Call initialize() first.');
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
this.producer = this.kafka.producer(producerOptions);
|
|
74
|
+
await this.producer.connect();
|
|
75
|
+
console.log('Producer connected successfully to Kafka broker');
|
|
76
|
+
return this.producer;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
this.producer = null;
|
|
79
|
+
throw new Error(`Failed to connect producer to Kafka broker: ${error.message}`);
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
/**
|
|
@@ -87,9 +94,15 @@ class KafkaManager {
|
|
|
87
94
|
consumerOptions.groupId = `cuppet-test-${Math.random().toString(16).slice(2, 8)}`;
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
try {
|
|
98
|
+
this.consumer = this.kafka.consumer(consumerOptions);
|
|
99
|
+
await this.consumer.connect();
|
|
100
|
+
console.log('Consumer connected successfully to Kafka broker');
|
|
101
|
+
return this.consumer;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
this.consumer = null;
|
|
104
|
+
throw new Error(`Failed to connect consumer to Kafka broker: ${error.message}`);
|
|
105
|
+
}
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
/**
|
|
@@ -106,13 +119,18 @@ class KafkaManager {
|
|
|
106
119
|
* @returns {Promise<void>}
|
|
107
120
|
*/
|
|
108
121
|
async sendMessage(topic, message = {}) {
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
try {
|
|
123
|
+
if (!this.producer) {
|
|
124
|
+
await this.createProducer();
|
|
125
|
+
}
|
|
126
|
+
await this.producer.send({
|
|
127
|
+
topic,
|
|
128
|
+
messages: [message],
|
|
129
|
+
});
|
|
130
|
+
console.log(`Message sent successfully to topic: ${topic}`);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw new Error(`Failed to send message to topic '${topic}': ${error.message}`);
|
|
111
133
|
}
|
|
112
|
-
await this.producer.send({
|
|
113
|
-
topic,
|
|
114
|
-
messages: [message],
|
|
115
|
-
});
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
/** Subscribe to a topic
|
|
@@ -120,24 +138,41 @@ class KafkaManager {
|
|
|
120
138
|
* @returns {Promise<Object>} - Object with topic, partition, and message properties
|
|
121
139
|
*/
|
|
122
140
|
async subscribeToTopics(topics = []) {
|
|
123
|
-
|
|
124
|
-
|
|
141
|
+
try {
|
|
142
|
+
if (!this.consumer) {
|
|
143
|
+
await this.createConsumer();
|
|
144
|
+
}
|
|
145
|
+
await this.consumer.subscribe({
|
|
146
|
+
topics: topics,
|
|
147
|
+
});
|
|
148
|
+
console.log(`Successfully subscribed to topics: ${topics.join(', ')}`);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
throw new Error(`Failed to subscribe to topics [${topics.join(', ')}]: ${error.message}`);
|
|
125
151
|
}
|
|
126
|
-
await this.consumer.subscribe({
|
|
127
|
-
topics: topics,
|
|
128
|
-
});
|
|
129
152
|
}
|
|
130
153
|
|
|
131
154
|
/** Consume a message from a topic
|
|
132
155
|
* @returns {Promise<Object>} - Object with topic, partition, and message properties
|
|
133
156
|
*/
|
|
134
157
|
async consumeMessage() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
158
|
+
if (!this.consumer) {
|
|
159
|
+
throw new Error('Consumer not initialized. Call subscribeToTopics() first.');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
this.consumer
|
|
164
|
+
.run({
|
|
165
|
+
eachMessage: async ({ topic, partition, message }) => {
|
|
166
|
+
try {
|
|
167
|
+
resolve({ topic, partition, message });
|
|
168
|
+
} catch (error) {
|
|
169
|
+
reject(new Error(`Failed to process consumed message: ${error.message}`));
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
.catch((error) => {
|
|
174
|
+
reject(new Error(`Failed to consume message: ${error.message}`));
|
|
175
|
+
});
|
|
141
176
|
});
|
|
142
177
|
}
|
|
143
178
|
|
|
@@ -145,8 +180,18 @@ class KafkaManager {
|
|
|
145
180
|
* @returns {Promise<void>}
|
|
146
181
|
*/
|
|
147
182
|
async disconnect() {
|
|
148
|
-
|
|
149
|
-
|
|
183
|
+
if (!this.consumer) {
|
|
184
|
+
console.log('No consumer to disconnect');
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await this.consumer.stop();
|
|
190
|
+
await this.consumer.disconnect();
|
|
191
|
+
console.log('Consumer disconnected successfully');
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error(`Failed to disconnect consumer: ${error.message}`);
|
|
194
|
+
}
|
|
150
195
|
}
|
|
151
196
|
|
|
152
197
|
/**
|
package/package.json
CHANGED
package/src/apiFunctions.js
CHANGED
|
@@ -124,6 +124,9 @@ module.exports = {
|
|
|
124
124
|
return this.response;
|
|
125
125
|
} catch (error) {
|
|
126
126
|
console.log('Request has failed, use response code step definition to validate the response!');
|
|
127
|
+
if (!error.response) {
|
|
128
|
+
throw new Error(`Request failed with: ${error}`);
|
|
129
|
+
}
|
|
127
130
|
return (this.response = error.response);
|
|
128
131
|
}
|
|
129
132
|
},
|
|
@@ -200,13 +203,13 @@ module.exports = {
|
|
|
200
203
|
*
|
|
201
204
|
* @async
|
|
202
205
|
* @function propertyIs
|
|
203
|
-
* @param {string} property - The property of the response data to check.
|
|
206
|
+
* @param {string} property - The property of the response data to check. Written in root.parent.child syntax.
|
|
204
207
|
* @param {string} type - The type that the property should be.
|
|
205
208
|
* @throws {Error} - Will throw an error if the property is not of the specified type.
|
|
206
209
|
*/
|
|
207
210
|
propertyIs: async function (property, type) {
|
|
208
|
-
const value = this.response.data
|
|
209
|
-
|
|
211
|
+
const value = await helper.getPropertyValue(this.response.data, property);
|
|
212
|
+
assert.typeOf(value, type, `The property is not an ${type}`);
|
|
210
213
|
},
|
|
211
214
|
|
|
212
215
|
/**
|