diff --git a/.run/Tests E2E Template.run.xml b/.run/Tests E2E Template.run.xml new file mode 100644 index 0000000..0e268e8 --- /dev/null +++ b/.run/Tests E2E Template.run.xml @@ -0,0 +1,20 @@ + + + project + + $PROJECT_DIR$/node_modules/mocha + $PROJECT_DIR$ + true + + + + + + bdd + --grep e2e --exit + DIRECTORY + $PROJECT_DIR$/test + true + + + \ No newline at end of file diff --git a/.run/Tests.run.xml b/.run/Tests.run.xml index 9d7de1c..c3b7d51 100644 --- a/.run/Tests.run.xml +++ b/.run/Tests.run.xml @@ -6,7 +6,7 @@ $PROJECT_DIR$ true bdd - + --grep should --exit DIRECTORY $PROJECT_DIR$/test true diff --git a/package.json b/package.json index 9ba7e9f..ab073db 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint": "eslint --ext .ts src", "lint:fix": "eslint --ext .ts src --fix", "prettier": "prettier --write .", - "test": "cross-env TS_NODE_PROJECT='./tsconfig.spec.json' nyc mocha --exit" + "test": "cross-env TS_NODE_PROJECT='./tsconfig.spec.json' nyc mocha --grep should --exit" }, "keywords": [ "Bosch Smart Home", diff --git a/test/bosch-smart-home-bridge.e2e.ts b/test/bosch-smart-home-bridge.e2e.ts new file mode 100644 index 0000000..27211b6 --- /dev/null +++ b/test/bosch-smart-home-bridge.e2e.ts @@ -0,0 +1,41 @@ +import { BoschSmartHomeBridge, BoschSmartHomeBridgeBuilder, BshbUtils } from "../src"; +import { expect } from "chai"; +import { DefaultTestLogger } from "./bshc-mock"; + +const host: string = process.env.BSHC_HOST!; +const identifier: string = process.env.BSHC_IDENTIFIER!; +const password: string = process.env.BSHC_PWD!; +const clientCert: string = "-----BEGIN CERTIFICATE-----\n" + process.env.BSHC_CERT! + "\n-----END CERTIFICATE-----"; +const clientPrivateKey: string = + "-----BEGIN RSA PRIVATE KEY-----\n" + process.env.BSHC_PRIV! + "\n-----END RSA PRIVATE KEY-----"; + +describe("BshbUtils", () => { + let bshb: BoschSmartHomeBridge; + before(() => { + const certResult = BshbUtils.generateClientCertificate(); + bshb = BoschSmartHomeBridgeBuilder.builder() + .withHost(host) + .withClientCert(clientCert) + .withClientPrivateKey(clientPrivateKey) + .withIgnoreCertificateCheck(true) + .withLogger(new DefaultTestLogger()) + .build(); + }); + + it("e2e get rooms", (done) => { + let response: any; + bshb + .getBshcClient() + .getRooms() + .subscribe({ + next: (value) => (response = value), + error: (error) => { + expect.fail(error, "Expected that rooms returns a result"); + }, + complete: () => { + expect(response).to.be.not.null; + done(); + }, + }); + }); +}); diff --git a/test/bosch-smart-home-bridge.spec.ts b/test/bosch-smart-home-bridge.spec.ts index 9435357..1c52105 100644 --- a/test/bosch-smart-home-bridge.spec.ts +++ b/test/bosch-smart-home-bridge.spec.ts @@ -23,7 +23,7 @@ describe("BoschSmartHomeBridge", () => { bshcAdmin = resetBshcAdminRouter(); }); - it("test not paired", (done) => { + it("should not be paired yet, and button is not pressed", (done) => { bshc.get("/smarthome/rooms", (req, res) => { res.statusCode = 401; res.json({}); @@ -35,8 +35,7 @@ describe("BoschSmartHomeBridge", () => { const identifier = BshbUtils.generateIdentifier(); - let response: any; - bshb.pairIfNeeded("test", identifier, "test", 1000, 1).subscribe({ + bshb.pairIfNeeded("test", identifier, "test", 1000, 0).subscribe({ next: (value) => expect.fail("Expected not connected"), error: (error) => { expect(error).not.to.be.null; @@ -48,7 +47,36 @@ describe("BoschSmartHomeBridge", () => { }); }); - it("test already pairing", (done) => { + it("should not be paired yet, and button is pressed", (done) => { + bshc.get("/smarthome/rooms", (req, res) => { + res.statusCode = 401; + res.json({}); + }); + bshcAdmin.post("/smarthome/clients", (req, res) => { + res.json({ + url: "http://localhost:8884", + token: "someToken", + }); + }); + + const identifier = BshbUtils.generateIdentifier(); + + let response: any; + bshb.pairIfNeeded("test", identifier, "test", 1000, 0).subscribe({ + next: (value) => (response = value), + error: (error) => { + expect.fail(error, "Expected that pairing is successful"); + }, + complete: () => { + expect(response).to.be.not.null; + expect(response.url).to.be.not.null; + expect(response.token).to.be.not.null; + done(); + }, + }); + }); + + it("should already be paired", (done) => { bshc.get("/smarthome/rooms", (req, res) => { res.json([ { @@ -63,10 +91,10 @@ describe("BoschSmartHomeBridge", () => { const identifier = BshbUtils.generateIdentifier(); let response: any; - bshb.pairIfNeeded("test", identifier, "test", 1000, 1).subscribe({ + bshb.pairIfNeeded("test", identifier, "test", 1000, 0).subscribe({ next: (value) => (response = value), error: (error) => { - expect.fail("Expected that rooms returns a result"); + expect.fail(error, "Expected that rooms returns a result"); }, complete: () => { expect(response).to.be.not.null; diff --git a/test/bshb-utils.spec.ts b/test/bshb-utils.spec.ts index 4f87372..e170365 100644 --- a/test/bshb-utils.spec.ts +++ b/test/bshb-utils.spec.ts @@ -1,15 +1,15 @@ -import { BshbUtils } from "../src/bshb-utils"; +import { BshbUtils } from "../src"; import { expect } from "chai"; describe("BshbUtils", () => { - it("generate identifier", () => { + it("should generate identifier", () => { const identifier = BshbUtils.generateIdentifier(); expect(identifier).to.not.be.null; expect(identifier.length).to.be.greaterThan(0); }); - it("generate client certificate", () => { + it("should generate client certificate", () => { const result = BshbUtils.generateClientCertificate(); expect(result).to.not.be.null;