github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/clients/app2app-test.ts (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // 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 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import * as sinon from "sinon"; 16 import io from 'socket.io-client'; 17 import { StubbedInstance, stubInterface } from "ts-sinon"; 18 import * as app2app from '../../../clients/app2app'; 19 20 export const testApp2App = async () => { 21 22 describe('App2App', () => { 23 24 let mocksSocketIo: StubbedInstance<SocketIOClient.Socket>; 25 let callbacks: {[f: string]: Function}; 26 27 before(() => { 28 callbacks = {}; 29 mocksSocketIo = stubInterface<SocketIOClient.Socket>(); 30 mocksSocketIo.on.callsFake((event, fn) => { 31 callbacks[event] = fn; 32 return mocksSocketIo; 33 }); 34 sinon.stub(io, 'connect').returns(mocksSocketIo); 35 }); 36 37 after(() => { 38 (io.connect as sinon.SinonStub).restore(); 39 }) 40 41 beforeEach(() => { 42 callbacks = {}; 43 app2app.reset(); 44 }); 45 46 describe('establishSocketIOConnection', () => { 47 48 it('subscribes after connect', async () => { 49 sinon.assert.notCalled(mocksSocketIo.emit); 50 callbacks['connect'](); 51 sinon.assert.calledWith(mocksSocketIo.emit, 'subscribe'); 52 }); 53 54 it('logs connect_error', async () => { 55 callbacks['connect_error'](new Error('pop')); 56 }); 57 58 it('logs error', async () => { 59 callbacks['error'](new Error('pop')); 60 }); 61 62 it('logs exception', async () => { 63 callbacks['exception'](new Error('pop'), {batch: 'test'}); 64 }); 65 66 }); 67 68 }); 69 };