From 10bc3b9584f2e1139d1055d6fdc03ea3f4a7e6c2 Mon Sep 17 00:00:00 2001 From: Amaury Date: Sun, 14 Mar 2021 18:18:29 +0100 Subject: [PATCH] added test's setup --- package-lock.json | 6 ++++++ package.json | 13 +++++++------ src/gestion-listener.ts | 18 ++++++++++++++++-- test/index-spec.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 test/index-spec.ts diff --git a/package-lock.json b/package-lock.json index ad42504..d88cd71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2475,6 +2475,12 @@ "is-number": "^7.0.0" } }, + "ts-mock-imports": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/ts-mock-imports/-/ts-mock-imports-1.3.3.tgz", + "integrity": "sha512-zCAcb89Y+f3Bhw5VaHrHMh5tiuwAQEl5D3e0r5ELCdLl9EnZpb8Oeei/S60Qf4LORIfmJEXb3TpR5kxtL6j2cg==", + "dev": true + }, "ts-node": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", diff --git a/package.json b/package.json index c182597..f3c3e84 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,13 @@ "author": "Amaury Joly ", "license": "MIT", "devDependencies": { - "@types/node": "^14.14.33", - "@types/mocha": "^8.2.1", "@types/chai": "^4.2.15", - "@typescript-eslint/parser": "^4.17.0", + "@types/mocha": "^8.2.1", + "@types/node": "^14.14.33", "@typescript-eslint/eslint-plugin": "^4.17.0", - "cross-env": "^7.0.3", + "@typescript-eslint/parser": "^4.17.0", "chai": "^4.3.3", + "cross-env": "^7.0.3", "eslint": "^7.21.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-config-prettier": "^8.1.0", @@ -26,9 +26,10 @@ "eslint-plugin-prettier": "3.3.1", "mocha": "8.2.1", "prettier": "2.2.1", - "sinon-chai": "3.5.0", - "ts-sinon": "2.0.1", + "sinon-chai": "^3.5.0", + "ts-mock-imports": "^1.3.3", "ts-node": "9.1.1", + "ts-sinon": "2.0.1", "typescript": "^4.1.3" }, "dependencies": { diff --git a/src/gestion-listener.ts b/src/gestion-listener.ts index 8ac1b17..a7859ff 100644 --- a/src/gestion-listener.ts +++ b/src/gestion-listener.ts @@ -1,5 +1,19 @@ -import {} from ""; +import { ListenerRss, ListenerRSSInfos } from "listener-rss/src/"; +/** + * Permit to manage a ListenerRSS array, data storage and event aggregation + */ export class GestionListener { - GestionListener(): any {} + listenerArray: ListenerRss[] = []; + + GestionListener(path?: string): void { + if (path) { + // load a file or a bdd + } else { + // keep the class empty + } + } + addNewListener(info: ListenerRSSInfos): void { + this.listenerArray.concat(new ListenerRss(info)); + } } diff --git a/test/index-spec.ts b/test/index-spec.ts new file mode 100644 index 0000000..8172b54 --- /dev/null +++ b/test/index-spec.ts @@ -0,0 +1,40 @@ +// external lib +import { ListenerRss, ListenerRSSInfos } from "listener-rss/src/"; + +// local lib +import { GestionListener } from "/src/index"; + +// Unit test +import * as chai from "chai"; +import sinon from "ts-sinon"; +import sinonChai from "sinon-chai"; +import { ImportMock, InPlaceMockManager } from "ts-mock-imports"; + +chai.use(sinonChai); + +const expect = chai.expect; + +describe("test class GestionListener", function () { + const listenerInfoArray: ListenerRSSInfos[] = [ + { + name: "service1", + address: "fake.rss.service1", + timeloop: 45, + }, + { + name: "service2", + address: "fake.rss.service2", + timeloop: 30, + }, + { + name: "service3", + address: "fake.rss.service3", + timeloop: 15, + }, + { + name: "service4", + address: "fake.rss.service4", + timeloop: 60, + }, + ]; +});