@actionlogementservices/wdio-test-context 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/amqp-client.js +15 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actionlogementservices/wdio-test-context",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A framework to add test context to webdriverio end to end tests.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -27,23 +27,31 @@ export async function publishMessage(connectionString, exchange, routingKey, typ
27
27
  let channel;
28
28
  try {
29
29
  connection = await amqp.connect(connectionString, { clientProperties: { connection_name: appId } });
30
- channel = await connection.createChannel();
30
+ channel = await connection.createConfirmChannel();
31
31
  const content = Buffer.from(JSON.stringify(payload));
32
32
  /** @type {import('amqplib').Options.Publish} */ const options = {
33
33
  appId,
34
+ headers: {},
34
35
  contentType: 'application/json',
35
36
  correlationId,
36
37
  timestamp: Date.now(),
37
38
  type
38
39
  };
39
- const result = channel.publish(exchange, routingKey, content, options);
40
- if (result) logger.debug('Amqp message sent.');
41
- return result;
40
+ return new Promise((resolve, reject) =>
41
+ channel.publish(exchange, routingKey, content, options, error => {
42
+ if (error) {
43
+ logger.detailError(error);
44
+ reject(`Amqp error: '${error.message}'!`);
45
+ } else {
46
+ logger.debug('Amqp message sent.');
47
+ resolve(true);
48
+ }
49
+ if (channel) channel.close();
50
+ if (connection) connection.close();
51
+ })
52
+ );
42
53
  } catch (error) {
43
54
  logger.detailError(error);
44
55
  throw new Error(`Amqp error: '${error.message}'!`);
45
- } finally {
46
- if (channel) channel.close();
47
- if (connection) connection.close();
48
56
  }
49
57
  }