Best JavaScript code snippet using storybook-root
testPvp.js
Source:testPvp.js
...296 callbackFn();297 };298 let callbackFn = () => {299 if(pairAllocatedProgress && pairDead){300 pvp_01.removeAllListeners('progress');301 pvp_01.removeAllListeners('error');302 pvp_01.removeAllListeners('direct-message');303 pvp_01.removeAllListeners('finish');304 pvp_01.removeAllListeners('model');305 pvp_01.removeAllListeners('sync');306 pvp_01.removeAllListeners('turn-message');307 pvp_01.removeAllListeners('paused');308 pvp_01.removeAllListeners('unpaused');309 done();310 }311 };312 pvp_01.on('progress', callbackFn_Progress);313 pvp_01.on('begin', () => done(new Error('WTF 1')));314 pvp_01.on('error', err => done(err));315 pvp_01.on('direct-message', () => done(new Error('WTF 2')));316 pvp_01.on('finish', callbackFn_Finish);317 pvp_01.on('model', () => done(new Error('WTF 3')));318 pvp_01.on('sync', () => done(new Error('WTF 4')));319 pvp_01.on('turn-message', () => done(new Error('WTF 5')));320 pvp_01.on('paused', () => done(new Error('WTF 6')));321 pvp_01.on('unpaused', () => done(new Error('WTF 7')));322 pvp_01.doConnect({ payload: '01' });323 });324 it('Second should close client-side', done => {325 let callbackFn = response => {326 expect(response.ok).to.be.equal(true);327 expect(response.details.endMessage).to.be.equal('Forced to close client-side');328 done();329 };330 pvp_02.on('finish', callbackFn);331 pvp_02.forceDestroyClient();332 });333 });334 describe('Get pvp done normally', () => {335 it('First should call dropMatchmaking', done => {336 let callbackFn = (err, response) => {337 expect(err).to.be.a('null');338 expect(response).to.be.an.instanceof(GbaseResponse);339 expect(response.ok).to.be.equal(true);340 expect(response.details.originalResponse).to.have.property('forReal');341 done();342 };343 gbaseApiStdl_01.pvp.dropMatchmaking(callbackFn);344 });345 it('Second should call dropMatchmaking', done => {346 let callbackFn = (err, response) => {347 expect(err).to.be.a('null');348 expect(response).to.be.an.instanceof(GbaseResponse);349 expect(response.ok).to.be.equal(true);350 expect(response.details.originalResponse).to.have.property('forReal');351 done();352 };353 gbaseApiStdl_02.pvp.dropMatchmaking(callbackFn);354 });355 it('The first should pull checkBattleNoSearch', done => {356 let callbackFn = (err, response) => {357 expect(err).to.be.a('null');358 expect(response).to.be.an.instanceof(GbaseResponse);359 expect(response.ok).to.be.equal(true);360 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');361 done();362 };363 gbaseApiStdl_01.pvp.checkBattleNoSearch(callbackFn);364 });365 it('The second should pull checkBattleNoSearch', done => {366 let callbackFn = (err, response) => {367 expect(err).to.be.a('null');368 expect(response).to.be.an.instanceof(GbaseResponse);369 expect(response.ok).to.be.equal(true);370 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');371 done();372 };373 gbaseApiStdl_02.pvp.checkBattleNoSearch(callbackFn);374 });375 var pvp_01, pvp_02;376 it('Both should find each other in pvp matchmaking', done => {377 let callbackFn_final = () => {378 if(pvp_01 && pvp_02){379 done();380 }381 };382 let callbackFn_01 = (err, response) => {383 expect(err).to.be.a('null');384 expect(response).to.be.an.instanceof(GbaseResponse);385 expect(response.ok).to.be.equal(true);386 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');387 pvp_01 = response.details.pvp;388 callbackFn_final();389 };390 let callbackFn_02 = (err, response) => {391 expect(err).to.be.a('null');392 expect(response).to.be.an.instanceof(GbaseResponse);393 expect(response.ok).to.be.equal(true);394 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');395 pvp_02 = response.details.pvp;396 callbackFn_final();397 };398 gbaseApiStdl_01.pvp.withOpponent(399 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,400 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),401 60, callbackFn_01402 );403 gbaseApiStdl_02.pvp.withOpponent(404 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,405 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),406 60, callbackFn_02407 );408 });409 it('Both should receive progress messages', done => {410 var begin_01 = false, begin_02 = false,411 shouldBeModel_01 = false, shouldBeModel_02 = false,412 beenModel_01 = false, beenModel_02 = false;413 let callbackFn_Progress = (i, msg) => {414 expect(EXPECTED_PROGRESS).to.include(msg);415 };416 let callbackFn_Begin = (i, msg) => {417 if(msg){418 expect(msg).to.be.equal(EXPECTED_BEGIN_MESSAGE);419 } else if(i === 0){420 shouldBeModel_01 = true;421 } else {422 shouldBeModel_02 = true;423 }424 if(i === 0){425 expect(pvp_01).to.have.property('myPing');426 expect(pvp_01).to.have.property('opponentPing');427 expect(pvp_01).to.have.property('isPaused', false);428 try{429 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload b' });430 } catch(__){431 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload a' });432 }433 expect(pvp_01).to.have.property('startTimestamp');434 expect(pvp_01).to.have.property('randomSeed');435 expect(pvp_01).to.have.property('meIsPlayerA');436 begin_01 = true;437 return callbackFn();438 } else if(i === 1){439 expect(pvp_02).to.have.property('myPing');440 expect(pvp_02).to.have.property('opponentPing');441 expect(pvp_02).to.have.property('isPaused', false);442 try{443 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload a' });444 } catch(__){445 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload b' });446 }447 expect(pvp_02).to.have.property('startTimestamp');448 expect(pvp_02).to.have.property('randomSeed');449 expect(pvp_02).to.have.property('meIsPlayerA');450 begin_02 = true;451 return callbackFn();452 }453 done(new Error('WTF 16'));454 };455 let callbackFn_Model = (i, msg) => {456 expect(msg).to.have.property('isA');457 expect(msg).to.have.property('mdl');458 expect(msg).to.have.property('playerTurnA', 0);459 expect(msg).to.have.property('playerTurnB', 0);460 expect(msg.mdl).to.have.property('model');461 expect(msg.mdl).to.have.property('randomSeed');462 expect(msg.mdl).to.have.property('startTs');463 if(i === 0){464 expect(shouldBeModel_01).to.be.equal(true);465 expect(beenModel_01).to.be.equal(false);466 beenModel_01 = true;467 } else {468 expect(shouldBeModel_02).to.be.equal(true);469 expect(beenModel_02).to.be.equal(false);470 beenModel_02 = true;471 }472 callbackFn();473 };474 let callbackFn = () => {475 if(begin_01 && begin_02 && (((shouldBeModel_01 && beenModel_01) || (!shouldBeModel_01))) && ((shouldBeModel_02 && beenModel_02) || (!shouldBeModel_02))){476 pvp_01.removeAllListeners('progress');477 pvp_01.removeAllListeners('begin');478 pvp_01.removeAllListeners('error');479 pvp_01.removeAllListeners('direct-message');480 pvp_01.removeAllListeners('finish');481 pvp_01.removeAllListeners('model');482 pvp_01.removeAllListeners('sync');483 pvp_01.removeAllListeners('turn-message');484 pvp_01.removeAllListeners('paused');485 pvp_01.removeAllListeners('unpaused');486 pvp_02.removeAllListeners('progress');487 pvp_02.removeAllListeners('begin');488 pvp_02.removeAllListeners('error');489 pvp_02.removeAllListeners('direct-message');490 pvp_02.removeAllListeners('finish');491 pvp_02.removeAllListeners('model');492 pvp_02.removeAllListeners('sync');493 pvp_02.removeAllListeners('turn-message');494 pvp_02.removeAllListeners('paused');495 pvp_02.removeAllListeners('unpaused');496 done();497 }498 };499 pvp_01.on('progress', msg => callbackFn_Progress(0, msg));500 pvp_01.on('begin', msg => callbackFn_Begin(0, msg));501 pvp_01.on('error', err => done(err));502 pvp_01.on('direct-message', () => done(new Error('WTF 1')));503 pvp_01.on('finish', () => done(new Error('WTF 2')));504 pvp_01.on('model', msg => callbackFn_Model(0, msg));505 pvp_01.on('sync', () => done(new Error('WTF 4')));506 pvp_01.on('turn-message', () => done(new Error('WTF 5')));507 pvp_01.on('paused', () => done(new Error('WTF 6')));508 pvp_01.on('unpaused', () => done(new Error('WTF 7')));509 pvp_02.on('progress', msg => callbackFn_Progress(1, msg));510 pvp_02.on('begin', msg => callbackFn_Begin(1, msg));511 pvp_02.on('error', err => done(err));512 pvp_02.on('direct-message', () => done(new Error('WTF 8')));513 pvp_02.on('finish', () => done(new Error('WTF 9')));514 pvp_02.on('model', msg => callbackFn_Model(1, msg));515 pvp_02.on('sync', () => done(new Error('WTF 11')));516 pvp_02.on('turn-message', () => done(new Error('WTF 12')));517 pvp_02.on('paused', () => done(new Error('WTF 13')));518 pvp_02.on('unpaused', () => done(new Error('WTF 14')));519 pvp_01.doConnect({ payload: '01' });520 pvp_02.doConnect({ payload: '02' });521 });522 it(`First player should send ${HOW_MUCH_DIRECT} direct messages and the second should receive them`, done => {523 var theMessagesCounter = 0;524 let callbackFn_Message = msg => {525 msg = msg.message;526 if(theMessagesCounter === msg && msg < HOW_MUCH_DIRECT){527 if(++theMessagesCounter === HOW_MUCH_DIRECT){528 pvp_01.removeAllListeners('progress');529 pvp_01.removeAllListeners('begin');530 pvp_01.removeAllListeners('error');531 pvp_01.removeAllListeners('direct-message');532 pvp_01.removeAllListeners('finish');533 pvp_01.removeAllListeners('model');534 pvp_01.removeAllListeners('sync');535 pvp_01.removeAllListeners('turn-message');536 pvp_01.removeAllListeners('paused');537 pvp_01.removeAllListeners('unpaused');538 pvp_02.removeAllListeners('progress');539 pvp_02.removeAllListeners('begin');540 pvp_02.removeAllListeners('error');541 pvp_02.removeAllListeners('direct-message');542 pvp_02.removeAllListeners('finish');543 pvp_02.removeAllListeners('model');544 pvp_02.removeAllListeners('sync');545 pvp_02.removeAllListeners('turn-message');546 pvp_02.removeAllListeners('paused');547 pvp_02.removeAllListeners('unpaused');548 done();549 }550 } else {551 done(new Error('WTF 18'));552 }553 };554 pvp_01.on('progress', () => done(new Error('WTF 1')));555 pvp_01.on('begin', () => done(new Error('WTF 2')));556 pvp_01.on('error', err => done(err));557 pvp_01.on('direct-message', () => done(new Error('WTF 3')));558 pvp_01.on('finish', () => done(new Error('WTF 4')));559 pvp_01.on('model', () => done(new Error('WTF 5')));560 pvp_01.on('sync', () => done(new Error('WTF 6')));561 pvp_01.on('turn-message', () => done(new Error('WTF 7')));562 pvp_01.on('paused', () => done(new Error('WTF 8')));563 pvp_01.on('unpaused', () => done(new Error('WTF 9')));564 pvp_02.on('progress', () => done(new Error('WTF 10')));565 pvp_02.on('begin', () => done(new Error('WTF 11')));566 pvp_02.on('error', err => done(err));567 pvp_02.on('direct-message', callbackFn_Message);568 pvp_02.on('finish', () => done(new Error('WTF 12')));569 pvp_02.on('model', () => done(new Error('WTF 13')));570 pvp_02.on('sync', () => done(new Error('WTF 14')));571 pvp_02.on('turn-message', () => done(new Error('WTF 15')));572 pvp_02.on('paused', () => done(new Error('WTF 16')));573 pvp_02.on('unpaused', () => done(new Error('WTF 17')));574 for(let i = 0 ; i < HOW_MUCH_DIRECT ; i++){575 pvp_01.sendDirect(i);576 }577 });578 it(`Second player should send ${HOW_MUCH_DIRECT} direct messages and the first should receive them`, done => {579 var theMessagesCounter = 0;580 let callbackFn_Message = msg => {581 msg = msg.message;582 if(theMessagesCounter === msg && msg < HOW_MUCH_DIRECT){583 if(++theMessagesCounter === HOW_MUCH_DIRECT){584 pvp_01.removeAllListeners('progress');585 pvp_01.removeAllListeners('begin');586 pvp_01.removeAllListeners('error');587 pvp_01.removeAllListeners('direct-message');588 pvp_01.removeAllListeners('finish');589 pvp_01.removeAllListeners('model');590 pvp_01.removeAllListeners('sync');591 pvp_01.removeAllListeners('turn-message');592 pvp_01.removeAllListeners('paused');593 pvp_01.removeAllListeners('unpaused');594 pvp_02.removeAllListeners('progress');595 pvp_02.removeAllListeners('begin');596 pvp_02.removeAllListeners('error');597 pvp_02.removeAllListeners('direct-message');598 pvp_02.removeAllListeners('finish');599 pvp_02.removeAllListeners('model');600 pvp_02.removeAllListeners('sync');601 pvp_02.removeAllListeners('turn-message');602 pvp_02.removeAllListeners('paused');603 pvp_02.removeAllListeners('unpaused');604 done();605 }606 } else {607 done(new Error('WTF 18'));608 }609 };610 pvp_01.on('progress', () => done(new Error('WTF 1')));611 pvp_01.on('begin', () => done(new Error('WTF 2')));612 pvp_01.on('error', err => done(err));613 pvp_01.on('direct-message', callbackFn_Message);614 pvp_01.on('finish', () => done(new Error('WTF 3')));615 pvp_01.on('model', () => done(new Error('WTF 4')));616 pvp_01.on('sync', () => done(new Error('WTF 5')));617 pvp_01.on('turn-message', () => done(new Error('WTF 6')));618 pvp_01.on('paused', () => done(new Error('WTF 7')));619 pvp_01.on('unpaused', () => done(new Error('WTF 8')));620 pvp_02.on('progress', () => done(new Error('WTF 9')));621 pvp_02.on('begin', () => done(new Error('WTF 10')));622 pvp_02.on('error', err => done(err));623 pvp_02.on('direct-message', () => done(new Error('WTF 11')));624 pvp_02.on('finish', () => done(new Error('WTF 12')));625 pvp_02.on('model', () => done(new Error('WTF 13')));626 pvp_02.on('sync', () => done(new Error('WTF 14')));627 pvp_02.on('turn-message', () => done(new Error('WTF 15')));628 pvp_02.on('paused', () => done(new Error('WTF 16')));629 pvp_02.on('unpaused', () => done(new Error('WTF 17')));630 for(let i = 0 ; i < HOW_MUCH_DIRECT ; i++){631 pvp_02.sendDirect(i);632 }633 });634 it(`First player should make ${HOW_MUCH_TURNS - 1} turns and the second should see them`, done => {635 var theMessagesCounter = 0;636 let callbackFn_Message = msg => {637 msg = msg.m.message;638 if(theMessagesCounter === msg && msg < HOW_MUCH_TURNS - 1){639 if(++theMessagesCounter === HOW_MUCH_TURNS - 1){640 pvp_01.removeAllListeners('progress');641 pvp_01.removeAllListeners('begin');642 pvp_01.removeAllListeners('error');643 pvp_01.removeAllListeners('direct-message');644 pvp_01.removeAllListeners('finish');645 pvp_01.removeAllListeners('model');646 pvp_01.removeAllListeners('sync');647 pvp_01.removeAllListeners('turn-message');648 pvp_01.removeAllListeners('paused');649 pvp_01.removeAllListeners('unpaused');650 pvp_02.removeAllListeners('progress');651 pvp_02.removeAllListeners('begin');652 pvp_02.removeAllListeners('error');653 pvp_02.removeAllListeners('direct-message');654 pvp_02.removeAllListeners('finish');655 pvp_02.removeAllListeners('model');656 pvp_02.removeAllListeners('sync');657 pvp_02.removeAllListeners('turn-message');658 pvp_02.removeAllListeners('paused');659 pvp_02.removeAllListeners('unpaused');660 done();661 }662 } else {663 done(new Error('WTF 18'));664 }665 };666 pvp_01.on('progress', () => done(new Error('WTF 1')));667 pvp_01.on('begin', () => done(new Error('WTF 2')));668 pvp_01.on('error', err => done(err));669 pvp_01.on('direct-message', () => done(new Error('WTF 3')));670 pvp_01.on('finish', () => done(new Error('WTF 4')));671 pvp_01.on('model', () => done(new Error('WTF 5')));672 pvp_01.on('sync', () => done(new Error('WTF 6')));673 pvp_01.on('turn-message', () => done(new Error('WTF 7')));674 pvp_01.on('paused', () => done(new Error('WTF 8')));675 pvp_01.on('unpaused', () => done(new Error('WTF 9')));676 pvp_02.on('progress', () => done(new Error('WTF 10')));677 pvp_02.on('begin', () => done(new Error('WTF 11')));678 pvp_02.on('error', err => done(err));679 pvp_02.on('direct-message', () => done(new Error('WTF 12')));680 pvp_02.on('finish', () => done(new Error('WTF 13')));681 pvp_02.on('model', () => done(new Error('WTF 14')));682 pvp_02.on('sync', () => done(new Error('WTF 15')));683 pvp_02.on('turn-message', callbackFn_Message);684 pvp_02.on('paused', () => done(new Error('WTF 16')));685 pvp_02.on('unpaused', () => done(new Error('WTF 17')));686 for(let i = 0 ; i < HOW_MUCH_TURNS - 1 ; i++){687 pvp_01.sendTurn(i);688 }689 });690 it(`Second player should make ${HOW_MUCH_TURNS - 1} turns and the first should see them`, done => {691 var theMessagesCounter = 0;692 let callbackFn_Message = msg => {693 msg = msg.m.message;694 if(theMessagesCounter === msg && msg < HOW_MUCH_TURNS - 1){695 if(++theMessagesCounter === HOW_MUCH_TURNS - 1){696 pvp_01.removeAllListeners('progress');697 pvp_01.removeAllListeners('begin');698 pvp_01.removeAllListeners('error');699 pvp_01.removeAllListeners('direct-message');700 pvp_01.removeAllListeners('finish');701 pvp_01.removeAllListeners('model');702 pvp_01.removeAllListeners('sync');703 pvp_01.removeAllListeners('turn-message');704 pvp_01.removeAllListeners('paused');705 pvp_01.removeAllListeners('unpaused');706 pvp_02.removeAllListeners('progress');707 pvp_02.removeAllListeners('begin');708 pvp_02.removeAllListeners('error');709 pvp_02.removeAllListeners('direct-message');710 pvp_02.removeAllListeners('finish');711 pvp_02.removeAllListeners('model');712 pvp_02.removeAllListeners('sync');713 pvp_02.removeAllListeners('turn-message');714 pvp_02.removeAllListeners('paused');715 pvp_02.removeAllListeners('unpaused');716 done();717 }718 } else {719 done(new Error('WTF 18'));720 }721 };722 pvp_01.on('progress', () => done(new Error('WTF 1')));723 pvp_01.on('begin', () => done(new Error('WTF 2')));724 pvp_01.on('error', err => done(err));725 pvp_01.on('direct-message', () => done(new Error('WTF 3')));726 pvp_01.on('finish', () => done(new Error('WTF 4')));727 pvp_01.on('model', () => done(new Error('WTF 5')));728 pvp_01.on('sync', () => done(new Error('WTF 6')));729 pvp_01.on('turn-message', callbackFn_Message);730 pvp_01.on('paused', () => done(new Error('WTF 7')));731 pvp_01.on('unpaused', () => done(new Error('WTF 8')));732 pvp_02.on('progress', () => done(new Error('WTF 9')));733 pvp_02.on('begin', () => done(new Error('WTF 10')));734 pvp_02.on('error', err => done(err));735 pvp_02.on('direct-message', () => done(new Error('WTF 11')));736 pvp_02.on('finish', () => done(new Error('WTF 12')));737 pvp_02.on('model', () => done(new Error('WTF 13')));738 pvp_02.on('sync', () => done(new Error('WTF 14')));739 pvp_02.on('turn-message', () => done(new Error('WTF 15')));740 pvp_02.on('paused', () => done(new Error('WTF 16')));741 pvp_02.on('unpaused', () => done(new Error('WTF 17')));742 for(let i = 0 ; i < HOW_MUCH_TURNS - 1 ; i++){743 pvp_02.sendTurn(i);744 }745 });746 it(`First player should finalize pvp by sending ${HOW_MUCH_TURNS}th turn`, done => {747 let firstIsDone = false, secondIsDone = false;748 let callbackFn_Finish = (i, msg) => {749 expect(msg.ok).to.be.equal(true);750 expect(msg.details.endMessage).to.have.property('gameIsOver', true);751 expect(msg.details.endMessage).to.have.property('finalm');752 expect(msg.details.endMessage.finalm).to.have.property('m');753 try{754 expect(msg.details.endMessage.finalm).to.have.property('asq', HOW_MUCH_TURNS);755 } catch(__){756 expect(msg.details.endMessage.finalm).to.have.property('bsq', HOW_MUCH_TURNS);757 }758 try{759 expect(msg.details.endMessage.finalm).to.have.property('bsq', HOW_MUCH_TURNS - 1);760 } catch(__){761 expect(msg.details.endMessage.finalm).to.have.property('asq', HOW_MUCH_TURNS - 1);762 }763 expect(msg.details.endMessage.finalm.m).to.deep.equal({ message: 'FIN!' });764 if(i === 0){765 if(!firstIsDone){766 firstIsDone = true;767 } else {768 return done(new Error('WTF 17'));769 }770 } else if(i === 1){771 if(!secondIsDone){772 secondIsDone = true;773 } else {774 return done(new Error('WTF 18'));775 }776 }777 if(firstIsDone && secondIsDone){778 pvp_01.removeAllListeners('progress');779 pvp_01.removeAllListeners('begin');780 pvp_01.removeAllListeners('error');781 pvp_01.removeAllListeners('direct-message');782 pvp_01.removeAllListeners('finish');783 pvp_01.removeAllListeners('model');784 pvp_01.removeAllListeners('sync');785 pvp_01.removeAllListeners('turn-message');786 pvp_01.removeAllListeners('paused');787 pvp_01.removeAllListeners('unpaused');788 pvp_02.removeAllListeners('progress');789 pvp_02.removeAllListeners('begin');790 pvp_02.removeAllListeners('error');791 pvp_02.removeAllListeners('direct-message');792 pvp_02.removeAllListeners('finish');793 pvp_02.removeAllListeners('model');794 pvp_02.removeAllListeners('sync');795 pvp_02.removeAllListeners('turn-message');796 pvp_02.removeAllListeners('paused');797 pvp_02.removeAllListeners('unpaused');798 done();799 }800 };801 pvp_01.on('progress', () => done(new Error('WTF 1')));802 pvp_01.on('begin', () => done(new Error('WTF 2')));803 pvp_01.on('error', err => done(err));804 pvp_01.on('direct-message', () => done(new Error('WTF 3')));805 pvp_01.on('finish', msg => callbackFn_Finish(0, msg));806 pvp_01.on('model', () => done(new Error('WTF 4')));807 pvp_01.on('sync', () => done(new Error('WTF 5')));808 pvp_01.on('turn-message', () => done(new Error('WTF 6')));809 pvp_01.on('paused', () => done(new Error('WTF 7')));810 pvp_01.on('unpaused', () => done(new Error('WTF 8')));811 pvp_02.on('progress', () => done(new Error('WTF 9')));812 pvp_02.on('begin', () => done(new Error('WTF 10')));813 pvp_02.on('error', err => done(err));814 pvp_02.on('direct-message', () => done(new Error('WTF 11')));815 pvp_02.on('finish', msg => callbackFn_Finish(1, msg));816 pvp_02.on('model', () => done(new Error('WTF 12')));817 pvp_02.on('sync', () => done(new Error('WTF 13')));818 pvp_02.on('turn-message', () => done(new Error('WTF 14')));819 pvp_02.on('paused', () => done(new Error('WTF 15')));820 pvp_02.on('unpaused', () => done(new Error('WTF 16')));821 pvp_01.sendTurn('FIN!');822 });823 it('First player should list battle journal', done => {824 let callbackFn = (err, response) => {825 expect(err).to.be.a('null');826 expect(response).to.be.an.instanceof(GbaseResponse);827 expect(response.ok).to.be.equal(true);828 // expect(response.details.originalResponse.l.length).to.be.equal(1);829 done();830 };831 // We get a finish event independently of battle journal entry, so we give some penalty time to persist832 setTimeout(() => gbaseApiStdl_01.pvp.battlesList(0, 20, false, callbackFn), 1000);833 });834 it('Second player should list battle journal', done => {835 let callbackFn = (err, response) => {836 expect(err).to.be.a('null');837 expect(response).to.be.an.instanceof(GbaseResponse);838 expect(response.ok).to.be.equal(true);839 expect(response.details.originalResponse.l.length).to.be.equal(1);840 done();841 };842 // We get a finish event independently of battle journal entry, so we give some penalty time to persist843 setTimeout(() => gbaseApiStdl_02.pvp.battlesList(0, 20, false, callbackFn), 1000);844 });845 });846 describe('Pause during gameplay', () => {847 const HOW_MUCH_TURNS = 15;848 it('First should call dropMatchmaking', done => {849 let callbackFn = (err, response) => {850 expect(err).to.be.a('null');851 expect(response).to.be.an.instanceof(GbaseResponse);852 expect(response.ok).to.be.equal(true);853 expect(response.details.originalResponse).to.have.property('forReal');854 done();855 };856 gbaseApiStdl_01.pvp.dropMatchmaking(callbackFn);857 });858 it('Second should call dropMatchmaking', done => {859 let callbackFn = (err, response) => {860 expect(err).to.be.a('null');861 expect(response).to.be.an.instanceof(GbaseResponse);862 expect(response.ok).to.be.equal(true);863 expect(response.details.originalResponse).to.have.property('forReal');864 done();865 };866 gbaseApiStdl_02.pvp.dropMatchmaking(callbackFn);867 });868 it('The first should pull checkBattleNoSearch', done => {869 let callbackFn = (err, response) => {870 expect(err).to.be.a('null');871 expect(response).to.be.an.instanceof(GbaseResponse);872 expect(response.ok).to.be.equal(true);873 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');874 done();875 };876 gbaseApiStdl_01.pvp.checkBattleNoSearch(callbackFn);877 });878 it('The second should pull checkBattleNoSearch', done => {879 let callbackFn = (err, response) => {880 expect(err).to.be.a('null');881 expect(response).to.be.an.instanceof(GbaseResponse);882 expect(response.ok).to.be.equal(true);883 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');884 done();885 };886 gbaseApiStdl_02.pvp.checkBattleNoSearch(callbackFn);887 });888 var pvp_01, pvp_02;889 it('Both should find each other in pvp matchmaking', done => {890 let callbackFn_final = () => {891 if(pvp_01 && pvp_02){892 done();893 }894 };895 let callbackFn_01 = (err, response) => {896 expect(err).to.be.a('null');897 expect(response).to.be.an.instanceof(GbaseResponse);898 expect(response.ok).to.be.equal(true);899 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');900 pvp_01 = response.details.pvp;901 callbackFn_final();902 };903 let callbackFn_02 = (err, response) => {904 expect(err).to.be.a('null');905 expect(response).to.be.an.instanceof(GbaseResponse);906 expect(response.ok).to.be.equal(true);907 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');908 pvp_02 = response.details.pvp;909 callbackFn_final();910 };911 gbaseApiStdl_01.pvp.withOpponent(912 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,913 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),914 60, callbackFn_01915 );916 gbaseApiStdl_02.pvp.withOpponent(917 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,918 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),919 60, callbackFn_02920 );921 });922 it('Both should receive progress messages', done => {923 var begin_01 = false, begin_02 = false,924 shouldBeModel_01 = false, shouldBeModel_02 = false,925 beenModel_01 = false, beenModel_02 = false;926 let callbackFn_Progress = (i, msg) => {927 expect(EXPECTED_PROGRESS).to.include(msg);928 };929 let callbackFn_Begin = (i, msg) => {930 if(msg){931 expect(msg).to.be.equal(EXPECTED_BEGIN_MESSAGE);932 } else if(i === 0){933 shouldBeModel_01 = true;934 } else {935 shouldBeModel_02 = true;936 }937 if(i === 0){938 expect(pvp_01).to.have.property('myPing');939 expect(pvp_01).to.have.property('opponentPing');940 expect(pvp_01).to.have.property('isPaused', false);941 try{942 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload b' });943 } catch(__){944 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload a' });945 }946 expect(pvp_01).to.have.property('startTimestamp');947 expect(pvp_01).to.have.property('randomSeed');948 expect(pvp_01).to.have.property('meIsPlayerA');949 begin_01 = true;950 return callbackFn();951 } else if(i === 1){952 expect(pvp_02).to.have.property('myPing');953 expect(pvp_02).to.have.property('opponentPing');954 expect(pvp_02).to.have.property('isPaused', false);955 try{956 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload a' });957 } catch(__){958 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload b' });959 }960 expect(pvp_02).to.have.property('startTimestamp');961 expect(pvp_02).to.have.property('randomSeed');962 expect(pvp_02).to.have.property('meIsPlayerA');963 begin_02 = true;964 return callbackFn();965 }966 done(new Error('WTF 16'));967 };968 let callbackFn_Model = (i, msg) => {969 expect(msg).to.have.property('isA');970 expect(msg).to.have.property('mdl');971 expect(msg).to.have.property('playerTurnA', 0);972 expect(msg).to.have.property('playerTurnB', 0);973 expect(msg.mdl).to.have.property('model');974 expect(msg.mdl).to.have.property('randomSeed');975 expect(msg.mdl).to.have.property('startTs');976 if(i === 0){977 expect(shouldBeModel_01).to.be.equal(true);978 expect(beenModel_01).to.be.equal(false);979 beenModel_01 = true;980 } else {981 expect(shouldBeModel_02).to.be.equal(true);982 expect(beenModel_02).to.be.equal(false);983 beenModel_02 = true;984 }985 callbackFn();986 };987 let callbackFn = () => {988 if(begin_01 && begin_02 && (((shouldBeModel_01 && beenModel_01) || (!shouldBeModel_01))) && ((shouldBeModel_02 && beenModel_02) || (!shouldBeModel_02))){989 pvp_01.removeAllListeners('progress');990 pvp_01.removeAllListeners('begin');991 pvp_01.removeAllListeners('error');992 pvp_01.removeAllListeners('direct-message');993 pvp_01.removeAllListeners('finish');994 pvp_01.removeAllListeners('model');995 pvp_01.removeAllListeners('sync');996 pvp_01.removeAllListeners('turn-message');997 pvp_01.removeAllListeners('paused');998 pvp_01.removeAllListeners('unpaused');999 pvp_02.removeAllListeners('progress');1000 pvp_02.removeAllListeners('begin');1001 pvp_02.removeAllListeners('error');1002 pvp_02.removeAllListeners('direct-message');1003 pvp_02.removeAllListeners('finish');1004 pvp_02.removeAllListeners('model');1005 pvp_02.removeAllListeners('sync');1006 pvp_02.removeAllListeners('turn-message');1007 pvp_02.removeAllListeners('paused');1008 pvp_02.removeAllListeners('unpaused');1009 done();1010 }1011 };1012 pvp_01.on('progress', msg => callbackFn_Progress(0, msg));1013 pvp_01.on('begin', msg => callbackFn_Begin(0, msg));1014 pvp_01.on('error', err => done(err));1015 pvp_01.on('direct-message', () => done(new Error('WTF 1')));1016 pvp_01.on('finish', () => done(new Error('WTF 2')));1017 pvp_01.on('model', msg => callbackFn_Model(0, msg));1018 pvp_01.on('sync', () => done(new Error('WTF 4')));1019 pvp_01.on('turn-message', () => done(new Error('WTF 5')));1020 pvp_01.on('paused', () => done(new Error('WTF 6')));1021 pvp_01.on('unpaused', () => done(new Error('WTF 7')));1022 pvp_02.on('progress', msg => callbackFn_Progress(1, msg));1023 pvp_02.on('begin', msg => callbackFn_Begin(1, msg));1024 pvp_02.on('error', err => done(err));1025 pvp_02.on('direct-message', () => done(new Error('WTF 8')));1026 pvp_02.on('finish', () => done(new Error('WTF 9')));1027 pvp_02.on('model', msg => callbackFn_Model(1, msg));1028 pvp_02.on('sync', () => done(new Error('WTF 11')));1029 pvp_02.on('turn-message', () => done(new Error('WTF 12')));1030 pvp_02.on('paused', () => done(new Error('WTF 13')));1031 pvp_02.on('unpaused', () => done(new Error('WTF 14')));1032 pvp_01.doConnect({ payload: '01' });1033 pvp_02.doConnect({ payload: '02' });1034 });1035 it(`First player should make ${HOW_MUCH_TURNS - 1} turns and the second should see them`, done => {1036 var theMessagesCounter = 0;1037 let callbackFn_Message = msg => {1038 msg = msg.m.message;1039 if(theMessagesCounter === msg && msg < HOW_MUCH_TURNS - 1){1040 if(++theMessagesCounter === HOW_MUCH_TURNS - 1){1041 pvp_01.removeAllListeners('progress');1042 pvp_01.removeAllListeners('begin');1043 pvp_01.removeAllListeners('error');1044 pvp_01.removeAllListeners('direct-message');1045 pvp_01.removeAllListeners('finish');1046 pvp_01.removeAllListeners('model');1047 pvp_01.removeAllListeners('sync');1048 pvp_01.removeAllListeners('turn-message');1049 pvp_01.removeAllListeners('paused');1050 pvp_01.removeAllListeners('unpaused');1051 pvp_02.removeAllListeners('progress');1052 pvp_02.removeAllListeners('begin');1053 pvp_02.removeAllListeners('error');1054 pvp_02.removeAllListeners('direct-message');1055 pvp_02.removeAllListeners('finish');1056 pvp_02.removeAllListeners('model');1057 pvp_02.removeAllListeners('sync');1058 pvp_02.removeAllListeners('turn-message');1059 pvp_02.removeAllListeners('paused');1060 pvp_02.removeAllListeners('unpaused');1061 done();1062 }1063 } else {1064 done(new Error('WTF 18'));1065 }1066 };1067 pvp_01.on('progress', () => done(new Error('WTF 1')));1068 pvp_01.on('begin', () => done(new Error('WTF 2')));1069 pvp_01.on('error', err => done(err));1070 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1071 pvp_01.on('finish', () => done(new Error('WTF 4')));1072 pvp_01.on('model', () => done(new Error('WTF 5')));1073 pvp_01.on('sync', () => done(new Error('WTF 6')));1074 pvp_01.on('turn-message', () => done(new Error('WTF 7')));1075 pvp_01.on('paused', () => done(new Error('WTF 8')));1076 pvp_01.on('unpaused', () => done(new Error('WTF 9')));1077 pvp_02.on('progress', () => done(new Error('WTF 10')));1078 pvp_02.on('begin', () => done(new Error('WTF 11')));1079 pvp_02.on('error', err => done(err));1080 pvp_02.on('direct-message', () => done(new Error('WTF 12')));1081 pvp_02.on('finish', () => done(new Error('WTF 13')));1082 pvp_02.on('model', () => done(new Error('WTF 14')));1083 pvp_02.on('sync', () => done(new Error('WTF 15')));1084 pvp_02.on('turn-message', callbackFn_Message);1085 pvp_02.on('paused', () => done(new Error('WTF 16')));1086 pvp_02.on('unpaused', () => done(new Error('WTF 17')));1087 for(let i = 0 ; i < HOW_MUCH_TURNS - 1 ; i++){1088 pvp_01.sendTurn(i);1089 }1090 });1091 it(`Second player should make ${HOW_MUCH_TURNS - 1} turns and the first should see them`, done => {1092 var theMessagesCounter = 0;1093 let callbackFn_Message = msg => {1094 msg = msg.m.message;1095 if(theMessagesCounter === msg && msg < HOW_MUCH_TURNS - 1){1096 if(++theMessagesCounter === HOW_MUCH_TURNS - 1){1097 pvp_01.removeAllListeners('progress');1098 pvp_01.removeAllListeners('begin');1099 pvp_01.removeAllListeners('error');1100 pvp_01.removeAllListeners('direct-message');1101 pvp_01.removeAllListeners('finish');1102 pvp_01.removeAllListeners('model');1103 pvp_01.removeAllListeners('sync');1104 pvp_01.removeAllListeners('turn-message');1105 pvp_01.removeAllListeners('paused');1106 pvp_01.removeAllListeners('unpaused');1107 pvp_02.removeAllListeners('progress');1108 pvp_02.removeAllListeners('begin');1109 pvp_02.removeAllListeners('error');1110 pvp_02.removeAllListeners('direct-message');1111 pvp_02.removeAllListeners('finish');1112 pvp_02.removeAllListeners('model');1113 pvp_02.removeAllListeners('sync');1114 pvp_02.removeAllListeners('turn-message');1115 pvp_02.removeAllListeners('paused');1116 pvp_02.removeAllListeners('unpaused');1117 done();1118 }1119 } else {1120 done(new Error('WTF 18'));1121 }1122 };1123 pvp_01.on('progress', () => done(new Error('WTF 1')));1124 pvp_01.on('begin', () => done(new Error('WTF 2')));1125 pvp_01.on('error', err => done(err));1126 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1127 pvp_01.on('finish', () => done(new Error('WTF 4')));1128 pvp_01.on('model', () => done(new Error('WTF 5')));1129 pvp_01.on('sync', () => done(new Error('WTF 6')));1130 pvp_01.on('turn-message', callbackFn_Message);1131 pvp_01.on('paused', () => done(new Error('WTF 7')));1132 pvp_01.on('unpaused', () => done(new Error('WTF 8')));1133 pvp_02.on('progress', () => done(new Error('WTF 9')));1134 pvp_02.on('begin', () => done(new Error('WTF 10')));1135 pvp_02.on('error', err => done(err));1136 pvp_02.on('direct-message', () => done(new Error('WTF 11')));1137 pvp_02.on('finish', () => done(new Error('WTF 12')));1138 pvp_02.on('model', () => done(new Error('WTF 13')));1139 pvp_02.on('sync', () => done(new Error('WTF 14')));1140 pvp_02.on('turn-message', () => done(new Error('WTF 15')));1141 pvp_02.on('paused', () => done(new Error('WTF 16')));1142 pvp_02.on('unpaused', () => done(new Error('WTF 17')));1143 for(let i = 0 ; i < HOW_MUCH_TURNS - 1 ; i++){1144 pvp_02.sendTurn(i);1145 }1146 });1147 it('First player should force disconnect and both should see the pause', done => {1148 var pauseArguments1, pauseArguments2;1149 let callbackFn = () => {1150 if(pauseArguments1 && pauseArguments2){1151 expect(pauseArguments1[0]).to.be.equal('Game paused due to disconnection');1152 expect(pauseArguments1[1]).to.be.an('undefined');1153 expect(pauseArguments1[2]).to.be.an('undefined');1154 expect(pauseArguments2[0]).to.have.property('isA');1155 expect(pauseArguments2[0]).to.have.property('playerTurnA');1156 expect(pauseArguments2[0]).to.have.property('playerTurnB');1157 expect(pauseArguments2[0]).to.have.property('theModel');1158 expect(pauseArguments2[1]).to.be.above(0);1159 expect(pauseArguments2[2]).to.be.an('undefined');1160 setTimeout(() => {1161 pvp_01.removeAllListeners('progress');1162 pvp_01.removeAllListeners('begin');1163 pvp_01.removeAllListeners('error');1164 pvp_01.removeAllListeners('direct-message');1165 pvp_01.removeAllListeners('finish');1166 pvp_01.removeAllListeners('model');1167 pvp_01.removeAllListeners('sync');1168 pvp_01.removeAllListeners('turn-message');1169 pvp_01.removeAllListeners('paused');1170 pvp_01.removeAllListeners('unpaused');1171 pvp_02.removeAllListeners('progress');1172 pvp_02.removeAllListeners('begin');1173 pvp_02.removeAllListeners('error');1174 pvp_02.removeAllListeners('direct-message');1175 pvp_02.removeAllListeners('finish');1176 pvp_02.removeAllListeners('model');1177 pvp_02.removeAllListeners('sync');1178 pvp_02.removeAllListeners('turn-message');1179 pvp_02.removeAllListeners('paused');1180 pvp_02.removeAllListeners('unpaused');1181 done();1182 }, 1000);1183 }1184 };1185 pvp_01.on('progress', () => done(new Error('WTF 1')));1186 pvp_01.on('begin', () => done(new Error('WTF 2')));1187 pvp_01.on('error', err => done(err));1188 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1189 pvp_01.on('finish', () => done(new Error('WTF 4')));1190 pvp_01.on('model', () => done(new Error('WTF 5')));1191 pvp_01.on('sync', () => done(new Error('WTF 6')));1192 pvp_01.on('turn-message', () => done(new Error('WTF 7')));1193 pvp_01.on('paused', (theMessage, ts1, ts2) => {1194 pauseArguments1 = [theMessage, ts1, ts2];1195 callbackFn();1196 });1197 pvp_01.on('unpaused', () => done(new Error('WTF 9')));1198 pvp_02.on('progress', () => done(new Error('WTF 10')));1199 pvp_02.on('begin', () => done(new Error('WTF 11')));1200 pvp_02.on('error', err => done(err));1201 pvp_02.on('direct-message', () => done(new Error('WTF 12')));1202 pvp_02.on('finish', () => done(new Error('WTF 13')));1203 pvp_02.on('model', () => done(new Error('WTF 14')));1204 pvp_02.on('sync', () => done(new Error('WTF 15')));1205 pvp_02.on('turn-message', () => done(new Error('WTF 16')));1206 pvp_02.on('paused', (theMessage, ts1, ts2) => {1207 pauseArguments2 = [theMessage, ts1, ts2];1208 callbackFn();1209 });1210 pvp_02.on('unpaused', () => done(new Error('WTF 17')));1211 pvp_01.forceDisconnect();1212 });1213 it('Second should try to send message during pause', () => {1214 try{1215 pvp_02.sendTurn('la message');1216 } catch(errImExpecting){1217 expect(errImExpecting).to.be.instanceof(GbaseError);1218 expect(errImExpecting).to.have.property('code', 138);1219 return;1220 }1221 throw new Error('WTF');1222 });1223 it('First player should reconnect and both should see unpaused with the same timestamp', done => {1224 let gotUnpaused1 = false, gotUnpaused2 = false, gotModel = false,1225 unpauseTs1, unpauseTs2,1226 pauseTs1, pauseTs2;1227 let callbackFn_Unpause1 = (msg, at, from) => {1228 expect(at).to.be.above(0);1229 expect(from).to.be.above(0);1230 expect(msg).to.be.equal('GR: opponent connected');1231 gotUnpaused1 = true;1232 unpauseTs1 = at;1233 pauseTs1 = from;1234 callbackFn();1235 };1236 let callbackFn_Unpause2 = (msg, at, from) => {1237 expect(at).to.be.above(0);1238 expect(from).to.be.above(0);1239 expect(msg).to.be.a('null');1240 gotUnpaused2 = true;1241 unpauseTs2 = at;1242 pauseTs2 = from;1243 callbackFn();1244 };1245 let callbackFn_Model = msg => {1246 expect(msg).to.have.property('mdl');1247 expect(msg).to.have.property('isA');1248 expect(msg).to.have.property('playerTurnA');1249 expect(msg).to.have.property('playerTurnB');1250 expect(msg.mdl).to.have.property('randomSeed');1251 expect(msg.mdl).to.have.property('startTs');1252 expect(msg.mdl).to.have.property('model');1253 gotModel = true;1254 callbackFn();1255 };1256 let callbackFn = () => {1257 if(gotUnpaused1 && gotUnpaused2 && gotModel){1258 expect(unpauseTs1).to.be.equal(unpauseTs2);1259 expect(pauseTs1).to.be.equal(pauseTs2);1260 pvp_01.removeAllListeners('progress');1261 pvp_01.removeAllListeners('begin');1262 pvp_01.removeAllListeners('error');1263 pvp_01.removeAllListeners('direct-message');1264 pvp_01.removeAllListeners('finish');1265 pvp_01.removeAllListeners('model');1266 pvp_01.removeAllListeners('sync');1267 pvp_01.removeAllListeners('turn-message');1268 pvp_01.removeAllListeners('paused');1269 pvp_01.removeAllListeners('unpaused');1270 pvp_02.removeAllListeners('progress');1271 pvp_02.removeAllListeners('begin');1272 pvp_02.removeAllListeners('error');1273 pvp_02.removeAllListeners('direct-message');1274 pvp_02.removeAllListeners('finish');1275 pvp_02.removeAllListeners('model');1276 pvp_02.removeAllListeners('sync');1277 pvp_02.removeAllListeners('turn-message');1278 pvp_02.removeAllListeners('paused');1279 pvp_02.removeAllListeners('unpaused');1280 done();1281 }1282 };1283 pvp_01.on('progress', () => done(new Error('WTF 1')));1284 pvp_01.on('begin', () => done(new Error('WTF 2')));1285 pvp_01.on('error', err => done(err));1286 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1287 pvp_01.on('finish', () => done(new Error('WTF 4')));1288 pvp_01.on('model', callbackFn_Model);1289 pvp_01.on('sync', () => done(new Error('WTF 5')));1290 pvp_01.on('turn-message', () => done(new Error('WTF 6')));1291 pvp_01.on('paused', () => done(new Error('WTF 7')));1292 pvp_01.on('unpaused', callbackFn_Unpause2);1293 pvp_02.on('progress', () => done(new Error('WTF 9')));1294 pvp_02.on('begin', () => done(new Error('WTF 10')));1295 pvp_02.on('error', err => done(err));1296 pvp_02.on('direct-message', () => done(new Error('WTF 11')));1297 pvp_02.on('finish', () => done(new Error('WTF 12')));1298 pvp_02.on('model', () => done(new Error('WTF 13')));1299 pvp_02.on('sync', () => done(new Error('WTF 14')));1300 pvp_02.on('turn-message', () => done(new Error('WTF 15')));1301 pvp_02.on('paused', () => done(new Error('WTF 16')));1302 pvp_02.on('unpaused', callbackFn_Unpause1);1303 pvp_01.reconnect();1304 });1305 it('Second player should destroy pvp client', done => {1306 var gotFinish = false, pauseArguments1, pauseArguments2,1307 gotPaused = false;1308 let callbackFn_Finish = response => {1309 expect(response.ok).to.be.equal(true);1310 expect(response.details.endMessage).to.be.equal('Forced to close client-side');1311 gotFinish = true;1312 callbackFn();1313 };1314 let callbackFn_Paused = () => {1315 if(pauseArguments1 && pauseArguments2){1316 expect(pauseArguments1[0]).to.have.property('isA');1317 expect(pauseArguments1[0]).to.have.property('playerTurnA');1318 expect(pauseArguments1[0]).to.have.property('playerTurnB');1319 expect(pauseArguments1[0]).to.have.property('theModel');1320 expect(pauseArguments1[1]).to.be.above(0);1321 expect(pauseArguments1[2]).to.be.an('undefined');1322 expect(pauseArguments2[0]).to.be.equal('Game paused due to disconnection');1323 expect(pauseArguments2[1]).to.be.an('undefined');1324 expect(pauseArguments2[2]).to.be.an('undefined');1325 gotPaused = true;1326 callbackFn();1327 }1328 };1329 let callbackFn = () => {1330 if(gotFinish && gotPaused){1331 setTimeout(() => {1332 pvp_01.removeAllListeners('progress');1333 pvp_01.removeAllListeners('begin');1334 pvp_01.removeAllListeners('error');1335 pvp_01.removeAllListeners('direct-message');1336 pvp_01.removeAllListeners('finish');1337 pvp_01.removeAllListeners('model');1338 pvp_01.removeAllListeners('sync');1339 pvp_01.removeAllListeners('turn-message');1340 pvp_01.removeAllListeners('paused');1341 pvp_01.removeAllListeners('unpaused');1342 pvp_02.removeAllListeners('progress');1343 pvp_02.removeAllListeners('begin');1344 pvp_02.removeAllListeners('error');1345 pvp_02.removeAllListeners('direct-message');1346 pvp_02.removeAllListeners('finish');1347 pvp_02.removeAllListeners('model');1348 pvp_02.removeAllListeners('sync');1349 pvp_02.removeAllListeners('turn-message');1350 pvp_02.removeAllListeners('paused');1351 pvp_02.removeAllListeners('unpaused');1352 done();1353 }, 1000);1354 }1355 };1356 pvp_01.on('progress', () => done(new Error('WTF 1')));1357 pvp_01.on('begin', () => done(new Error('WTF 2')));1358 pvp_01.on('error', err => done(err));1359 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1360 pvp_01.on('finish', () => done(new Error('WTF 4')));1361 pvp_01.on('model', () => done(new Error('WTF 5')));1362 pvp_01.on('sync', () => done(new Error('WTF 6')));1363 pvp_01.on('turn-message', () => done(new Error('WTF 7')));1364 pvp_01.on('paused', (theMessage, ts1, ts2) => {1365 pauseArguments1 = [theMessage, ts1, ts2];1366 callbackFn_Paused();1367 });1368 pvp_01.on('unpaused', () => done(new Error('WTF 8')));1369 pvp_02.on('progress', () => done(new Error('WTF 9')));1370 pvp_02.on('begin', () => done(new Error('WTF 10')));1371 pvp_02.on('error', err => done(err));1372 pvp_02.on('direct-message', () => done(new Error('WTF 11')));1373 pvp_02.on('finish', callbackFn_Finish);1374 pvp_02.on('model', () => done(new Error('WTF 12')));1375 pvp_02.on('sync', () => done(new Error('WTF 13')));1376 pvp_02.on('turn-message', () => done(new Error('WTF 14')));1377 pvp_02.on('paused', (theMessage, ts1, ts2) => {1378 pauseArguments2 = [theMessage, ts1, ts2];1379 callbackFn_Paused();1380 });1381 pvp_02.on('unpaused', () => done(new Error('WTF 16')));1382 pvp_02.forceDestroyClient();1383 });1384 var pvpRoomData;1385 it('The second should pull checkBattleNoSearch', done => {1386 let callbackFn = (err, response) => {1387 expect(err).to.be.a('null');1388 expect(response).to.be.an.instanceof(GbaseResponse);1389 expect(response.ok).to.be.equal(true);1390 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');1391 pvpRoomData = response.details.originalResponse;1392 done();1393 };1394 gbaseApiStdl_02.pvp.checkBattleNoSearch(callbackFn);1395 });1396 it('The second should rebuild his lost pvp', done => {1397 var connect = false, unpauseArguments1, unpauseArguments2,1398 unpaused = false, theBegin = false, theSync = false;1399 let callbackFn_Connect = (err, response) => {1400 expect(err).to.be.a('null');1401 expect(response).to.be.an.instanceof(GbaseResponse);1402 expect(response.ok).to.be.equal(true);1403 expect(response.details).to.have.property('pvp');1404 pvp_02 = response.details.pvp;1405 pvp_02.on('progress', () => done(new Error('WTF 9')));1406 pvp_02.on('begin', callbackFn_Begin);1407 pvp_02.on('error', err => done(err));1408 pvp_02.on('direct-message', () => done(new Error('WTF 11')));1409 pvp_02.on('finish', () => done(new Error('WTF 12')));1410 pvp_02.on('model', () => done(new Error('WTF 13')));1411 pvp_02.on('sync', callbackFn_Sync);1412 pvp_02.on('turn-message', () => done(new Error('WTF 14')));1413 pvp_02.on('paused', () => done(new Error('WTF 15')));1414 pvp_02.on('unpaused', (theMessage, ts1, ts2) => {1415 unpauseArguments2 = [theMessage, ts1, ts2];1416 callbackFn_Unpaused();1417 });1418 connect = true;1419 callbackFn();1420 };1421 let callbackFn_Unpaused = () => {1422 if(unpauseArguments1 && unpauseArguments2){1423 expect(unpauseArguments1[0]).to.be.equal('GR: opponent connected');1424 expect(unpauseArguments1[1]).to.be.above(0);1425 expect(unpauseArguments1[2]).to.be.above(0);1426 expect(unpauseArguments2[0]).to.be.a('null');1427 expect(unpauseArguments2[1]).to.be.above(0);1428 expect(unpauseArguments2[2]).to.be.above(0);1429 unpaused = true;1430 callbackFn();1431 }1432 };1433 let callbackFn_Begin = msg => {1434 expect(msg).to.be.a('undefined');1435 theBegin = true;1436 callbackFn();1437 };1438 let callbackFn_Sync = msg => {1439 expect(msg).to.have.property('isA');1440 expect(msg).to.have.property('playerTurnA');1441 expect(msg).to.have.property('playerTurnB');1442 expect(msg).to.have.property('mdl');1443 expect(msg.mdl).to.have.property('model');1444 expect(msg.mdl).to.have.property('randomSeed');1445 expect(msg.mdl).to.have.property('startTs');1446 theSync = true;1447 callbackFn();1448 };1449 let callbackFn = () => {1450 if(connect && unpaused && theBegin && theSync){1451 pvp_01.removeAllListeners('progress');1452 pvp_01.removeAllListeners('begin');1453 pvp_01.removeAllListeners('error');1454 pvp_01.removeAllListeners('direct-message');1455 pvp_01.removeAllListeners('finish');1456 pvp_01.removeAllListeners('model');1457 pvp_01.removeAllListeners('sync');1458 pvp_01.removeAllListeners('turn-message');1459 pvp_01.removeAllListeners('paused');1460 pvp_01.removeAllListeners('unpaused');1461 pvp_02.removeAllListeners('progress');1462 pvp_02.removeAllListeners('begin');1463 pvp_02.removeAllListeners('error');1464 pvp_02.removeAllListeners('direct-message');1465 pvp_02.removeAllListeners('finish');1466 pvp_02.removeAllListeners('model');1467 pvp_02.removeAllListeners('sync');1468 pvp_02.removeAllListeners('turn-message');1469 pvp_02.removeAllListeners('paused');1470 pvp_02.removeAllListeners('unpaused');1471 done();1472 }1473 };1474 pvp_01.on('progress', () => done(new Error('WTF 1')));1475 pvp_01.on('begin', () => done(new Error('WTF 2')));1476 pvp_01.on('error', err => done(err));1477 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1478 pvp_01.on('finish', () => done(new Error('WTF 4')));1479 pvp_01.on('model', () => done(new Error('WTF 5')));1480 pvp_01.on('sync', () => done(new Error('WTF 6')));1481 pvp_01.on('turn-message', () => done(new Error('WTF 7')));1482 pvp_01.on('paused', () => done(new Error('WTF 8')));1483 pvp_01.on('unpaused', (theMessage, ts1, ts2) => {1484 unpauseArguments1 = [theMessage, ts1, ts2];1485 callbackFn_Unpaused();1486 });1487 gbaseApiStdl_02.pvp.beginOnAddressAndKey(pvpRoomData, callbackFn_Connect);1488 });1489 it(`First player should finalize pvp by sending ${HOW_MUCH_TURNS}th turn`, done => {1490 let firstIsDone = false, secondIsDone = false;1491 let callbackFn_Finish = (i, msg) => {1492 expect(msg.ok).to.be.equal(true);1493 expect(msg.details.endMessage).to.have.property('gameIsOver', true);1494 expect(msg.details.endMessage).to.have.property('finalm');1495 expect(msg.details.endMessage.finalm).to.have.property('m');1496 try{1497 expect(msg.details.endMessage.finalm).to.have.property('asq', HOW_MUCH_TURNS);1498 } catch(__){1499 expect(msg.details.endMessage.finalm).to.have.property('bsq', HOW_MUCH_TURNS);1500 }1501 try{1502 expect(msg.details.endMessage.finalm).to.have.property('bsq', HOW_MUCH_TURNS - 1);1503 } catch(__){1504 expect(msg.details.endMessage.finalm).to.have.property('asq', HOW_MUCH_TURNS - 1);1505 }1506 expect(msg.details.endMessage.finalm.m).to.deep.equal({ message: 'FIN!' });1507 if(i === 0){1508 if(!firstIsDone){1509 firstIsDone = true;1510 } else {1511 return done(new Error('WTF 17'));1512 }1513 } else if(i === 1){1514 if(!secondIsDone){1515 secondIsDone = true;1516 } else {1517 return done(new Error('WTF 18'));1518 }1519 }1520 if(firstIsDone && secondIsDone){1521 pvp_01.removeAllListeners('progress');1522 pvp_01.removeAllListeners('begin');1523 pvp_01.removeAllListeners('error');1524 pvp_01.removeAllListeners('direct-message');1525 pvp_01.removeAllListeners('finish');1526 pvp_01.removeAllListeners('model');1527 pvp_01.removeAllListeners('sync');1528 pvp_01.removeAllListeners('turn-message');1529 pvp_01.removeAllListeners('paused');1530 pvp_01.removeAllListeners('unpaused');1531 pvp_02.removeAllListeners('progress');1532 pvp_02.removeAllListeners('begin');1533 pvp_02.removeAllListeners('error');1534 pvp_02.removeAllListeners('direct-message');1535 pvp_02.removeAllListeners('finish');1536 pvp_02.removeAllListeners('model');1537 pvp_02.removeAllListeners('sync');1538 pvp_02.removeAllListeners('turn-message');1539 pvp_02.removeAllListeners('paused');1540 pvp_02.removeAllListeners('unpaused');1541 done();1542 }1543 };1544 pvp_01.on('progress', () => done(new Error('WTF 1')));1545 pvp_01.on('begin', () => done(new Error('WTF 2')));1546 pvp_01.on('error', err => done(err));1547 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1548 pvp_01.on('finish', msg => callbackFn_Finish(0, msg));1549 pvp_01.on('model', () => done(new Error('WTF 4')));1550 pvp_01.on('sync', () => done(new Error('WTF 5')));1551 pvp_01.on('turn-message', () => done(new Error('WTF 6')));1552 pvp_01.on('paused', () => done(new Error('WTF 7')));1553 pvp_01.on('unpaused', () => done(new Error('WTF 8')));1554 pvp_02.on('progress', () => done(new Error('WTF 9')));1555 pvp_02.on('begin', () => done(new Error('WTF 10')));1556 pvp_02.on('error', err => done(err));1557 pvp_02.on('direct-message', () => done(new Error('WTF 11')));1558 pvp_02.on('finish', msg => callbackFn_Finish(1, msg));1559 pvp_02.on('model', () => done(new Error('WTF 12')));1560 pvp_02.on('sync', () => done(new Error('WTF 13')));1561 pvp_02.on('turn-message', () => done(new Error('WTF 14')));1562 pvp_02.on('paused', () => done(new Error('WTF 15')));1563 pvp_02.on('unpaused', () => done(new Error('WTF 16')));1564 pvp_01.sendTurn('FIN!');1565 });1566 });1567 describe('Pause and auto-gameover during gameplay', () => {1568 it('First should call dropMatchmaking', done => {1569 let callbackFn = (err, response) => {1570 expect(err).to.be.a('null');1571 expect(response).to.be.an.instanceof(GbaseResponse);1572 expect(response.ok).to.be.equal(true);1573 expect(response.details.originalResponse).to.have.property('forReal');1574 done();1575 };1576 gbaseApiStdl_01.pvp.dropMatchmaking(callbackFn);1577 });1578 it('Second should call dropMatchmaking', done => {1579 let callbackFn = (err, response) => {1580 expect(err).to.be.a('null');1581 expect(response).to.be.an.instanceof(GbaseResponse);1582 expect(response.ok).to.be.equal(true);1583 expect(response.details.originalResponse).to.have.property('forReal');1584 done();1585 };1586 gbaseApiStdl_02.pvp.dropMatchmaking(callbackFn);1587 });1588 it('The first should pull checkBattleNoSearch', done => {1589 let callbackFn = (err, response) => {1590 expect(err).to.be.a('null');1591 expect(response).to.be.an.instanceof(GbaseResponse);1592 expect(response.ok).to.be.equal(true);1593 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');1594 done();1595 };1596 gbaseApiStdl_01.pvp.checkBattleNoSearch(callbackFn);1597 });1598 it('The second should pull checkBattleNoSearch', done => {1599 let callbackFn = (err, response) => {1600 expect(err).to.be.a('null');1601 expect(response).to.be.an.instanceof(GbaseResponse);1602 expect(response.ok).to.be.equal(true);1603 expect(response.details.originalResponse.stat).to.be.equal('MM: neither in queue nor in battle');1604 done();1605 };1606 gbaseApiStdl_02.pvp.checkBattleNoSearch(callbackFn);1607 });1608 var pvp_01, pvp_02;1609 it('Both should find each other in pvp matchmaking', done => {1610 let callbackFn_final = () => {1611 if(pvp_01 && pvp_02){1612 done();1613 }1614 };1615 let callbackFn_01 = (err, response) => {1616 expect(err).to.be.a('null');1617 expect(response).to.be.an.instanceof(GbaseResponse);1618 expect(response.ok).to.be.equal(true);1619 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');1620 pvp_01 = response.details.pvp;1621 callbackFn_final();1622 };1623 let callbackFn_02 = (err, response) => {1624 expect(err).to.be.a('null');1625 expect(response).to.be.an.instanceof(GbaseResponse);1626 expect(response.ok).to.be.equal(true);1627 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');1628 pvp_02 = response.details.pvp;1629 callbackFn_final();1630 };1631 gbaseApiStdl_01.pvp.withOpponent(1632 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,1633 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),1634 60, callbackFn_011635 );1636 gbaseApiStdl_02.pvp.withOpponent(1637 FROM_SEGMENT, GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,1638 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),1639 60, callbackFn_021640 );1641 });1642 it('Both should receive progress messages', done => {1643 var begin_01 = false, begin_02 = false,1644 shouldBeModel_01 = false, shouldBeModel_02 = false,1645 beenModel_01 = false, beenModel_02 = false;1646 let callbackFn_Progress = (i, msg) => {1647 expect(EXPECTED_PROGRESS).to.include(msg);1648 };1649 let callbackFn_Begin = (i, msg) => {1650 if(msg){1651 expect(msg).to.be.equal(EXPECTED_BEGIN_MESSAGE);1652 } else if(i === 0){1653 shouldBeModel_01 = true;1654 } else {1655 shouldBeModel_02 = true;1656 }1657 if(i === 0){1658 expect(pvp_01).to.have.property('myPing');1659 expect(pvp_01).to.have.property('opponentPing');1660 expect(pvp_01).to.have.property('isPaused', false);1661 try{1662 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload b' });1663 } catch(__){1664 expect(pvp_01.opponentPayload).to.deep.equal({ some: 'payload a' });1665 }1666 expect(pvp_01).to.have.property('startTimestamp');1667 expect(pvp_01).to.have.property('randomSeed');1668 expect(pvp_01).to.have.property('meIsPlayerA');1669 begin_01 = true;1670 return callbackFn();1671 } else if(i === 1){1672 expect(pvp_02).to.have.property('myPing');1673 expect(pvp_02).to.have.property('opponentPing');1674 expect(pvp_02).to.have.property('isPaused', false);1675 try{1676 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload a' });1677 } catch(__){1678 expect(pvp_02.opponentPayload).to.deep.equal({ some: 'payload b' });1679 }1680 expect(pvp_02).to.have.property('startTimestamp');1681 expect(pvp_02).to.have.property('randomSeed');1682 expect(pvp_02).to.have.property('meIsPlayerA');1683 begin_02 = true;1684 return callbackFn();1685 }1686 done(new Error('WTF 16'));1687 };1688 let callbackFn_Model = (i, msg) => {1689 expect(msg).to.have.property('isA');1690 expect(msg).to.have.property('mdl');1691 expect(msg).to.have.property('playerTurnA', 0);1692 expect(msg).to.have.property('playerTurnB', 0);1693 expect(msg.mdl).to.have.property('model');1694 expect(msg.mdl).to.have.property('randomSeed');1695 expect(msg.mdl).to.have.property('startTs');1696 if(i === 0){1697 expect(shouldBeModel_01).to.be.equal(true);1698 expect(beenModel_01).to.be.equal(false);1699 beenModel_01 = true;1700 } else {1701 expect(shouldBeModel_02).to.be.equal(true);1702 expect(beenModel_02).to.be.equal(false);1703 beenModel_02 = true;1704 }1705 callbackFn();1706 };1707 let callbackFn = () => {1708 if(begin_01 && begin_02 && (((shouldBeModel_01 && beenModel_01) || (!shouldBeModel_01))) && ((shouldBeModel_02 && beenModel_02) || (!shouldBeModel_02))){1709 pvp_01.removeAllListeners('progress');1710 pvp_01.removeAllListeners('begin');1711 pvp_01.removeAllListeners('error');1712 pvp_01.removeAllListeners('direct-message');1713 pvp_01.removeAllListeners('finish');1714 pvp_01.removeAllListeners('model');1715 pvp_01.removeAllListeners('sync');1716 pvp_01.removeAllListeners('turn-message');1717 pvp_01.removeAllListeners('paused');1718 pvp_01.removeAllListeners('unpaused');1719 pvp_02.removeAllListeners('progress');1720 pvp_02.removeAllListeners('begin');1721 pvp_02.removeAllListeners('error');1722 pvp_02.removeAllListeners('direct-message');1723 pvp_02.removeAllListeners('finish');1724 pvp_02.removeAllListeners('model');1725 pvp_02.removeAllListeners('sync');1726 pvp_02.removeAllListeners('turn-message');1727 pvp_02.removeAllListeners('paused');1728 pvp_02.removeAllListeners('unpaused');1729 done();1730 }1731 };1732 pvp_01.on('progress', msg => callbackFn_Progress(0, msg));1733 pvp_01.on('begin', msg => callbackFn_Begin(0, msg));1734 pvp_01.on('error', err => done(err));1735 pvp_01.on('direct-message', () => done(new Error('WTF 1')));1736 pvp_01.on('finish', () => done(new Error('WTF 2')));1737 pvp_01.on('model', msg => callbackFn_Model(0, msg));1738 pvp_01.on('sync', () => done(new Error('WTF 4')));1739 pvp_01.on('turn-message', () => done(new Error('WTF 5')));1740 pvp_01.on('paused', () => done(new Error('WTF 6')));1741 pvp_01.on('unpaused', () => done(new Error('WTF 7')));1742 pvp_02.on('progress', msg => callbackFn_Progress(1, msg));1743 pvp_02.on('begin', msg => callbackFn_Begin(1, msg));1744 pvp_02.on('error', err => done(err));1745 pvp_02.on('direct-message', () => done(new Error('WTF 8')));1746 pvp_02.on('finish', () => done(new Error('WTF 9')));1747 pvp_02.on('model', msg => callbackFn_Model(1, msg));1748 pvp_02.on('sync', () => done(new Error('WTF 11')));1749 pvp_02.on('turn-message', () => done(new Error('WTF 12')));1750 pvp_02.on('paused', () => done(new Error('WTF 13')));1751 pvp_02.on('unpaused', () => done(new Error('WTF 14')));1752 pvp_01.doConnect({ payload: '01' });1753 pvp_02.doConnect({ payload: '02' });1754 });1755 it('First player should force disconnect and the second should see the pause', done => {1756 var pauseArguments1, pauseArguments2;1757 let callbackFn = () => {1758 if(pauseArguments1 && pauseArguments2){1759 expect(pauseArguments1[0]).to.be.equal('Game paused due to disconnection');1760 expect(pauseArguments1[1]).to.be.an('undefined');1761 expect(pauseArguments2[0]).to.have.property('isA');1762 expect(pauseArguments2[0]).to.have.property('playerTurnA');1763 expect(pauseArguments2[0]).to.have.property('playerTurnB');1764 expect(pauseArguments2[0]).to.have.property('theModel');1765 expect(pauseArguments2[1]).to.be.above(0);1766 setTimeout(() => {1767 pvp_01.removeAllListeners('progress');1768 pvp_01.removeAllListeners('begin');1769 pvp_01.removeAllListeners('error');1770 pvp_01.removeAllListeners('direct-message');1771 pvp_01.removeAllListeners('finish');1772 pvp_01.removeAllListeners('model');1773 pvp_01.removeAllListeners('sync');1774 pvp_01.removeAllListeners('turn-message');1775 pvp_01.removeAllListeners('paused');1776 pvp_01.removeAllListeners('unpaused');1777 pvp_02.removeAllListeners('progress');1778 pvp_02.removeAllListeners('begin');1779 pvp_02.removeAllListeners('error');1780 pvp_02.removeAllListeners('direct-message');1781 pvp_02.removeAllListeners('finish');1782 pvp_02.removeAllListeners('model');1783 pvp_02.removeAllListeners('sync');1784 pvp_02.removeAllListeners('turn-message');1785 pvp_02.removeAllListeners('paused');1786 pvp_02.removeAllListeners('unpaused');1787 done();1788 }, 1000);1789 }1790 };1791 pvp_01.on('progress', () => done(new Error('WTF 1')));1792 pvp_01.on('begin', () => done(new Error('WTF 2')));1793 pvp_01.on('error', err => done(err));1794 pvp_01.on('direct-message', () => done(new Error('WTF 3')));1795 pvp_01.on('finish', () => done(new Error('WTF 4')));1796 pvp_01.on('model', () => done(new Error('WTF 5')));1797 pvp_01.on('sync', () => done(new Error('WTF 6')));1798 pvp_01.on('turn-message', () => done(new Error('WTF 7')));1799 pvp_01.on('paused', (theMessage, fromTs) => {1800 pauseArguments1 = [theMessage, fromTs];1801 callbackFn();1802 });1803 pvp_01.on('unpaused', () => done(new Error('WTF 9')));1804 pvp_02.on('progress', () => done(new Error('WTF 10')));1805 pvp_02.on('begin', () => done(new Error('WTF 11')));1806 pvp_02.on('error', err => done(err));1807 pvp_02.on('direct-message', () => done(new Error('WTF 12')));1808 pvp_02.on('finish', () => done(new Error('WTF 13')));1809 pvp_02.on('model', () => done(new Error('WTF 14')));1810 pvp_02.on('sync', () => done(new Error('WTF 15')));1811 pvp_02.on('turn-message', () => done(new Error('WTF 16')));1812 pvp_02.on('paused', (theMessage, fromTs) => {1813 pauseArguments2 = [theMessage, fromTs];1814 callbackFn();1815 });1816 pvp_02.on('unpaused', () => done(new Error('WTF 17')));1817 pvp_01.forceDisconnect();1818 });1819 it('Second should see the automatic finish', done => {1820 let callbackFn = response => {1821 expect(response).to.be.an.instanceof(GbaseResponse);1822 expect(response.ok).to.be.equal(true);1823 try{1824 expect(response.details.endMessage).to.be.equal('GR: auto gameover');1825 } catch(__){1826 try{1827 expect(response.details.endMessage).to.be.equal('GR: pair dead or ttl is out');1828 } catch(__){1829 expect(response.details.endMessage).to.be.equal('Pair was not found. It\'s done or ttl is out');1830 }1831 }1832 pvp_02.removeAllListeners('progress');1833 pvp_02.removeAllListeners('begin');1834 pvp_02.removeAllListeners('error');1835 pvp_02.removeAllListeners('direct-message');1836 pvp_02.removeAllListeners('finish');1837 pvp_02.removeAllListeners('sync');1838 pvp_02.removeAllListeners('turn-message');1839 pvp_02.removeAllListeners('paused');1840 pvp_02.removeAllListeners('unpaused');1841 setTimeout(done, 1000);1842 };1843 pvp_02.on('progress', () => done(new Error('WTF 1')));1844 pvp_02.on('begin', () => done(new Error('WTF 2')));1845 pvp_02.on('error', err => done(err));1846 pvp_02.on('direct-message', () => done(new Error('WTF 3')));1847 pvp_02.on('finish', callbackFn);1848 pvp_02.on('sync', () => done(new Error('WTF 5')));1849 pvp_02.on('turn-message', () => done(new Error('WTF 6')));1850 pvp_02.on('paused', () => done(new Error('WTF 7')));1851 pvp_02.on('unpaused', () => done(new Error('WTF 8')));1852 });1853 it('First should destroy local pvp', () => {1854 pvp_01.forceDestroyClient();1855 });1856 it('First player should list battle journal and see entry with auto=true', done => {1857 let callbackFn = (err, response) => {1858 expect(err).to.be.a('null');1859 expect(response).to.be.an.instanceof(GbaseResponse);1860 expect(response.ok).to.be.equal(true);1861 expect(response.details.originalResponse.l.length).to.be.equal(3);1862 expect(response.details.originalResponse.l[0].auto).to.be.equal(true);1863 done();1864 };1865 // We get a finish event independently of battle journal entry, so we give some penalty time to persist1866 setTimeout(() => gbaseApiStdl_01.pvp.battlesList(0, 20, false, callbackFn), 1000);1867 });1868 it('Second player should list battle journal and see entry with auto=true', done => {1869 let callbackFn = (err, response) => {1870 expect(err).to.be.a('null');1871 expect(response).to.be.an.instanceof(GbaseResponse);1872 expect(response.ok).to.be.equal(true);1873 expect(response.details.originalResponse.l.length).to.be.equal(3);1874 expect(response.details.originalResponse.l[0].auto).to.be.equal(true);1875 done();1876 };1877 // We get a finish event independently of battle journal entry, so we give some penalty time to persist1878 setTimeout(() => gbaseApiStdl_02.pvp.battlesList(0, 20, false, callbackFn), 1000);1879 });1880 });1881 });1882 describe('Player versus self', () => {1883 it('First should call dropMatchmaking', done => {1884 let callbackFn = (err, response) => {1885 expect(err).to.be.a('null');1886 expect(response).to.be.an.instanceof(GbaseResponse);1887 expect(response.ok).to.be.equal(true);1888 expect(response.details.originalResponse).to.have.property('forReal');1889 done();1890 };1891 gbaseApiStdl_01.pvp.dropMatchmaking(callbackFn);1892 });1893 var thePvp, pvpRoomData;1894 it('First player should begin game versus self', done => {1895 let callbackFn = (err, response) => {1896 expect(err).to.be.a('null');1897 expect(response).to.be.an.instanceof(GbaseResponse);1898 expect(response.ok).to.be.equal(true);1899 expect(response.details).to.have.property('pvp');1900 thePvp = response.details.pvp;1901 done();1902 };1903 gbaseApiStdl_01.pvp.beginVersusSelf(2, callbackFn);1904 });1905 it('First should receive progress messages', done => {1906 var begin = false, shouldBeModel = false, beenModel = false;1907 let callbackFn_Progress = msg => {1908 expect(EXPECTED_PROGRESS).to.include(msg);1909 };1910 let callbackFn_Begin = msg => {1911 if(msg){1912 expect(msg).to.be.equal(EXPECTED_BEGIN_MESSAGE);1913 } else {1914 shouldBeModel = true;1915 }1916 expect(thePvp).to.have.property('myPing');1917 expect(thePvp).to.have.property('opponentPing');1918 expect(thePvp).to.have.property('isPaused', false);1919 expect(thePvp.opponentPayload).to.deep.equal({ some: 'payload b', alsoBot: true });1920 expect(thePvp).to.have.property('startTimestamp');1921 expect(thePvp).to.have.property('randomSeed');1922 expect(thePvp).to.have.property('meIsPlayerA');1923 begin = true;1924 callbackFn();1925 };1926 let callbackFn_Model = msg => {1927 expect(msg).to.have.property('isA');1928 expect(msg).to.have.property('mdl');1929 expect(msg).to.have.property('playerTurnA', 0);1930 expect(msg).to.have.property('playerTurnB', 0);1931 expect(msg.mdl).to.have.property('model');1932 expect(msg.mdl).to.have.property('randomSeed');1933 expect(msg.mdl).to.have.property('startTs');1934 expect(shouldBeModel).to.be.equal(true);1935 expect(beenModel).to.be.equal(false);1936 beenModel = true;1937 callbackFn();1938 };1939 let callbackFn = () => {1940 if(begin && ((shouldBeModel && beenModel) || !shouldBeModel)){1941 thePvp.removeAllListeners('progress');1942 thePvp.removeAllListeners('begin');1943 thePvp.removeAllListeners('error');1944 thePvp.removeAllListeners('direct-message');1945 thePvp.removeAllListeners('finish');1946 thePvp.removeAllListeners('model');1947 thePvp.removeAllListeners('sync');1948 thePvp.removeAllListeners('turn-message');1949 thePvp.removeAllListeners('paused');1950 thePvp.removeAllListeners('unpaused');1951 done();1952 }1953 };1954 thePvp.on('progress', callbackFn_Progress);1955 thePvp.on('begin', callbackFn_Begin);1956 thePvp.on('error', err => done(err));1957 thePvp.on('direct-message', () => done(new Error('WTF 1')));1958 thePvp.on('finish', () => done(new Error('WTF 2')));1959 thePvp.on('model', callbackFn_Model);1960 thePvp.on('sync', () => done(new Error('WTF 4')));1961 thePvp.on('turn-message', () => done(new Error('WTF 5')));1962 thePvp.on('paused', () => done(new Error('WTF 6')));1963 thePvp.on('unpaused', () => done(new Error('WTF 7')));1964 thePvp.doConnect({ payload: '01' });1965 });1966 it(`First player should send ${HOW_MUCH_DIRECT} direct messages and get all of them`, done => {1967 var theMessagesCounter = 0;1968 let callbackFn_Message = msg => {1969 msg = msg.message;1970 if(theMessagesCounter === msg && msg < HOW_MUCH_DIRECT){1971 if(++theMessagesCounter === HOW_MUCH_DIRECT){1972 thePvp.removeAllListeners('progress');1973 thePvp.removeAllListeners('begin');1974 thePvp.removeAllListeners('error');1975 thePvp.removeAllListeners('direct-message');1976 thePvp.removeAllListeners('finish');1977 thePvp.removeAllListeners('model');1978 thePvp.removeAllListeners('sync');1979 thePvp.removeAllListeners('turn-message');1980 thePvp.removeAllListeners('paused');1981 thePvp.removeAllListeners('unpaused');1982 done();1983 }1984 } else {1985 done(new Error('WTF 9'));1986 }1987 };1988 thePvp.on('progress', () => done(new Error('WTF 1')));1989 thePvp.on('begin', () => done(new Error('WTF 2')));1990 thePvp.on('error', err => done(err));1991 thePvp.on('direct-message', callbackFn_Message);1992 thePvp.on('finish', () => done(new Error('WTF 3')));1993 thePvp.on('model', () => done(new Error('WTF 4')));1994 thePvp.on('sync', () => done(new Error('WTF 5')));1995 thePvp.on('turn-message', () => done(new Error('WTF 6')));1996 thePvp.on('paused', () => done(new Error('WTF 7')));1997 thePvp.on('unpaused', () => done(new Error('WTF 8')));1998 for(let i = 0 ; i < HOW_MUCH_DIRECT ; i++){1999 thePvp.sendDirect(i);2000 }2001 });2002 it(`The first should send ${HOW_MUCH_TURNS - 1} turn messages and get them all`, done => {2003 var theMessagesCounter = 0;2004 let callbackFn_Message = msg => {2005 msg = msg.m.message;2006 if(theMessagesCounter === msg && msg < HOW_MUCH_TURNS - 1){2007 if(++theMessagesCounter === HOW_MUCH_TURNS - 1){2008 thePvp.removeAllListeners('progress');2009 thePvp.removeAllListeners('begin');2010 thePvp.removeAllListeners('error');2011 thePvp.removeAllListeners('direct-message');2012 thePvp.removeAllListeners('finish');2013 thePvp.removeAllListeners('model');2014 thePvp.removeAllListeners('sync');2015 thePvp.removeAllListeners('turn-message');2016 thePvp.removeAllListeners('paused');2017 thePvp.removeAllListeners('unpaused');2018 done();2019 }2020 } else {2021 done(new Error('WTF 9'));2022 }2023 };2024 thePvp.on('progress', () => done(new Error('WTF 1')));2025 thePvp.on('begin', () => done(new Error('WTF 2')));2026 thePvp.on('error', err => done(err));2027 thePvp.on('direct-message', () => done(new Error('WTF 3')));2028 thePvp.on('finish', () => done(new Error('WTF 4')));2029 thePvp.on('model', () => done(new Error('WTF 5')));2030 thePvp.on('sync', () => done(new Error('WTF 6')));2031 thePvp.on('turn-message', callbackFn_Message);2032 thePvp.on('paused', () => done(new Error('WTF 7')));2033 thePvp.on('unpaused', () => done(new Error('WTF 8')));2034 for(let i = 0 ; i < HOW_MUCH_TURNS - 1 ; i++){2035 thePvp.sendTurn(i);2036 }2037 });2038 it('First player should disconnect', () => {2039 thePvp.removeAllListeners('progress');2040 thePvp.removeAllListeners('begin');2041 thePvp.removeAllListeners('error');2042 thePvp.removeAllListeners('direct-message');2043 thePvp.removeAllListeners('finish');2044 thePvp.removeAllListeners('model');2045 thePvp.removeAllListeners('sync');2046 thePvp.removeAllListeners('turn-message');2047 thePvp.removeAllListeners('paused');2048 thePvp.removeAllListeners('unpaused');2049 thePvp.forceDestroyClient();2050 });2051 it('First should pull checkBattleNoSearch', done => {2052 let callbackFn = (err, response) => {2053 expect(err).to.be.a('null');2054 expect(response).to.be.an.instanceof(GbaseResponse);2055 expect(response.ok).to.be.equal(true);2056 expect(response.details.originalResponse.stat).to.be.equal('MM: gameroom allocated');2057 pvpRoomData = response.details.originalResponse;2058 done();2059 };2060 gbaseApiStdl_01.pvp.checkBattleNoSearch(callbackFn);2061 });2062 it('First should reconnect', done => {2063 let callbackFn = (err, response) => {2064 expect(err).to.be.a('null');2065 expect(response).to.be.an.instanceof(GbaseResponse);2066 expect(response.ok).to.be.equal(true);2067 expect(response.details).to.have.property('pvp');2068 thePvp = response.details.pvp;2069 done();2070 };2071 gbaseApiStdl_01.pvp.beginOnAddressAndKey(pvpRoomData, callbackFn);2072 });2073 it('First should get "sync" event', done => {2074 var theBegin = false, theSync = false;2075 let callbackFn_Begin = msg => {2076 expect(msg).to.be.a('undefined');2077 theBegin = true;2078 callbackFn();2079 };2080 let callbackFn_Sync = msg => {2081 expect(msg).to.have.property('isA');2082 expect(msg).to.have.property('playerTurnA');2083 expect(msg).to.have.property('playerTurnB');2084 expect(msg).to.have.property('mdl');2085 expect(msg.mdl).to.have.property('model');2086 expect(msg.mdl).to.have.property('randomSeed');2087 expect(msg.mdl).to.have.property('startTs');2088 theSync = true;2089 callbackFn();2090 };2091 let callbackFn = () => {2092 if(theBegin && theSync){2093 thePvp.removeAllListeners('progress');2094 thePvp.removeAllListeners('begin');2095 thePvp.removeAllListeners('error');2096 thePvp.removeAllListeners('direct-message');2097 thePvp.removeAllListeners('finish');2098 thePvp.removeAllListeners('model');2099 thePvp.removeAllListeners('sync');2100 thePvp.removeAllListeners('turn-message');2101 thePvp.removeAllListeners('paused');2102 thePvp.removeAllListeners('unpaused');2103 done();2104 }2105 };2106 thePvp.on('progress', () => done(new Error('WTF 1')));2107 thePvp.on('begin', callbackFn_Begin);2108 thePvp.on('error', err => done(err));2109 thePvp.on('direct-message', () => done(new Error('WTF 3')));2110 thePvp.on('finish', () => done(new Error('WTF 4')));2111 thePvp.on('model', () => done(new Error('WTF 5')));2112 thePvp.on('sync', callbackFn_Sync);2113 thePvp.on('turn-message', () => done(new Error('WTF 6')));2114 thePvp.on('paused', () => done(new Error('WTF 7')));2115 thePvp.on('unpaused', () => done(new Error('WTF 8')));2116 });2117 it(`First player should finalize pvp by sending ${HOW_MUCH_TURNS}th turn`, done => {2118 let callbackFn_Finish = msg => {2119 expect(msg.ok).to.be.equal(true);2120 expect(msg.details.endMessage).to.have.property('gameIsOver', true);2121 expect(msg.details.endMessage).to.have.property('finalm');2122 expect(msg.details.endMessage.finalm).to.have.property('m');2123 expect(msg.details.endMessage.finalm).to.have.property('asq', HOW_MUCH_TURNS);2124 expect(msg.details.endMessage.finalm).to.have.property('bsq', 0);2125 expect(msg.details.endMessage.finalm.m).to.deep.equal({ message: 'FIN!' });2126 thePvp.removeAllListeners('progress');2127 thePvp.removeAllListeners('begin');2128 thePvp.removeAllListeners('error');2129 thePvp.removeAllListeners('direct-message');2130 thePvp.removeAllListeners('finish');2131 thePvp.removeAllListeners('model');2132 thePvp.removeAllListeners('sync');2133 thePvp.removeAllListeners('turn-message');2134 thePvp.removeAllListeners('paused');2135 thePvp.removeAllListeners('unpaused');2136 done();2137 };2138 thePvp.on('progress', () => done(new Error('WTF 1')));2139 thePvp.on('begin', () => done(new Error('WTF 2')));2140 thePvp.on('error', err => done(err));2141 thePvp.on('direct-message', () => done(new Error('WTF 3')));2142 thePvp.on('finish', callbackFn_Finish);2143 thePvp.on('model', () => done(new Error('WTF 4')));2144 thePvp.on('sync', () => done(new Error('WTF 5')));2145 thePvp.on('turn-message', () => done(new Error('WTF 6')));2146 thePvp.on('paused', () => done(new Error('WTF 7')));2147 thePvp.on('unpaused', () => done(new Error('WTF 8')));2148 thePvp.sendTurn('FIN!');2149 });2150 });2151 for(let i = 0 ; i < 30 ; i++){2152 describe(`WTF! #${i + 1}`, () => {2153 var pvpPlayer_01, pvpPlayer_02;2154 it('Should done step 1', () => {2155 pvpPlayer_01 = new GbaseApi(null, null, HMAC_SECRET, 'stdl', '0.0.2', LOCAL_ADDRESS);2156 pvpPlayer_02 = new GbaseApi(null, null, HMAC_SECRET, 'stdl', '0.0.2', LOCAL_ADDRESS);2157 });2158 it('Should done step 2.1', done => {2159 let callbackFn = (err, response) => {2160 expect(err).to.be.a('null');2161 expect(response).to.be.an.instanceof(GbaseResponse);2162 expect(response.ok).to.be.equal(true);2163 done();2164 };2165 pvpPlayer_01.account.signupGbaseAnon(callbackFn);2166 });2167 it('Should done step 2.2', done => {2168 let callbackFn = (err, response) => {2169 expect(err).to.be.a('null');2170 expect(response).to.be.an.instanceof(GbaseResponse);2171 expect(response.ok).to.be.equal(true);2172 done();2173 };2174 pvpPlayer_02.account.signupGbaseAnon(callbackFn);2175 });2176 it('Should done step 3.1', done => {2177 let callbackFn = (err, response) => {2178 expect(err).to.be.a('null');2179 expect(response).to.be.an.instanceof(GbaseResponse);2180 expect(response.ok).to.be.equal(true);2181 done();2182 };2183 pvpPlayer_01.profile.create(callbackFn);2184 });2185 it('Should done step 3.2', done => {2186 let callbackFn = (err, response) => {2187 expect(err).to.be.a('null');2188 expect(response).to.be.an.instanceof(GbaseResponse);2189 expect(response.ok).to.be.equal(true);2190 done();2191 };2192 pvpPlayer_02.profile.create(callbackFn);2193 });2194 it('Should done step 4.1', done => {2195 let callbackFn = (err, response) => {2196 expect(err).to.be.a('null');2197 expect(response).to.be.an.instanceof(GbaseResponse);2198 expect(response.ok).to.be.equal(true);2199 done();2200 };2201 pvpPlayer_01.leaderboards.postRecord(12345, FROM_SEGMENT, callbackFn);2202 });2203 it('Should done step 4.2', done => {2204 let callbackFn = (err, response) => {2205 expect(err).to.be.a('null');2206 expect(response).to.be.an.instanceof(GbaseResponse);2207 expect(response.ok).to.be.equal(true);2208 done();2209 };2210 pvpPlayer_02.leaderboards.postRecord(12345, FROM_SEGMENT, callbackFn);2211 });2212 var pvp_01, pvp_02;2213 it('Should done step 5', done => {2214 let callbackFn_01 = (err, response) => {2215 expect(err).to.be.a('null');2216 expect(response).to.be.an.instanceof(GbaseResponse);2217 expect(response.ok).to.be.equal(true);2218 pvp_01 = response.details.pvp;2219 callbackFn_Final();2220 };2221 let callbackFn_02 = (err, response) => {2222 expect(err).to.be.a('null');2223 expect(response).to.be.an.instanceof(GbaseResponse);2224 expect(response.ok).to.be.equal(true);2225 pvp_02 = response.details.pvp;2226 callbackFn_Final();2227 };2228 let callbackFn_Final = () => {2229 if(pvp_01 && pvp_02){2230 done();2231 }2232 };2233 pvpPlayer_01.pvp.withOpponent(2234 'segma', GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,2235 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),2236 60, callbackFn_012237 );2238 pvpPlayer_02.pvp.withOpponent(2239 'segma', GbaseApi.MATCHMAKING_STRATEGIES.BY_RATING,2240 new GbaseRangePicker('any').range(GbaseRangePicker.NEGATIVE_INFINITY, GbaseRangePicker.POSITIVE_INFINITY),2241 60, callbackFn_022242 );2243 });2244 it('Should done step 6', done => {2245 var begin_01 = false, begin_02 = false;2246 let callbackFn_Begin = i => {2247 if(i === 0){2248 begin_01 = true;2249 callbackFn();2250 } else if(i === 1){2251 begin_02 = true;2252 callbackFn();2253 }2254 };2255 let callbackFn = () => {2256 if(begin_01 && begin_02){2257 pvp_01.removeAllListeners('begin');2258 pvp_01.removeAllListeners('error');2259 pvp_02.removeAllListeners('begin');2260 pvp_02.removeAllListeners('error');2261 done();2262 }2263 };2264 pvp_01.on('begin', msg => callbackFn_Begin(0, msg));2265 pvp_01.on('error', err => console.error(err));2266 pvp_02.on('begin', msg => callbackFn_Begin(1, msg));2267 pvp_02.on('error', err => console.error(err));2268 pvp_01.doConnect({ payload: '01' });2269 pvp_02.doConnect({ payload: '02' });2270 });2271 it('Should done step 7.1', done => {2272 var theMessagesCounter = 0;2273 let callbackFn_Message = msg => {2274 msg = msg.m.message;2275 if(theMessagesCounter === msg && msg < 14){2276 if(++theMessagesCounter === 14){2277 pvp_02.removeAllListeners('turn-message');2278 done();2279 }2280 }2281 };2282 pvp_02.on('turn-message', callbackFn_Message);2283 for(let i = 0 ; i < 14 ; i++){2284 pvp_01.sendTurn(i);2285 }2286 });2287 it('Should done step 7.2', done => {2288 var theMessagesCounter = 0;2289 let callbackFn_Message = msg => {2290 msg = msg.m.message;2291 if(theMessagesCounter === msg && msg < 14){2292 if(++theMessagesCounter === 14){2293 pvp_01.removeAllListeners('turn-message');2294 done();2295 }2296 }2297 };2298 pvp_01.on('turn-message', callbackFn_Message);2299 for(let i = 0 ; i < 14 ; i++){2300 pvp_02.sendTurn(i);2301 }2302 });2303 it('Should done step 8', done => {2304 let firstIsDone = false, secondIsDone = false;2305 let callbackFn_Finish = i => {2306 if(i === 0){2307 firstIsDone = true;2308 } else if(i === 1){2309 secondIsDone = true;2310 }2311 if(firstIsDone && secondIsDone){2312 pvp_01.removeAllListeners('error');2313 pvp_01.removeAllListeners('finish');2314 pvp_02.removeAllListeners('error');2315 pvp_02.removeAllListeners('finish');2316 done();2317 }2318 };2319 pvp_01.on('finish', msg => callbackFn_Finish(0, msg));2320 pvp_01.on('error', err => console.error(err));2321 pvp_02.on('finish', msg => callbackFn_Finish(1, msg));2322 pvp_02.on('error', err => console.error(err));2323 pvp_01.sendTurn('FIN!');2324 });2325 it('Should done step 9.1', done => {2326 let callbackFn = (err, response) => {2327 expect(err).to.be.a('null');2328 expect(response).to.be.an.instanceof(GbaseResponse);2329 expect(response.ok).to.be.equal(true);...
issue_107.js
Source:issue_107.js
...189 it('First player should connect ws with gameroom', done => {190 let callbackFn = () => {191 if(openIsOk && messageIsOkay){192 expect(theMessage).to.deep.equal({ c: 0, m: 'GR: pair allocated. Wait for opponent' });193 wsConnection1.removeAllListeners('error');194 wsConnection1.removeAllListeners('open');195 wsConnection1.removeAllListeners('message');196 wsConnection1.removeAllListeners('close');197 done();198 }199 };200 wsConnection1 = new WebSocket(`ws://${gameroomHost}:${gameroomPort}/?bkey=${bookingKey1}&pv=${_PLATFORM_VERSION}`);201 var openIsOk = false, messageIsOkay = false, theMessage;202 wsConnection1.on('error', err => done(err));203 wsConnection1.on('open', () => {204 if(!openIsOk){205 openIsOk = true;206 callbackFn();207 } else {208 done(new Error('WTF 1'));209 }210 });211 wsConnection1.on('message', message => {212 if(!messageIsOkay){213 messageIsOkay = true;214 theMessage = JSON.parse(message);215 callbackFn();216 } else {217 done(new Error('WTF 2'));218 }219 });220 wsConnection1.on('close', () => done(new Error('WTF 3')));221 });222 it('Second player should release booking and first player should get knowledgeable about it', done => {223 var releaseIsOkay = false, wsMessageIsOkay = false, theMessage;224 let generalCallbackFn = () => {225 if(releaseIsOkay && wsMessageIsOkay){226 expect(theMessage).to.deep.equal({ p: 1, m: 'PRGS: all players connected' });227 wsConnection1.removeAllListeners('error');228 wsConnection1.removeAllListeners('open');229 wsConnection1.removeAllListeners('message');230 wsConnection1.removeAllListeners('close');231 done();232 }233 };234 wsConnection1.on('open', () => done(new Error('WTF 1')));235 wsConnection1.on('close', () => done(new Error('WTF 2')));236 wsConnection1.on('error', err => done(err));237 wsConnection1.on('message', msg => {238 if(!wsMessageIsOkay){239 theMessage = JSON.parse(msg);240 wsMessageIsOkay = true;241 generalCallbackFn();242 } else {243 done(new Error('WTF 3'));244 }245 });246 let callbackFn = (err, response, body) => {247 expect(err).to.be.a('null');248 expect(response.statusCode).to.be.equal(200);249 expect(body).to.deep.equal({ c: 1, m: 'GR: pair formed' });250 releaseIsOkay = true;251 generalCallbackFn();252 };253 testUtils.pvp.thePost(gameroomHost, gameroomPort, 'releaseBooking', null, null, bookingKey2, callbackFn);254 });255 it('Second player should connect ws with gameroom', done => {256 let callbackFn = () => {257 if(openIsOk && messageIsOkay){258 expect(theMessage).to.deep.equal({ c: 1, m: 'GR: pair formed' });259 wsConnection2.removeAllListeners('error');260 wsConnection2.removeAllListeners('open');261 wsConnection2.removeAllListeners('message');262 wsConnection2.removeAllListeners('close');263 done();264 }265 };266 wsConnection2 = new WebSocket(`ws://${gameroomHost}:${gameroomPort}/?bkey=${bookingKey2}&pv=${_PLATFORM_VERSION}`);267 var openIsOk = false, messageIsOkay = false, theMessage;268 wsConnection2.on('error', err => done(err));269 wsConnection2.on('open', () => {270 if(!openIsOk){271 openIsOk = true;272 callbackFn();273 } else {274 done(new Error('WTF 1'));275 }276 });277 wsConnection2.on('message', message => {278 if(!messageIsOkay){279 messageIsOkay = true;280 theMessage = JSON.parse(message);281 callbackFn();282 } else {283 done(new Error('WTF 2'));284 }285 });286 wsConnection2.on('close', () => done(new Error('WTF 3')));287 });288 it('First player should ping pre game room', done => {289 let callbackFn = () => {290 wsConnection1.removeAllListeners('error');291 wsConnection1.removeAllListeners('open');292 wsConnection1.removeAllListeners('message');293 wsConnection1.removeAllListeners('close');294 done();295 };296 wsConnection1.on('error', err => done(err));297 wsConnection1.on('open', () => done(new Error('WTF 1')));298 wsConnection1.on('message', callbackFn);299 wsConnection1.on('close', () => done(new Error('WTF 2')));300 let message = { ping: 10 },301 sign = `/${JSON.stringify(message)}${bookingKey1}default`;302 message.sign = crypto.createHash('sha256').update(Buffer.from(sign), 'binary').digest('hex');303 wsConnection1.send(JSON.stringify(message));304 });305 it('Second player should ping pre game room', done => {306 let callbackFn = () => {307 wsConnection2.removeAllListeners('error');308 wsConnection2.removeAllListeners('open');309 wsConnection2.removeAllListeners('message');310 wsConnection2.removeAllListeners('close');311 done();312 };313 wsConnection2.on('error', err => done(err));314 wsConnection2.on('open', () => done(new Error('WTF 1')));315 wsConnection2.on('message', callbackFn);316 wsConnection2.on('close', () => done(new Error('WTF 2')));317 let message = { ping: 10 },318 sign = `/${JSON.stringify(message)}${bookingKey1}default`;319 message.sign = crypto.createHash('sha256').update(Buffer.from(sign), 'binary').digest('hex');320 wsConnection2.send(JSON.stringify(message));321 });322 it('First player should set payload', done => {323 wsConnection1.on('error', err => done(err));324 wsConnection1.on('open', () => done(new Error('WTF 1')));325 wsConnection1.on('message', () => done(new Error('WTF 2')));326 wsConnection1.on('close', () => done(new Error('WTF 3')));327 wsConnection2.on('error', err => done(err));328 wsConnection2.on('open', () => done(new Error('WTF 4')));329 wsConnection2.on('message', () => done(new Error('WTF 5')));330 wsConnection2.on('close', () => done(new Error('WTF 6')));331 let callbackFn = (err, response, body) => {332 expect(err).to.be.a('null');333 expect(response.statusCode).to.be.equal(200);334 expect(body).to.deep.equal({ c: 1, m: 'GR: payload set' });335 wsConnection1.removeAllListeners('error');336 wsConnection1.removeAllListeners('open');337 wsConnection1.removeAllListeners('message');338 wsConnection1.removeAllListeners('close');339 wsConnection2.removeAllListeners('error');340 wsConnection2.removeAllListeners('open');341 wsConnection2.removeAllListeners('message');342 wsConnection2.removeAllListeners('close');343 done();344 };345 testUtils.pvp.thePost(gameroomHost, gameroomPort, 'setPayload', null, {346 player: 1, payload: 'alpha'347 }, bookingKey1, callbackFn);348 });349 it('Second player should set payload', done => {350 var setPayloadIsOkay = false, firstMessageIsOkay = false, secondMessageIsOkay = false,351 message1, message2;352 let generalCallbackFn = () => {353 if(setPayloadIsOkay && firstMessageIsOkay && secondMessageIsOkay){354 expect(message1).to.deep.equal({ p: 2, m: 'PRGS: all payloads set', isA: true, oppPayload: { player: 2, payload: 'beta' } });355 expect(message2).to.deep.equal({ p: 2, m: 'PRGS: all payloads set', isA: false, oppPayload: { player: 1, payload: 'alpha' } });356 wsConnection1.removeAllListeners('error');357 wsConnection1.removeAllListeners('open');358 wsConnection1.removeAllListeners('message');359 wsConnection1.removeAllListeners('close');360 wsConnection2.removeAllListeners('error');361 wsConnection2.removeAllListeners('open');362 wsConnection2.removeAllListeners('message');363 wsConnection2.removeAllListeners('close');364 done();365 }366 };367 wsConnection1.on('error', err => done(err));368 wsConnection1.on('open', () => done(new Error('WTF 1')));369 wsConnection1.on('message', msg => {370 if(!firstMessageIsOkay){371 firstMessageIsOkay = true;372 message1 = JSON.parse(msg);373 generalCallbackFn();374 } else {375 done(new Error('WTF 2'));376 }377 });378 wsConnection1.on('close', () => done(new Error('WTF 3')));379 wsConnection2.on('error', err => done(err));380 wsConnection2.on('open', () => done(new Error('WTF 4')));381 wsConnection2.on('message', msg => {382 if(!secondMessageIsOkay){383 secondMessageIsOkay = true;384 message2 = JSON.parse(msg);385 generalCallbackFn();386 } else {387 done(new Error('WTF 5'));388 }389 });390 wsConnection2.on('close', () => done(new Error('WTF 6')));391 let callbackFn = (err, response, body) => {392 expect(err).to.be.a('null');393 expect(response.statusCode).to.be.equal(200);394 expect(body).to.deep.equal({ c: 2, m: 'GR: set ready' });395 setPayloadIsOkay = true;396 generalCallbackFn();397 };398 testUtils.pvp.thePost(gameroomHost, gameroomPort, 'setPayload', null, {399 player: 2, payload: 'beta'400 }, bookingKey2, callbackFn);401 });402 it('First player should set ready', done => {403 let callbackFn = (err, response, body) => {404 expect(err).to.be.a('null');405 expect(response.statusCode).to.be.equal(200);406 expect(body).to.deep.equal({ c: 2, m: 'GR: waiting opponent', oppPayload: { player: 2, payload: 'beta' } });407 done();408 };409 testUtils.pvp.thePost(gameroomHost, gameroomPort, 'setReady', null, null, bookingKey1, callbackFn);410 });411 it('Second player should set ready', done => {412 let callbackFn = (err, response, body) => {413 expect(err).to.be.a('null');414 expect(response.statusCode).to.be.equal(200);415 expect(body).to.have.property('randomSeed');416 expect(body).to.have.property('startTs');417 expect(body).to.have.property('isA');418 delete body.randomSeed;419 delete body.startTs;420 delete body.isA;421 expect(body).to.deep.equal({ p: 4, c: 3, m: 'GR: gameplay model established', oppPayload: { player: 1, payload: 'alpha' } });422 done();423 };424 testUtils.pvp.thePost(gameroomHost, gameroomPort, 'setReady', null, null, bookingKey2, callbackFn);425 });426 it('First player should ping pre game room', done => {427 let callbackFn = () => {428 wsConnection1.removeAllListeners('error');429 wsConnection1.removeAllListeners('open');430 wsConnection1.removeAllListeners('message');431 wsConnection1.removeAllListeners('close');432 done();433 };434 wsConnection1.on('error', err => done(err));435 wsConnection1.on('open', () => done(new Error('WTF 1')));436 wsConnection1.on('message', callbackFn);437 wsConnection1.on('close', () => done(new Error('WTF 2')));438 let message = { ping: 10 },439 sign = `/${JSON.stringify(message)}${bookingKey1}default`;440 message.sign = crypto.createHash('sha256').update(Buffer.from(sign), 'binary').digest('hex');441 wsConnection1.send(JSON.stringify(message));442 });443 it('Second player should ping pre game room', done => {444 let callbackFn = () => {445 wsConnection2.removeAllListeners('error');446 wsConnection2.removeAllListeners('open');447 wsConnection2.removeAllListeners('message');448 wsConnection2.removeAllListeners('close');449 done();450 };451 wsConnection2.on('error', err => done(err));452 wsConnection2.on('open', () => done(new Error('WTF 1')));453 wsConnection2.on('message', callbackFn);454 wsConnection2.on('close', () => done(new Error('WTF 2')));455 let message = { ping: 10 },456 sign = `/${JSON.stringify(message)}${bookingKey1}default`;457 message.sign = crypto.createHash('sha256').update(Buffer.from(sign), 'binary').digest('hex');458 wsConnection2.send(JSON.stringify(message));459 });460});461describe('After stuff', () => {462 it('Should clean utils cache', () => {...
event.ts
Source:event.ts
...25 emit(event: 'send', msg: string): void;26 emit(event: 'message', msg: string): void;27 emit(event: 'connect'): void;28 emit(event: 'disconnect'): void;29 removeAllListeners(event: 'send'): void30 removeAllListeners(event: 'message'): void31 removeAllListeners(event: 'connect'): void32 removeAllListeners(event: 'disconnect'): void33}34interface BotEvent {35 on(event: 'login', listener: () => void): void;36 on(event: 'UserList', listener: (msg: UserList[]) => void): void;37 on(event: 'PublicMessage', listener: (msg: PublicMessage) => void): void;38 on(event: 'PrivateMessage', listener: (msg: PrivateMessage) => void): void;39 on(event: 'LeaveRoom', listener: (msg: SystemMessage) => void): void;40 on(event: 'JoinRoom', listener: (msg: SystemMessage) => void): void;41 on(event: 'damaku', listener: (msg: Damaku) => void): void;42 on(event: 'like', listener: (msg: Like) => void): void;43 on(event: 'SwitchRoom', listener: (msg: SwitchRoom) => void): void;44 on(event: 'music', listener: (msg: Music) => void): void;45 on(event: 'paymentCallback', listener: (msg: paymentCallback) => void): void;46 on(event: 'GetUserListCallback', listener: (msg: GetUserListCallback[]) => void): void;47 on(event: 'UserProfileCallback', listener: (msg: UserProfileCallback) => void): void;48 on(event: 'BankCallback', listener: (msg: BankCallback) => void): void;49 on(event: 'MediaListCallback', listener: (msg: MediaListCallback[]) => void): void;50 on(event: 'SelfMove', listener: (msg: SelfMove) => void): void;51 on(event: 'payment', listener: (msg: Payment) => void): void;52 on(event: 'roomNotice', listener: (msg: RoomNotice) => void): void;53 on(event: 'follower', listener: (msg: Follower) => void): void;54 once(event: 'login', listener: () => void): void;55 once(event: 'UserList', listener: (msg: UserList[]) => void): void;56 once(event: 'PublicMessage', listener: (msg: PublicMessage) => void): void;57 once(event: 'PrivateMessage', listener: (msg: PrivateMessage) => void): void;58 once(event: 'LeaveRoom', listener: (msg: SystemMessage) => void): void;59 once(event: 'JoinRoom', listener: (msg: SystemMessage) => void): void;60 once(event: 'damaku', listener: (msg: Damaku) => void): void;61 once(event: 'like', listener: (msg: Like) => void): void;62 once(event: 'SwitchRoom', listener: (msg: SwitchRoom) => void): void;63 once(event: 'music', listener: (msg: Music) => void): void;64 once(event: 'paymentCallback', listener: (msg: paymentCallback) => void): void;65 once(event: 'GetUserListCallback', listener: (msg: GetUserListCallback[]) => void): void;66 once(event: 'UserProfileCallback', listener: (msg: UserProfileCallback) => void): void;67 once(event: 'BankCallback', listener: (msg: BankCallback) => void): void;68 once(event: 'MediaListCallback', listener: (msg: MediaListCallback[]) => void): void;69 once(event: 'SelfMove', listener: (msg: SelfMove) => void): void;70 once(event: 'payment', listener: (msg: Payment) => void): void;71 once(event: 'roomNotice', listener: (msg: RoomNotice) => void): void;72 once(event: 'follower', listener: (msg: Follower) => void): void;73 emit(event: 'login'): void;74 emit(event: 'UserList', msg: UserList[]): void;75 emit(event: 'PublicMessage', msg: PublicMessage): void;76 emit(event: 'PrivateMessage', msg: PrivateMessage): void;77 emit(event: 'LeaveRoom', msg: SystemMessage): void;78 emit(event: 'JoinRoom', msg: SystemMessage): void;79 emit(event: 'damaku', msg: Damaku): void;80 emit(event: 'like', msg: Like): void;81 emit(event: 'SwitchRoom', msg: SwitchRoom): void;82 emit(event: 'music', msg: Music): void;83 emit(event: 'paymentCallback', msg: paymentCallback): void;84 emit(event: 'GetUserListCallback', msg: GetUserListCallback[]): void;85 emit(event: 'UserProfileCallback', msg: UserProfileCallback): void;86 emit(event: 'BankCallback', msg: BankCallback): void;87 emit(event: 'MediaListCallback', msg: MediaListCallback[]): void;88 emit(event: 'SelfMove', msg: SelfMove): void;89 emit(event: 'payment', msg: Payment): void;90 emit(event: 'roomNotice', msg: RoomNotice): void;91 emit(event: 'follower', msg: Follower): void;92 removeAllListeners(event: 'login'): void93 removeAllListeners(event: 'UserList'): void94 removeAllListeners(event: 'PublicMessage'): void95 removeAllListeners(event: 'PrivateMessage'): void96 removeAllListeners(event: 'LeaveRoom'): void97 removeAllListeners(event: 'JoinRoom'): void98 removeAllListeners(event: 'damaku'): void99 removeAllListeners(event: 'like'): void100 removeAllListeners(event: 'SwitchRoom'): void101 removeAllListeners(event: 'music'): void102 removeAllListeners(event: 'paymentCallback'): void103 removeAllListeners(event: 'GetUserListCallback'): void104 removeAllListeners(event: 'UserProfileCallback'): void105 removeAllListeners(event: 'BankCallback'): void106 removeAllListeners(event: 'MediaListCallback'): void107 removeAllListeners(event: 'SelfMove'): void108 removeAllListeners(event: 'payment'): void109 removeAllListeners(event: 'roomNotice'): void110 removeAllListeners(event: 'follower'): void111}112export const WebSocket: WebSocketEvent = new EventEmitter()113export const Bot: BotEvent = new EventEmitter()114// @ts-ignore...
index.js
Source:index.js
...24 mainWindow = null25 })26 // Clear all listeners on reload.27 window.on('reload', () => {28 window.removeAllListeners('move')29 window.removeAllListeners('resize')30 window.removeAllListeners('restore')31 window.removeAllListeners('maximize')32 window.removeAllListeners('unmaximize')33 window.removeAllListeners('enter-full-screen')34 window.removeAllListeners('leave-full-screen')35 window.removeAllListeners('enter-html-full-screen')36 window.removeAllListeners('leave-html-full-screen')37 })38 window.webContents.on('devtools-opened', () => {39 window.focus()40 setImmediate(() => {41 window.focus()42 })43 })44 return window45}46// quit application when all windows are closed47app.on('window-all-closed', () => {48 // on macOS it is common for applications to stay open until the user explicitly quits49 if (process.platform !== 'darwin') {50 app.quit()...
cmdListeners.js
Source:cmdListeners.js
...32 eventHandler('messageReactionAdd')(bot, msgReaction, user)33 })34}35exports.removeAllListeners = function(bot) {36 bot.removeAllListeners('message')37 bot.removeAllListeners('guildCreate')38 bot.removeAllListeners('guildUpdate')39 bot.removeAllListeners('guildDelete')40 bot.removeAllListeners('channelDelete')41 bot.removeAllListeners('roleUpdate')42 bot.removeAllListeners('roleDelete')...
Using AI Code Generation
1const { removeAllListeners } = require('storybook-root-cause');2removeAllListeners();3const { removeListener } = require('storybook-root-cause');4removeListener();5const { removeAllListeners } = require('storybook-root-cause');6removeAllListeners();7const { removeListener } = require('storybook-root-cause');8removeListener();9const { removeAllListeners } = require('storybook-root-cause');10removeAllListeners();11const { removeListener } = require('storybook-root-cause');12removeListener();13const { removeAllListeners } = require('storybook-root-cause');14removeAllListeners();15const { removeListener } = require('storybook-root-cause');16removeListener();17const { removeAllListeners } = require('storybook-root-cause');18removeAllListeners();19const { removeListener } = require('storybook-root-cause');20removeListener();21const { removeAllListeners } = require('storybook-root-cause');22removeAllListeners();23const { removeListener } = require('storybook-root-cause');24removeListener();25const { removeAllListeners } = require('storybook-root-cause');26removeAllListeners();27const { removeListener } = require('storybook-root-cause');28removeListener();
Using AI Code Generation
1const { removeAllListeners } = require('storybook-root-cause');2removeAllListeners();3const { removeListener } = require('storybook-root-cause');4removeListener('click');5const { removeListenersByType } = require('storybook-root-cause');6removeListenersByType('click');7const { removeListenersByElement } = require('storybook-root-cause');8removeListenersByElement(element);9const { removeListenersBySelector } = require('storybook-root-cause');10removeListenersBySelector('selector');11const { removeListenersByElementAndType } = require('storybook-root-cause');12removeListenersByElementAndType(element, 'click');13const { removeListenersBySelectorAndType } = require('storybook-root-cause');14removeListenersBySelectorAndType('selector', 'click');15const { removeListenersByElementAndSelector } = require('storybook-root-cause');16removeListenersByElementAndSelector(element, 'selector');17const { removeListenersBySelectorAndSelector } = require('storybook-root-cause');18removeListenersBySelectorAndSelector('selector', 'selector');19const { removeListenersByElementAndSelectorAndType } = require('storybook-root-cause');20removeListenersByElementAndSelectorAndType(element, 'selector', 'click');21const { removeListenersBySelectorAndSelectorAndType } = require('storybook-root-cause');22removeListenersBySelectorAndSelectorAndType('selector', 'selector', 'click');23const { removeListenersByElementAndSelectorAndTypeAndCapture } = require('
Using AI Code Generation
1import { removeAllListeners } from 'storybook-root';2import { removeAllListeners } from 'storybook-root';3import { removeAllListeners } from 'storybook-root';4import { removeAllListeners } from 'storybook-root';5import { removeAllListeners } from 'storybook-root';6import { removeAllListeners } from 'storybook-root';7import { removeAllListeners } from 'storybook-root';8import { removeAllListeners } from 'storybook-root';9import { removeAllListeners } from 'storybook-root';10import { removeAllListeners } from 'storybook-root';11import { removeAllListeners } from 'storybook-root';12import { removeAllListeners } from 'storybook-root';13import { removeAllListeners } from 'storybook-root';
Using AI Code Generation
1const { removeAllListeners } = require('storybook-root-logger');2removeAllListeners();3import { removeAllListeners } from 'storybook-root-logger';4removeAllListeners();5const { removeAllListeners } = require('storybook-root-logger');6removeAllListeners();7import { removeAllListeners } from 'storybook-root-logger';8removeAllListeners();9The MIT License (MIT) Copyright (c) 2020 Pavan Kumar Sunkara
Using AI Code Generation
1import { removeAllListeners } from 'storybook-root';2import { withInfo } from '@storybook/addon-info';3import { withKnobs } from '@storybook/addon-knobs';4removeAllListeners();5export default {6};7export const withText = () => <Button>Hello Button</Button>;8withText.story = {9 parameters: {10 info: {11 },12 },13};14export const withEmoji = () => <Button>😀 😎 👍 💯</Button>;15withEmoji.story = {16 parameters: {17 info: {18 },19 },20};21export const withSomeEmojiAndText = () => (22);23withSomeEmojiAndText.story = {24 parameters: {25 info: {26 },27 },28};
Using AI Code Generation
1import { removeAllListeners } from 'storybook-root';2removeAllListeners();3import { removeAllListeners } from 'storybook-root';4test('removeAllListeners', () => {5 removeAllListeners();6});7import { removeAllListeners } from 'storybook-root';8removeAllListeners();9import { removeAllListeners } from 'storybook-root';10removeAllListeners();11import { removeAllListeners } from 'storybook-root';12removeAllListeners();13import { removeAllListeners } from 'storybook-root';14removeAllListeners();15import { removeAllListeners } from 'storybook-root';16removeAllListeners();17import { removeAllListeners } from 'storybook-root';18removeAllListeners();19import { removeAllListeners } from 'storybook-root';20removeAllListeners();21import { removeAllListeners } from 'storybook-root';22removeAllListeners();23import { removeAllListeners } from 'storybook-root';24removeAllListeners();25import { removeAllListeners } from 'storybook-root';26removeAllListeners();27import { removeAllListeners } from 'storybook-root';28removeAllListeners();29import { removeAllListeners } from 'storybook-root';30removeAllListeners();31import { removeAllListeners } from 'storybook-root';32removeAllListeners();
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!!