Best JavaScript code snippet using tracetest
queue-router-test.js
Source:queue-router-test.js
1var _ = require('lodash');2var test = require('../test');3var QueueRouter = require(process.cwd() + '/services/queue-router');4describe('QueueRouter',function() {5 6 var mockdgram = null;7 var mockRoute = require(process.cwd() + '/test-server/mocks/route-test');8 var helpers = require(process.cwd() + '/lib/hash-helpers');9 var hashkeys = require(process.cwd() + '/lib/config-hashkeys');10 var testGateway = Object.freeze(helpers.hash2config({'gateway:imei': '123456789012345'},hashkeys.gateway));11 beforeEach(function () {12 test.mockery.enable();13 test.mockery.registerMock('dgram',mockdgram = new test.mockdgram());14 test.mockery.registerMock('then-redis', test.mockredis);15 test.mockery.warnOnUnregistered(false);16 test.mockredis.reset();17 mockRoute.reset();18 });19 afterEach(function () {20 test.mockery.deregisterMock('then-redis');21 test.mockery.deregisterMock('dgram');22 test.mockery.disable();23 test.mockredis.snapshot().should.eql([]);24 test.pp.snapshot().should.eql([]);25 mockRoute.snapshot().should.eql([]);26 });27 it('should properly initialize data with minimal arguments',function(){28 var router = new QueueRouter();29 router.config.should.eql({idleReport: 12,maxRetries: 168,maxTicks: 720,timeoutInterval: 5});30 router.routes.should.eql({});31 router.setQueueArgs();32 router.transmitArgs.should.eql(['m2m-ack:queue','m2m-command:queue','m2m-transmit:queue',5]);33 test.pp.snapshot().should.eql([]);34 test.mockredis.snapshot().should.eql([]);35 });36 it('should properly initialize data with all arguments',function(){37 var router = new QueueRouter({idleReport: 10,maxRetries: 2,maxTicks: 16,timeoutInterval: 1});38 router.addRoute(1,mockRoute);39 router.config.should.eql({idleReport: 10,maxRetries: 2,maxTicks: 16,timeoutInterval: 1});40 router.queues.should.eql({1: mockRoute.queueKey});41 router.routes.should.eql({testQueue: mockRoute});42 router.setQueueArgs();43 router.transmitArgs.should.eql(['m2m-ack:queue','m2m-command:queue','m2m-transmit:queue','testQueue',1]);44 test.pp.snapshot().should.eql([45 '[router ] add route(testQueue): 1'46 ]);47 test.mockredis.snapshot().should.eql([]);48 });49 it('should detect an unexpected unsolicited message',function(){50 var router = new QueueRouter();51 router.listener.client.events.message('test',{address: 'localhost',port:1234});52 test.mockredis.snapshot().should.eql([]);53 test.pp.snapshot().should.eql([54 '[router ] incoming - size: 4 from: localhost:1234',55 '[router ] unexpected response: "test"'56 ]);57 });58 it('should throw an error if start called twice',function(done){59 var router = new QueueRouter();60 router.start(testGateway);61 test.expect(function(){ router.start(testGateway); }).to.throw('already started');62 router.stop();63 test.pp.snapshot().should.eql([64 '[router ] start watching',65 '[router ] stop watching'66 ]);67 test.mockredis.snapshot().should.eql([68 {quit: null}69 ]);70 test.pp.snapshot().should.eql([]);71 done();72 });73 it('should throw an error if stopped before started',function(done){74 var router = new QueueRouter();75 test.expect(function(){ router.stop(); }).to.throw('not started');76 test.mockredis.snapshot().should.eql([]);77 test.pp.snapshot().should.eql([]);78 done();79 });80 it('should log an idle message if nothing in the queues',function(done){81 var events = [];82 var router = new QueueRouter().on('note',function(event){83 events.push(event);84 if (events.length >= 12) {85 router.stop();86 events.should.eql(['idle','idle','idle','idle','idle','idle','idle','idle','idle','idle','idle','idle']);87 test.mockredis.snapshot().should.eql([88 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},89 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},90 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},91 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},92 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},93 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},94 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},95 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},96 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},97 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},98 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},99 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},100 {quit: null}101 ]);102 test.pp.snapshot().should.eql([103 '[router ] start watching',104 '[router ] idle: 12',105 '[router ] stop watching'106 ]);107 done();108 }109 }).start(testGateway);110 });111 it('should ignore an unexpected ack',function(done){112 test.mockredis.lookup.brpop = [['m2m-ack:queue','1']];113 var router = new QueueRouter().on('note',function(event){114 router.stop();115 event.should.eql('ignoreAck');116 test.mockredis.snapshot().should.eql([117 {mget: QueueRouter.ACK_STATE_KEYS},118 {brpop: router.transmitArgs},119 {quit: null}120 ]);121 test.pp.snapshot().should.eql([122 '[router ] start watching',123 '[router ] ignoring ack: 1',124 '[router ] stop watching'125 ]);126 done();127 }).start(testGateway);128 });129 it('should detect an invalid message',function(done){130 test.mockredis.lookup.brpop = [['m2m-transmit:queue','{...']];131 var count = 0;132 var router = new QueueRouter().on('note',function(event){133 event.should.eql('error');134 if (count++ <= 0) return;135 router.stop();136 test.mockredis.snapshot().should.eql([137 {mget: QueueRouter.ACK_STATE_KEYS},138 {brpop: router.transmitArgs},139 {quit: null}140 ]);141 test.pp.snapshot().should.eql([142 '[router ] start watching',143 '[router ] json error: SyntaxError: Unexpected token .',144 '[router ] invalid message received: {...',145 '[router ] stop watching'146 ]);147 done();148 }).start(testGateway);149 });150 it('should transmit a basic message providing sequenceNumber',function(done){151 test.mockredis.lookup.brpop = [['m2m-transmit:queue','{"routeKey":"testQueue","eventCode":10,"timestamp":0,"sequenceNumber":1,"11":12,"13":"string","14":null,"15":"\\u0001"}']];152 var router = new QueueRouter().on('note',function(event){153 router.stop();154 event.should.eql('transmit');155 var redisSnapshot = test.mockredis.snapshot();156 var ppSnapshot = test.pp.snapshot();157 if (process.version > 'v0.12.') { // NOTE - v0.10 (used on Travis-CI) encodes buffer objects differently, making string matching difficult...158 redisSnapshot.should.eql([159 {mget: QueueRouter.ACK_STATE_KEYS},160 {brpop: router.transmitArgs},161 {mset: [162 'm2m-ack:message','{"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":10,"sequenceNumber":1,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"},{"type":1,"id":11,"value":12},{"type":2,"id":13,"value":"string"},{"type":11,"id":15,"value":{"type":"Buffer","data":[1]}}]}',163 'm2m-ack:route-key','testQueue',164 'm2m-ack:retries',0,165 'm2m-ack:ticks',0,166 'm2m-ack:sequence-number',1167 ]},168 {quit: null}169 ]);170 ppSnapshot.should.eql([171 '[router ] start watching',172 '[router ] valid message received: {"routeKey":"testQueue","eventCode":10,"timestamp":0,"sequenceNumber":1,"11":12,"13":"string","14":null,"15":"\\u0001"}',173 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":10,"sequenceNumber":1,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"},{"type":1,"id":11,"value":12},{"type":2,"id":13,"value":"string"},{"type":11,"id":15,"value":{"type":"Buffer","data":[1]}}]}',174 "[router ] outgoing - size: 54 to: localhost:4001",175 '[router ] stop watching'176 ]);177 }178 done();179 }).start(testGateway);180 });181 it('should transmit a basic message without a sequenceNumber or timestamp (and HACK an undefined attribute for code coverage)',function(done){182 test.timekeeper.freeze(1000000000000);183 test.mockredis.lookup.brpop = [['m2m-transmit:queue','{"routeKey":"testQueue","hack":1}']];184 test.mockredis.lookup.get['m2m-transmit:last-sequence-number'] = 1;185 var router = new QueueRouter().on('note',function(event){186 router.stop();187 event.should.eql('transmit');188 test.mockredis.snapshot().should.eql([189 {mget: QueueRouter.ACK_STATE_KEYS},190 {brpop: router.transmitArgs},191 {incr: 'm2m-transmit:last-sequence-number'},192 {mset: [193 'm2m-ack:message','{"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":1000000000000,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',194 'm2m-ack:route-key','testQueue',195 'm2m-ack:retries',0,196 'm2m-ack:ticks',0,197 'm2m-ack:sequence-number',2198 ]},199 {quit: null}200 ]);201 test.pp.snapshot().should.eql([202 '[router ] start watching',203 '[router ] valid message received: {"routeKey":"testQueue","hack":1}',204 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":1000000000000,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',205 "[router ] outgoing - size: 34 to: localhost:4001",206 '[router ] stop watching'207 ]);208 test.timekeeper.reset();209 done();210 }).start(testGateway);211 });212 it('should retry several times and then discard a message that is not acked where primary is private',function(done){213 test.mockredis.lookup.get['m2m-ack:message'] = '{"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}';214 test.mockredis.lookup.get['m2m-ack:sequence-number'] = '2';215 test.mockredis.lookup.get['m2m-ack:route-key'] = 'testQueue';216 test.mockredis.lookup.get['m2m-transmit:retries'] = '0';217 var events = [];218 var router = new QueueRouter({maxRetries: 5,maxTicks: -1})219 .on('note',function(event){220 events.push(event);221 if (event === 'error') {222 router.stop();223 test.mockredis.snapshot().should.eql([224 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},225 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},226 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},227 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},228 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},229 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{del: QueueRouter.ACK_STATE_KEYS},230 {quit: null}231 ]);232 test.pp.snapshot().should.eql([233 '[router ] add route(testQueue): 1',234 '[router ] start watching',235 '[router ] retry: 2',236 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',237 "[router ] outgoing - size: 34 to: localhost:4001",238 '[router ] retry: 2',239 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',240 "[router ] outgoing - size: 34 to: localhost:4000",241 '[router ] retry: 2',242 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',243 "[router ] outgoing - size: 34 to: localhost:4001",244 '[router ] retry: 2',245 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',246 "[router ] outgoing - size: 34 to: localhost:4000",247 '[router ] retry: 2',248 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',249 "[router ] outgoing - size: 34 to: localhost:4001",250 '[router ] too many retries: 2',251 '[test-route] error: 2',252 '[router ] stop watching'253 ]);254 mockRoute.snapshot().should.eql([{error: 2}]);255 done();256 }257 })258 .addRoute(1,mockRoute)259 .start(testGateway);260 });261 it('should retry several times and then discard a message that is not acked where primary is public',function(done){262 test.mockredis.lookup.get['m2m-ack:message'] = '{"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}';263 test.mockredis.lookup.get['m2m-ack:sequence-number'] = '2';264 test.mockredis.lookup.get['m2m-ack:route-key'] = 'testQueue';265 test.mockredis.lookup.get['m2m-transmit:retries'] = '0';266 var events = [];267 var router = new QueueRouter({idleReport: 1,maxRetries: 3,maxTicks: 2})268 .on('note',function(event){269 events.push(event);270 if (event === 'error') {271 router.stop();272 test.mockredis.snapshot().should.eql([273 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},274 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{incr: 'm2m-ack:ticks'},275 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},276 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{incr: 'm2m-ack:ticks'},277 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{incr: 'm2m-ack:ticks'},278 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{set: ['m2m-ack:ticks',0]},{incr: 'm2m-ack:retries'},279 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{del: QueueRouter.ACK_STATE_KEYS},280 {quit: null}281 ]);282 test.pp.snapshot().should.eql([283 '[router ] add route(testQueue): 1',284 '[router ] start watching',285 '[router ] retry: 2',286 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',287 "[router ] outgoing - size: 34 to: localhost:4000",288 '[router ] retry: 2',289 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',290 "[router ] outgoing - size: 34 to: localhost:4001",291 '[router ] backoff: 1',292 '[router ] retry: 2',293 '[router ] transmit: {"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',294 "[router ] outgoing - size: 34 to: localhost:4000",295 '[router ] too many retries: 2',296 '[test-route] error: 2',297 '[router ] stop watching'298 ]);299 mockRoute.snapshot().should.eql([{error: 2}]);300 done();301 }302 })303 .addRoute(1,mockRoute)304 .start(_.defaults({primary: 'private'},testGateway));305 });306 it('should handle an ack of an expected message',function(done){307 test.mockredis.lookup.brpop = [['m2m-ack:queue','2']];308 test.mockredis.lookup.get['m2m-ack:message'] = '{"messageType":170,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}';309 test.mockredis.lookup.get['m2m-ack:route-key'] = 'testQueue';310 test.mockredis.lookup.get['m2m-ack:sequence-number'] = '2';311 test.mockredis.lookup.get['m2m-transmit:retries'] = '0';312 var events = [];313 var router = new QueueRouter()314 .on('note',function(event){315 events.push(event);316 if (event === 'ack') {317 router.stop();318 test.mockredis.snapshot().should.eql([319 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.ackArgs},{del: QueueRouter.ACK_STATE_KEYS},320 {quit: null}321 ]);322 test.pp.snapshot().should.eql([323 '[router ] add route(testQueue): 1',324 '[router ] start watching',325 '[router ] acked: 2',326 '[test-route] ack: 2',327 '[router ] stop watching'328 ]);329 mockRoute.snapshot().should.eql([{ack: 2}]);330 done();331 }332 })333 .addRoute(1,mockRoute)334 .start(testGateway);335 });336 it('should handle an routed command and block until it is finished',function(done){337 test.mockredis.lookup.brpop = [null,['testQueue','"test command"']];338 var counter = 0;339 mockRoute.busyState.should.not.be.ok;340 var router = new QueueRouter()341 .on('note',function(){342 if (counter++ === 0) return;343 344 router.stop();345 mockRoute.busyState.should.be.ok;346 test.mockredis.snapshot().should.eql([347 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: ['m2m-ack:queue','m2m-command:queue','m2m-transmit:queue','testQueue',5]},348 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: ['m2m-ack:queue','m2m-command:queue','m2m-transmit:queue',5]},349 {quit: null}350 ]);351 test.pp.snapshot().should.eql([352 '[router ] add route(testQueue): 1',353 '[router ] start watching',354 '[router ] route(testQueue): "test command"',355 '[test-route] command: test command',356 '[router ] stop watching'357 ]);358 mockRoute.snapshot().should.eql([{command: 'test command'}]);359 done();360 })361 .addRoute(1,mockRoute)362 .start(testGateway);363 });364 it('should ignore an unexpected eventCode on the command queue',function(done){365 test.mockredis.lookup.brpop = [['m2m-command:queue','{"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}']];366 var router = new QueueRouter();367 router.on('note',function(event){368 router.stop();369 test.mockredis.snapshot().should.eql([370 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},371 {quit: null}372 ]);373 test.pp.snapshot().should.eql([374 '[router ] start watching',375 '[router ] ignoring command: {"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":0,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',376 '[router ] stop watching'377 ]);378 done();379 });380 router.start(testGateway);381 });382 it('should ignore command when no route is found',function(done){383 test.mockredis.lookup.brpop = [['m2m-command:queue','{"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":11,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}']];384 var router = new QueueRouter();385 router.on('note',function(event){386 router.stop();387 test.mockredis.snapshot().should.eql([388 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},389 {quit: null}390 ]);391 test.pp.snapshot().should.eql([392 '[router ] start watching',393 '[router ] route not found: {"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":11,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',394 '[router ] stop watching'395 ]);396 done();397 });398 router.start(testGateway);399 });400 it('should ignore command when no command is found',function(done){401 test.mockredis.lookup.brpop = [['m2m-command:queue','{"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":11,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}']];402 var router = new QueueRouter();403 router.addRoute(1,mockRoute);404 router.on('note',function(event){405 router.stop();406 test.mockredis.snapshot().should.eql([407 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},408 {quit: null}409 ]);410 test.pp.snapshot().should.eql([411 '[router ] add route(testQueue): 1',412 '[router ] start watching',413 '[router ] command not found: {"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":11,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"}]}',414 '[router ] stop watching'415 ]);416 done();417 });418 router.start(testGateway);419 });420 it('should route a command',function(done){421 test.mockredis.lookup.brpop = [['m2m-command:queue','{"messageType":204,"majorVersion":1,"minorVersion":0,"eventCode":11,"sequenceNumber":2,"timestamp":0,"tuples":[{"type":2,"id":0,"value":"123456789012345"},{"type":2,"id":10,"value":"test command"}]}']];422 var router = new QueueRouter();423 router.addRoute(1,mockRoute);424 router.on('note',function(event){425 router.stop();426 test.mockredis.snapshot().should.eql([427 {mget: QueueRouter.ACK_STATE_KEYS},{brpop: router.transmitArgs},428 {lpush: [mockRoute.queueKey,'{"command":"test command","requestID":2}']},429 {quit: null}430 ]);431 test.pp.snapshot().should.eql([432 '[router ] add route(testQueue): 1',433 '[router ] start watching',434 '[router ] stop watching'435 ]);436 done();437 });438 router.start(testGateway);439 });440 it('should detect a client error',function(done) {441 var router = new QueueRouter();442 router.start(testGateway);443 test.mockredis.events.error('test error');444 router.stop();445 test.pp.snapshot().should.eql([446 '[router ] start watching',447 '[router ] redis client error: test error',448 '[router ] stop watching'449 ]);450 test.mockredis.snapshot().should.eql([451 {end: null}452 ]);453 done();454 });...
socket-gateway.decorator.spec.ts
Source:socket-gateway.decorator.spec.ts
1import 'reflect-metadata';2import { expect } from 'chai';3import { WebSocketGateway } from '../../utils/socket-gateway.decorator';4describe('@WebSocketGateway', () => {5 @WebSocketGateway({ port: 80, namespace: '/' })6 class TestGateway {}7 it('should decorate transport with expected metadata', () => {8 const isGateway = Reflect.getMetadata('__isGateway', TestGateway);9 const port = Reflect.getMetadata('port', TestGateway);10 const namespace = Reflect.getMetadata('namespace', TestGateway);11 expect(isGateway).to.be.eql(true);12 expect(port).to.be.eql(80);13 expect(namespace).to.be.eql('/');14 });...
subscribe-message.decorator.spec.ts
Source:subscribe-message.decorator.spec.ts
1import 'reflect-metadata';2import { expect } from 'chai';3import { SubscribeMessage } from '../../utils/subscribe-message.decorator';4describe('@SubscribeMessage', () => {5 class TestGateway {6 @SubscribeMessage({ value: 'filter' })7 static fn() {}8 }9 it('should decorate transport with expected metadata', () => {10 const isMessageMapping = Reflect.getMetadata(11 '__isMessageMapping',12 TestGateway.fn,13 );14 const message = Reflect.getMetadata('message', TestGateway.fn);15 expect(isMessageMapping).to.be.true;16 expect(message).to.be.eql('filter');17 });...
Using AI Code Generation
1const tracetesting = require('tracetesting');2const TestGateway = tracetesting.TestGateway;3const tracetesting = require('tracetesting');4const TestGateway = tracetesting.TestGateway;5const tracetesting = require('tracetesting');6const TestGateway = tracetesting.TestGateway;7const tracetesting = require('tracetesting');8const TestGateway = tracetesting.TestGateway;9const tracetesting = require('tracetesting');10const TestGateway = tracetesting.TestGateway;11const tracetesting = require('tracetesting');12const TestGateway = tracetesting.TestGateway;13const tracetesting = require('tracetesting');14const TestGateway = tracetesting.TestGateway;15const tracetesting = require('tracetesting');16const TestGateway = tracetesting.TestGateway;17const tracetesting = require('tracetesting');18const TestGateway = tracetesting.TestGateway;19const tracetesting = require('tracetesting');20const TestGateway = tracetesting.TestGateway;21const tracetesting = require('tracetesting');22const TestGateway = tracetesting.TestGateway;23const tracetesting = require('tracetesting');24const TestGateway = tracetesting.TestGateway;25const tracetesting = require('tracetesting');26const TestGateway = tracetesting.TestGateway;27const tracetesting = require('tracetesting');
Using AI Code Generation
1var tracetest = require('tracetest');2tracetest.TestGateway();3var tracetest = {};4tracetest.TestGateway = function() {5 console.log('test');6};7module.exports = tracetest;
Using AI Code Generation
1var tracetest = require('tracetest');2var test = new tracetest.TestGateway();3test.TestGateway();4var tracetest = require('tracetest');5exports.TestGateway = tracetest.TestGateway;6var tracetest = require('tracetest');7exports.TestGateway = tracetest.TestGateway;8var tracetest = require('tracetest');9exports.TestGateway = tracetest.TestGateway;10var tracetest = require('tracetest');11exports.TestGateway = tracetest.TestGateway;12var tracetest = require('tracetest');13exports.TestGateway = tracetest.TestGateway;14var tracetest = require('tracetest');15exports.TestGateway = tracetest.TestGateway;16var tracetest = require('tracetest');17exports.TestGateway = tracetest.TestGateway;18var tracetest = require('tracetest');19exports.TestGateway = tracetest.TestGateway;20var tracetest = require('tracetest');21exports.TestGateway = tracetest.TestGateway;22var tracetest = require('tracetest');23exports.TestGateway = tracetest.TestGateway;24var tracetest = require('tracetest');
Using AI Code Generation
1var tracetest = require('./tracetest.js');2var test = new tracetest.TestGateway();3test.TestGateway();4var TestGateway = function() {5};6TestGateway.prototype.TestGateway = function() {7};8module.exports.TestGateway = TestGateway;
Using AI Code Generation
1var tracetesting = require('tracetesting');2tracetesting.TestGateway('test');3var tracetesting = {4 TestGateway: function (test) {5 }6};7module.exports = tracetesting;
Using AI Code Generation
1var tracetest = require('tracetest');2var testGateway = tracetest.TestGateway();3testGateway.TestMethod(123, function(err, result){4 console.log(result);5});6var tracetest = require('tracetest');7var TestGateway = function(){8 return {9 TestMethod: function(id, callback){10 tracetest.TestMethod(id, callback);11 }12 }13}14module.exports = {15}16module.exports = {17 TestMethod: function(id, callback){18 callback(null, id);19 }20}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!