|
| 1 | + |
| 2 | +import 'reflect-metadata'; |
| 3 | +import WebAppService from "./WebAppService"; |
| 4 | +import TYPES from "../../common/constant/Types"; |
| 5 | +import { Container, decorate, injectable } from "inversify"; |
| 6 | + |
| 7 | +describe('WebAppService', ()=>{ |
| 8 | + let appService : WebAppService; |
| 9 | + let container: Container | null; |
| 10 | + |
| 11 | + const notificationMock = jest.fn(); |
| 12 | + const subscriberMock = jest.fn(); |
| 13 | + const registerMock = jest.fn(); |
| 14 | + const listenMock = jest.fn(); |
| 15 | + |
| 16 | + class NotificationMock{ |
| 17 | + notify = notificationMock |
| 18 | + listen = listenMock |
| 19 | + } |
| 20 | + class SubscriberMock{ |
| 21 | + registerNotifier = registerMock |
| 22 | + subscribe = subscriberMock |
| 23 | + } |
| 24 | + |
| 25 | + decorate(injectable(), NotificationMock); |
| 26 | + decorate(injectable(), SubscriberMock); |
| 27 | + |
| 28 | + beforeEach(()=>{ |
| 29 | + container = new Container(); |
| 30 | + container.bind(TYPES.INotificationService).to(NotificationMock); |
| 31 | + container.bind(TYPES.ISubscriber).to(SubscriberMock); |
| 32 | + container.bind<WebAppService>(TYPES.WebAppService).to(WebAppService); |
| 33 | + appService = container.get<WebAppService>(TYPES.WebAppService); |
| 34 | + }); |
| 35 | + |
| 36 | + describe('startSubscribe', ()=>{ |
| 37 | + test('subscriber should be called', async ()=>{ |
| 38 | + appService.startSubscribe(); |
| 39 | + expect(registerMock.mock.calls.length).toBe(1); |
| 40 | + expect(subscriberMock.mock.calls.length).toBe(1); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('getNotificationService', ()=>{ |
| 45 | + test('return notification service', async ()=>{ |
| 46 | + let notifier = appService.getNotificationService(); |
| 47 | + expect(notifier.listen).toEqual(listenMock); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('get', ()=>{ |
| 52 | + test('port should be 5000', async ()=>{ |
| 53 | + expect(appService.get("port")).toEqual(5000); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('getApp', ()=>{ |
| 58 | + test('should throw no error', async ()=>{ |
| 59 | + expect(()=>{ |
| 60 | + appService.getApp(); |
| 61 | + }).not.toThrowError(); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + |
| 66 | + afterEach(() => { |
| 67 | + container = null; |
| 68 | + }); |
| 69 | + |
| 70 | +}); |
0 commit comments