From 06e004c766259587906e6e0a370465bb4b56653d Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:29:12 +0000 Subject: [PATCH 01/13] feat: Add unit tests for InfluxDBReporter class --- test/influxdb-reporter.test.js | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/influxdb-reporter.test.js diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js new file mode 100644 index 0000000..eecbfcc --- /dev/null +++ b/test/influxdb-reporter.test.js @@ -0,0 +1,64 @@ +const InfluxDBReporter = require('../src/influxdb-reporter'); +const HttpService = require('../src/http.service'); +const UdpService = require('../src/udp.service'); + +jest.mock('../src/http.service'); +jest.mock('../src/udp.service'); + +describe('InfluxDBReporter', () => { + let reporter; + + beforeEach(() => { + reporter = new InfluxDBReporter(); + }); + + describe('start', () => { + it('sets up the context correctly', () => { + // Test setup and assertions here + }); + + it('throws an error when required parameters are missing', () => { + // Test setup and assertions here + }); + }); + + describe('beforeItem', () => { + it('updates the context correctly', () => { + // Test setup and assertions here + }); + }); + + describe('request', () => { + it('updates the current item\'s data correctly', () => { + // Test setup and assertions here + }); + }); + + describe('exception', () => { + it('does not throw any errors when called', () => { + // Test setup and assertions here + }); + }); + + describe('assertion', () => { + it('updates the assertion count correctly', () => { + // Test setup and assertions here + }); + + it('handles failed and skipped assertions correctly', () => { + // Test setup and assertions here + }); + }); + + describe('item', () => { + it('sends data to the service correctly', () => { + // Test setup and assertions here + }); + }); + + describe('done', () => { + it('disconnects the service correctly', () => { + // Test setup and assertions here + }); + }); +}); From c39c94747d61f1f3babdccd1e5012914dfd6ddf9 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:29:51 +0000 Subject: [PATCH 02/13] Sandbox run test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index eecbfcc..a74c86d 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -1,63 +1,63 @@ -const InfluxDBReporter = require('../src/influxdb-reporter'); -const HttpService = require('../src/http.service'); -const UdpService = require('../src/udp.service'); +const InfluxDBReporter = require("../src/influxdb-reporter"); +const HttpService = require("../src/http.service"); +const UdpService = require("../src/udp.service"); -jest.mock('../src/http.service'); -jest.mock('../src/udp.service'); +jest.mock("../src/http.service"); +jest.mock("../src/udp.service"); -describe('InfluxDBReporter', () => { +describe("InfluxDBReporter", () => { let reporter; beforeEach(() => { reporter = new InfluxDBReporter(); }); - describe('start', () => { - it('sets up the context correctly', () => { + describe("start", () => { + it("sets up the context correctly", () => { // Test setup and assertions here }); - it('throws an error when required parameters are missing', () => { + it("throws an error when required parameters are missing", () => { // Test setup and assertions here }); }); - describe('beforeItem', () => { - it('updates the context correctly', () => { + describe("beforeItem", () => { + it("updates the context correctly", () => { // Test setup and assertions here }); }); - describe('request', () => { - it('updates the current item\'s data correctly', () => { + describe("request", () => { + it("updates the current item's data correctly", () => { // Test setup and assertions here }); }); - describe('exception', () => { - it('does not throw any errors when called', () => { + describe("exception", () => { + it("does not throw any errors when called", () => { // Test setup and assertions here }); }); - describe('assertion', () => { - it('updates the assertion count correctly', () => { + describe("assertion", () => { + it("updates the assertion count correctly", () => { // Test setup and assertions here }); - it('handles failed and skipped assertions correctly', () => { + it("handles failed and skipped assertions correctly", () => { // Test setup and assertions here }); }); - describe('item', () => { - it('sends data to the service correctly', () => { + describe("item", () => { + it("sends data to the service correctly", () => { // Test setup and assertions here }); }); - describe('done', () => { - it('disconnects the service correctly', () => { + describe("done", () => { + it("disconnects the service correctly", () => { // Test setup and assertions here }); }); From 9c874d29584cf8d30173db92d7a5b7ed259b21bd Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:30:17 +0000 Subject: [PATCH 03/13] feat: Add unit test step to Github Actions workflo --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..2b27dfe --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 16.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - name: Run Unit Tests + run: npm test From f2abc5b00f107c38be53c8c2d6ac73576be6164b Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:35:47 +0000 Subject: [PATCH 04/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index a74c86d..5a25331 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -14,51 +14,70 @@ describe("InfluxDBReporter", () => { describe("start", () => { it("sets up the context correctly", () => { - // Test setup and assertions here + const config = { /* some configuration */ }; + reporter.start(config); + expect(reporter.context).toEqual(config); }); it("throws an error when required parameters are missing", () => { - // Test setup and assertions here + const config = { /* missing required parameters */ }; + expect(() => reporter.start(config)).toThrow(); }); }); describe("beforeItem", () => { it("updates the context correctly", () => { - // Test setup and assertions here + const item = { /* some item */ }; + reporter.beforeItem(null, { item }); + expect(reporter.context.currentItem).toBe(item); }); }); describe("request", () => { it("updates the current item's data correctly", () => { - // Test setup and assertions here + const args = { /* some args */ }; + reporter.request(null, args); + expect(reporter.context.currentItem.data).toEqual(args); }); }); describe("exception", () => { it("does not throw any errors when called", () => { - // Test setup and assertions here + expect(() => reporter.exception()).not.toThrow(); }); }); describe("assertion", () => { it("updates the assertion count correctly", () => { - // Test setup and assertions here + reporter.assertion(null, {}); + expect(reporter.context.currentItem.data.assertions).toBe(1); }); it("handles failed and skipped assertions correctly", () => { - // Test setup and assertions here + const error = { /* some error */ }; + reporter.assertion(error, { skipped: false }); + expect(reporter.context.currentItem.data.failed_count).toBe(1); + expect(reporter.context.currentItem.data.skipped_count).toBe(0); + + reporter.assertion(null, { skipped: true }); + expect(reporter.context.currentItem.data.failed_count).toBe(1); + expect(reporter.context.currentItem.data.skipped_count).toBe(1); }); }); describe("item", () => { it("sends data to the service correctly", () => { - // Test setup and assertions here + const sendData = jest.spyOn(reporter.service, 'sendData'); + reporter.item(); + expect(sendData).toHaveBeenCalled(); }); }); describe("done", () => { it("disconnects the service correctly", () => { - // Test setup and assertions here + const disconnect = jest.spyOn(reporter.service, 'disconnect'); + reporter.done(); + expect(disconnect).toHaveBeenCalled(); }); }); }); From 2b5dc1de5fcdead15390258cb854b20d2e905404 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:36:05 +0000 Subject: [PATCH 05/13] Sandbox run test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 5a25331..6b5be5e 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -14,20 +14,26 @@ describe("InfluxDBReporter", () => { describe("start", () => { it("sets up the context correctly", () => { - const config = { /* some configuration */ }; + const config = { + /* some configuration */ + }; reporter.start(config); expect(reporter.context).toEqual(config); }); it("throws an error when required parameters are missing", () => { - const config = { /* missing required parameters */ }; + const config = { + /* missing required parameters */ + }; expect(() => reporter.start(config)).toThrow(); }); }); describe("beforeItem", () => { it("updates the context correctly", () => { - const item = { /* some item */ }; + const item = { + /* some item */ + }; reporter.beforeItem(null, { item }); expect(reporter.context.currentItem).toBe(item); }); @@ -35,7 +41,9 @@ describe("InfluxDBReporter", () => { describe("request", () => { it("updates the current item's data correctly", () => { - const args = { /* some args */ }; + const args = { + /* some args */ + }; reporter.request(null, args); expect(reporter.context.currentItem.data).toEqual(args); }); @@ -54,7 +62,9 @@ describe("InfluxDBReporter", () => { }); it("handles failed and skipped assertions correctly", () => { - const error = { /* some error */ }; + const error = { + /* some error */ + }; reporter.assertion(error, { skipped: false }); expect(reporter.context.currentItem.data.failed_count).toBe(1); expect(reporter.context.currentItem.data.skipped_count).toBe(0); @@ -67,7 +77,7 @@ describe("InfluxDBReporter", () => { describe("item", () => { it("sends data to the service correctly", () => { - const sendData = jest.spyOn(reporter.service, 'sendData'); + const sendData = jest.spyOn(reporter.service, "sendData"); reporter.item(); expect(sendData).toHaveBeenCalled(); }); @@ -75,7 +85,7 @@ describe("InfluxDBReporter", () => { describe("done", () => { it("disconnects the service correctly", () => { - const disconnect = jest.spyOn(reporter.service, 'disconnect'); + const disconnect = jest.spyOn(reporter.service, "disconnect"); reporter.done(); expect(disconnect).toHaveBeenCalled(); }); From fed46ae79ae12740b0b09e321008f486e0f907ae Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:37:27 +0000 Subject: [PATCH 06/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 6b5be5e..35b1451 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -12,6 +12,80 @@ describe("InfluxDBReporter", () => { reporter = new InfluxDBReporter(); }); + describe("start", () => { + it("sets up the context correctly", () => { + const config = { /* some configuration */ }; + reporter.start(config); + expect(reporter.context).toEqual(config); + }); + + it("throws an error when required parameters are missing", () => { + const config = { /* missing required parameters */ }; + expect(() => reporter.start(config)).toThrow(); + }); + }); + + describe("beforeItem", () => { + it("updates the context correctly", () => { + const item = { /* some item */ }; + reporter.beforeItem(null, { item }); + expect(reporter.context.currentItem).toBe(item); + }); + }); + + describe("request", () => { + it("updates the current item's data correctly", () => { + const args = { /* some args */ }; + reporter.request(null, args); + expect(reporter.context.currentItem.data).toEqual(args); + }); + }); + + describe("exception", () => { + it("does not throw any errors when called", () => { + expect(() => reporter.exception()).not.toThrow(); + }); + }); + + describe("assertion", () => { + it("updates the assertion count correctly", () => { + reporter.assertion(null, {}); + expect(reporter.context.currentItem.data.assertions).toBe(1); + }); + + it("handles failed and skipped assertions correctly", () => { + const error = { /* some error */ }; + reporter.assertion(error, { skipped: false }); + expect(reporter.context.currentItem.data.failed_count).toBe(1); + expect(reporter.context.currentItem.data.skipped_count).toBe(0); + + reporter.assertion(null, { skipped: true }); + expect(reporter.context.currentItem.data.failed_count).toBe(1); + expect(reporter.context.currentItem.data.skipped_count).toBe(1); + }); + }); + + describe("item", () => { + it("sends data to the service correctly", () => { + const sendData = jest.spyOn(reporter.service, "sendData"); + reporter.item(); + expect(sendData).toHaveBeenCalled(); + }); + }); + + describe("done", () => { + it("disconnects the service correctly", () => { + const disconnect = jest.spyOn(reporter.service, "disconnect"); + reporter.done(); + expect(disconnect).toHaveBeenCalled(); + }); + }); +}); + + beforeEach(() => { + reporter = new InfluxDBReporter(); + }); + describe("start", () => { it("sets up the context correctly", () => { const config = { From 2f05e6fd9157f58109c9afadce9d4258488e3457 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:38:26 +0000 Subject: [PATCH 07/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 35b1451..8ea10c3 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -80,7 +80,6 @@ describe("InfluxDBReporter", () => { expect(disconnect).toHaveBeenCalled(); }); }); -}); beforeEach(() => { reporter = new InfluxDBReporter(); From aa44015636ddd38bb02b18e815971f07701d479a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:38:44 +0000 Subject: [PATCH 08/13] Sandbox run test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 8ea10c3..9c9d17d 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -14,20 +14,26 @@ describe("InfluxDBReporter", () => { describe("start", () => { it("sets up the context correctly", () => { - const config = { /* some configuration */ }; + const config = { + /* some configuration */ + }; reporter.start(config); expect(reporter.context).toEqual(config); }); it("throws an error when required parameters are missing", () => { - const config = { /* missing required parameters */ }; + const config = { + /* missing required parameters */ + }; expect(() => reporter.start(config)).toThrow(); }); }); describe("beforeItem", () => { it("updates the context correctly", () => { - const item = { /* some item */ }; + const item = { + /* some item */ + }; reporter.beforeItem(null, { item }); expect(reporter.context.currentItem).toBe(item); }); @@ -35,7 +41,9 @@ describe("InfluxDBReporter", () => { describe("request", () => { it("updates the current item's data correctly", () => { - const args = { /* some args */ }; + const args = { + /* some args */ + }; reporter.request(null, args); expect(reporter.context.currentItem.data).toEqual(args); }); @@ -54,7 +62,9 @@ describe("InfluxDBReporter", () => { }); it("handles failed and skipped assertions correctly", () => { - const error = { /* some error */ }; + const error = { + /* some error */ + }; reporter.assertion(error, { skipped: false }); expect(reporter.context.currentItem.data.failed_count).toBe(1); expect(reporter.context.currentItem.data.skipped_count).toBe(0); From f1611d5dd2df9cca25bf37673f581cdd4a3a2409 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:39:34 +0000 Subject: [PATCH 09/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 9c9d17d..474f2e9 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -12,6 +12,18 @@ describe("InfluxDBReporter", () => { reporter = new InfluxDBReporter(); }); + describe("request", () => { + it("updates the current item's data correctly", () => { + const request = { /* some request */ }; + reporter.request(null, request); + expect(reporter.context.currentItem.data).toEqual(request); + }); + }); + + beforeEach(() => { + reporter = new InfluxDBReporter(); + }); + describe("start", () => { it("sets up the context correctly", () => { const config = { From 2cd34013f57a60e25cb7d5fbf2e454b0dde525dc Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:39:53 +0000 Subject: [PATCH 10/13] Sandbox run test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 474f2e9..06ce000 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -14,7 +14,9 @@ describe("InfluxDBReporter", () => { describe("request", () => { it("updates the current item's data correctly", () => { - const request = { /* some request */ }; + const request = { + /* some request */ + }; reporter.request(null, request); expect(reporter.context.currentItem.data).toEqual(request); }); From 2c2c458d56303bb8074a67af8bcfd5f564640f52 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:40:42 +0000 Subject: [PATCH 11/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index 06ce000..c31c61a 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -64,8 +64,9 @@ describe("InfluxDBReporter", () => { }); describe("exception", () => { - it("does not throw any errors when called", () => { - expect(() => reporter.exception()).not.toThrow(); + it("does not throw any errors when called with an error", () => { + const error = new Error("Test error"); + expect(() => reporter.exception(error)).not.toThrow(); }); }); From 3c33a96a000a074b779a11d1ddc6a6620b003b60 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:42:24 +0000 Subject: [PATCH 12/13] feat: Updated test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index c31c61a..ab10ad0 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -92,9 +92,11 @@ describe("InfluxDBReporter", () => { describe("item", () => { it("sends data to the service correctly", () => { + const item = { /* some item */ }; + reporter.context.currentItem = item; const sendData = jest.spyOn(reporter.service, "sendData"); reporter.item(); - expect(sendData).toHaveBeenCalled(); + expect(sendData).toHaveBeenCalledWith(item); }); }); From 74b7996b06faaf8d309e972506f5182e7f9a4939 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 04:42:42 +0000 Subject: [PATCH 13/13] Sandbox run test/influxdb-reporter.test.js --- test/influxdb-reporter.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/influxdb-reporter.test.js b/test/influxdb-reporter.test.js index ab10ad0..f5c93d3 100644 --- a/test/influxdb-reporter.test.js +++ b/test/influxdb-reporter.test.js @@ -92,7 +92,9 @@ describe("InfluxDBReporter", () => { describe("item", () => { it("sends data to the service correctly", () => { - const item = { /* some item */ }; + const item = { + /* some item */ + }; reporter.context.currentItem = item; const sendData = jest.spyOn(reporter.service, "sendData"); reporter.item();