CollinsOduor / rabbitmq-demo

0 stars 0 forks source link

Sweep: Add tests to cover all lines of code #11

Open CollinsOduor opened 1 year ago

CollinsOduor commented 1 year ago
Checklist - [X] `test/receiveTest.js` > • Add unit tests for the `connect` function in `receive.js`. Mock the `amqplib` module to simulate different scenarios such as successful connection and connection error. > • Add unit tests for the `createChannel` function in `receive.js`. Mock the `connection` object to simulate different scenarios such as successful channel creation and channel creation error. > • Add unit tests for the `assertQueue` and `consume` functions in `receive.js`. Mock the `channel` object to simulate different scenarios. - [X] `test/sendTest.js` > • Write unit tests for the `send.js` file. Mock the `amqplib` module and the `channel` object to simulate different scenarios. - [X] `package.json` > • Add Istanbul as a dev dependency. > • Add a script to run Istanbul for code coverage.
sweep-ai[bot] commented 1 year ago

66% ⭐ In the meantime, consider starring our repo so more people can hear about us! ⚡ Sweep Free Trial: I'm creating this ticket using GPT-4. You have 4 GPT-4 tickets left for the month and 1 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/CollinsOduor/rabbitmq-demo/blob/9438809388bb46135cedc46bb9eb2b02e166a198/README.md#L1-L4 https://github.com/CollinsOduor/rabbitmq-demo/blob/9438809388bb46135cedc46bb9eb2b02e166a198/test/receiveTest.js#L1-L6 https://github.com/CollinsOduor/rabbitmq-demo/blob/9438809388bb46135cedc46bb9eb2b02e166a198/index.js#L1-L6 https://github.com/CollinsOduor/rabbitmq-demo/blob/9438809388bb46135cedc46bb9eb2b02e166a198/rabbit-mq-scripts/receive.js#L1-L46 https://github.com/CollinsOduor/rabbitmq-demo/blob/9438809388bb46135cedc46bb9eb2b02e166a198/rabbit-mq-scripts/send.js#L1-L49

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
test/receiveTest.js Modify test/receiveTest.js with contents:
• Add unit tests for the connect function in receive.js. Mock the amqplib module to simulate different scenarios such as successful connection and connection error.
• Add unit tests for the createChannel function in receive.js. Mock the connection object to simulate different scenarios such as successful channel creation and channel creation error.
• Add unit tests for the assertQueue and consume functions in receive.js. Mock the channel object to simulate different scenarios.
test/sendTest.js Create test/sendTest.js with contents:
• Write unit tests for the send.js file. Mock the amqplib module and the channel object to simulate different scenarios.
package.json Modify package.json with contents:
• Add Istanbul as a dev dependency.
• Add a script to run Istanbul for code coverage.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add unit tests and code coverage sweep/add-unit-tests

Description

This PR adds unit tests and code coverage for the connect, createChannel, assertQueue, consume functions in receive.js and the send.js file. It also includes the necessary modifications to the package.json file to add Istanbul as a dev dependency and a script to run Istanbul for code coverage.

Summary of Changes

  • Added unit tests for the connect function in receive.js to ensure correct connection to the RabbitMQ server. Mocked the amqplib module to simulate different scenarios.
  • Added unit tests for the createChannel function in receive.js to ensure correct channel creation. Mocked the connection object to simulate different scenarios.
  • Added unit tests for the assertQueue and consume functions in receive.js to ensure correct queue assertion and message consumption. Mocked the channel object to simulate different scenarios.
  • Added unit tests for the send.js file to ensure correct message sending to the queue. Mocked the amqplib module and the channel object to simulate different scenarios.
  • Added Istanbul as a dev dependency in the package.json file.
  • Added a script to run Istanbul for code coverage.

Please review and merge this PR to improve the code coverage and ensure the reliability of the application.


Step 4: ⌨️ Coding

File Instructions Progress Error logs
test/receiveTest.js Modify test/receiveTest.js with contents:
• Add unit tests for the connect function in receive.js. Mock the amqplib module to simulate different scenarios such as successful connection and connection error.
• Add unit tests for the createChannel function in receive.js. Mock the connection object to simulate different scenarios such as successful channel creation and channel creation error.
• Add unit tests for the assertQueue and consume functions in receive.js. Mock the channel object to simulate different scenarios.
✅ Commit 093b6e5 No errors.
test/sendTest.js Create test/sendTest.js with contents:
• Write unit tests for the send.js file. Mock the amqplib module and the channel object to simulate different scenarios.
✅ Commit 731cee8 No errors.
package.json Modify package.json with contents:
• Add Istanbul as a dev dependency.
• Add a script to run Istanbul for code coverage.
✅ Commit 04e9ba9 No errors. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Working on it...


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord