|
| 1 | +/* |
| 2 | +Copyright 2019 Javier Brea |
| 3 | +Copyright 2019 XbyOrange |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at |
| 6 | +
|
| 7 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
| 10 | +*/ |
| 11 | + |
| 12 | +const express = require("express"); |
| 13 | +const sinon = require("sinon"); |
| 14 | + |
| 15 | +const LibMocks = require("../Libs.mocks"); |
| 16 | +const CoreMocks = require("../Core.mocks"); |
| 17 | + |
| 18 | +const About = require("../../../src/About"); |
| 19 | +const { version } = require("../../../package.json"); |
| 20 | + |
| 21 | +describe("About", () => { |
| 22 | + let sandbox; |
| 23 | + let libMocks; |
| 24 | + let coreMock; |
| 25 | + let coreInstance; |
| 26 | + let resMock; |
| 27 | + let about; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + sandbox = sinon.createSandbox(); |
| 31 | + resMock = { |
| 32 | + status: sandbox.stub(), |
| 33 | + send: sandbox.stub() |
| 34 | + }; |
| 35 | + libMocks = new LibMocks(); |
| 36 | + coreMock = new CoreMocks(); |
| 37 | + coreInstance = coreMock.stubs.instance; |
| 38 | + about = new About(coreInstance); |
| 39 | + expect.assertions(1); |
| 40 | + }); |
| 41 | + |
| 42 | + afterEach(() => { |
| 43 | + sandbox.restore(); |
| 44 | + libMocks.restore(); |
| 45 | + coreMock.restore(); |
| 46 | + }); |
| 47 | + |
| 48 | + describe("when created", () => { |
| 49 | + it("should create an express Router", async () => { |
| 50 | + expect(express.Router.calledOnce).toEqual(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should have added get router at /", async () => { |
| 54 | + expect(libMocks.stubs.express.get.getCall(0).args[0]).toEqual("/"); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe("getAbout router", () => { |
| 59 | + it("should return current package version", () => { |
| 60 | + about.getAbout({}, resMock); |
| 61 | + expect(resMock.send.getCall(0).args[0]).toEqual({ |
| 62 | + version |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe("router getter", () => { |
| 68 | + it("should return express created router", async () => { |
| 69 | + expect(about.router).toEqual(libMocks.stubs.express); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments