Skip to content

Commit

Permalink
feat: add socket launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewPattell committed Mar 7, 2023
1 parent df70bc1 commit 16d796e
Show file tree
Hide file tree
Showing 5 changed files with 584 additions and 76 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'no-await-in-loop': 'off',
'unicorn/no-nested-ternary': 'off',
'prettier/prettier': [
'error',
{
Expand Down
37 changes: 28 additions & 9 deletions __tests__/helpers/launchers-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gateway, Microservice } from '@lomray/microservice-nodejs-lib';
import { Gateway, Microservice, Socket } from '@lomray/microservice-nodejs-lib';
import type { IMiddlewareRepository } from '@lomray/microservice-remote-middleware';
import {
RemoteMiddlewareClient,
Expand All @@ -8,20 +8,15 @@ import { expect } from 'chai';
import rewiremock from 'rewiremock';
import sinon from 'sinon';
import type { ConnectionOptions } from 'typeorm';
import type {
start as OriginalStart,
startWithDb as OriginalStartWithDb,
run as OriginalRun,
} from '@helpers/launchers';
import type { start as OriginalStart, run as OriginalRun } from '@helpers/launchers';
import { TypeormMock } from '@mocks/index';
import Jobs from '@services/jobs';
import Log from '@services/log';
import RemoteConfig from '@services/remote-config';
import waitResult from '@test-helpers/wait-result';

const CreateDbConnection = sinon.stub().resolves();
const { start, startWithDb, run } = rewiremock.proxy<{
startWithDb: typeof OriginalStartWithDb;
const { start, run } = rewiremock.proxy<{
start: typeof OriginalStart;
run: typeof OriginalRun;
}>(() => require('@helpers/launchers'), {
Expand Down Expand Up @@ -69,7 +64,7 @@ describe('helpers/launchers', () => {
return rmMiddleware;
});

await startWithDb({
await run({
type: 'microservice',
msOptions,
msParams,
Expand Down Expand Up @@ -247,4 +242,28 @@ describe('helpers/launchers', () => {

expect(CreateDbConnection).to.calledOnce;
});

it('should correctly run microservice with socket', async () => {
const spyCreate = sandbox.spy(Socket, 'create');
const registerRoomsStub = sandbox.stub();
let stubbedStart;

await run({
type: 'socket',
msOptions,
msParams,
registerRooms: registerRoomsStub,
remoteMiddleware: { isEnable: false, type: 'client' },
remoteConfig: { isDisable: true },
hooks: {
afterCreateMicroservice: (microservice) => {
stubbedStart = sandbox.stub(microservice, 'start').resolves();
},
},
});

expect(stubbedStart).to.calledOnce;
expect(spyCreate).to.calledOnce;
expect(registerRoomsStub).to.calledOnceWith(Socket.getInstance());
});
});
Loading

0 comments on commit 16d796e

Please sign in to comment.