Example #1
0
 it("Sets the game name if it is allowed", () => {
   const spy: SinonSpy = sinon.spy();
   element.element.value = allowedName;
   subscribe(channel, spy);
   expect(nameInput(element)).to.equal(allowedName);
   expect(spy.calledWith(allowedName)).to.equal(true);
 });
Example #2
0
  describe('applyHeaders', () => {
    let normalizeSpy: SinonSpy;
    let updateSpy: SinonSpy;

    beforeEach(() => {
      normalizeSpy = sinon.spy(instance, 'normalize');
      updateSpy    = sinon.spy(instance, 'update');
    });

    afterEach(() => {
      normalizeSpy.restore();
      updateSpy.restore();
    });

    it('should call normalize and update', () => {
      const retVal = instance.applyHeaders(undefined);
      expect(retVal).to.deep.equal({ port: 0, state: 1 });
      expect(normalizeSpy.called).to.be.true;
      expect(updateSpy.calledOnce).to.be.true;
    });

    it('should return headers', () => {
      const header = { something: 'header' };
      const retVal = instance.applyHeaders(header as any);
      expect(retVal).to.deep.equal({ port: 0, state: 1, something: 'header' });
      expect(normalizeSpy.called).to.be.true;
      expect(updateSpy.calledOnce).to.be.true;
    });
  });
Example #3
0
    it('should return unmuted dappIds array in peer obj without height', () => {
      const expectedPeer = {
        broadhash: '',
        clock    : '',
        dappid   : ['dappId', 'dappId2'],
        height   : '',
        ip       : '127.0.0.1',
        nonce    : '',
        os       : '',
        port     : 1010,
        state    : 2,
        updated  : '',
        version  : '',
      };

      peer.dappid = ['dappId', 'dappId2'];

      const normalized = instance.normalize(Object.assign({}, peer));

      expect(parseIntSpy.calledTwice).to.be.true;
      expect(parseIntSpy.firstCall.args.length).to.equal(2);
      expect(parseIntSpy.firstCall.args[0]).to.equal(peer.port);
      expect(parseIntSpy.firstCall.args[1]).to.equal(0);
      expect(parseIntSpy.getCall(1).args.length).to.equal(2);
      expect(parseIntSpy.getCall(1).args[0]).to.equal(peer.state);
      expect(parseIntSpy.getCall(1).args[1]).to.equal(PeerState.DISCONNECTED);
      expect(normalized).to.deep.equal(expectedPeer);
    });
Example #4
0
    it('should call parseInt correctly when no height is passed', () => {
      const expectedPeer = {
        broadhash: '',
        clock    : '',
        height   : '',
        ip       : '127.0.0.1',
        nonce    : '',
        os       : '',
        port     : 1010,
        state    : 2,
        updated  : '',
        version  : '',
      };

      const normalized = instance.normalize(Object.assign({}, peer));

      expect(parseIntSpy.calledTwice).to.be.true;
      expect(parseIntSpy.firstCall.args.length).to.equal(2);
      expect(parseIntSpy.firstCall.args[0]).to.equal(peer.port);
      expect(parseIntSpy.firstCall.args[1]).to.equal(0);
      expect(parseIntSpy.getCall(1).args.length).to.equal(2);
      expect(parseIntSpy.getCall(1).args[0]).to.equal(peer.state);
      expect(parseIntSpy.getCall(1).args[1]).to.equal(PeerState.DISCONNECTED);
      expect(normalized).to.deep.equal(expectedPeer);
    });
Example #5
0
          .then(([result, response, descriptor]) => {
            // promise results
            expect(result).to.be.instanceof(FragmentResult);
            expect(result.data).to.deep.equal([{ id: 1, name: 'FOO JOE' }]);
            expect(response).to.have.all.keys([
              'code',
              'config',
              'data',
              'headers',
              'request',
              'status',
              'statusText'
            ]);
            expect(descriptor).to.equal(spyStore_touchResource.getCall(0).args[0]);

            // hooks
            expect(spyMutableUsers_generateDescriptor.callCount).to.equal(1);
            expect(spyStore_touchResource.callCount).to.equal(1);
            expect(spyStore_touchResource.getCall(0).args[0]).to.deep.match(expectedDescriptor);
            expect(spyStore_updateResource.callCount).to.equal(1);
            expect(spyStore_updateResource.getCall(0).args[1]).to.deep.equal({
              id: responseData.id,
              name: responseData.name.toUpperCase()
            });
            expect(spyStore_destroyResource.callCount).to.equal(0);
          }, () => {
Example #6
0
          .then(([result, response, descriptor]: TRequestResult) => {
            // promise results
            expect(result).to.be.instanceof(FragmentResult);
            expect(result.data).to.equal(null);
            expect(response).to.have.all.keys([
              'code',
              'config',
              'data',
              'headers',
              'request',
              'status',
              'statusText'
            ]);
            expect(descriptor).to.equal(spyStore_touchResource.getCall(0).args[0]);

            // hooks
            expect(spyMutableUsers_generateDescriptor.callCount).to.equal(1);
            expect(spyStore_touchResource.callCount).to.equal(1);
            expect(spyStore_touchResource.getCall(0).args[0]).to.deep.match(expectedDescriptor);
            expect(spyStore_updateResource.callCount).to.equal(0);
            expect(spyStore_destroyResource.callCount).to.equal(1);
            expect(spyStore_destroyResource.getCall(0).args[0]).to.equal(descriptor);
            expect(spyStore_destroyResource.getCall(0).args[1]).to.deep.equal({
              invoker: mutableUsers
            });
          }, () => {
 useFakeClock(clock=>{
     cache.get({
         numAsString:"5"
     });
     clock.tick(100);
     assert.equal(fetch.getCall(0).args[1], 25, "first static dependency passed in correctly");
     assert.equal(fetch.getCall(0).args[2], 3, "second static dependency passed in correctly");
 });
Example #8
0
 const mockOn = (event: string, cb: (err?: string) => void) => {
   if (!doError && event === 'ready') {
     onReadySpy();
     cb();
   } else if (doError && event === 'error') {
     onErrorSpy();
     cb('testError');
   }
 };
Example #9
0
      it('should invoke default handler when none specified', () => {
        const descriptor = new ResourceDescriptor(null, IActionType.get, schema.users.__stack);

        processResponse(descriptor, dataCollectionUsers);

        expect(spy_defaultHandler.callCount).to.equal(1);
        expect(spy_defaultHandler.getCall(0).args[0]).to.equal(descriptor);
        expect(spy_defaultHandler.getCall(0).args[1]).to.equal(dataCollectionUsers);
      });
Example #10
0
export function cleanSpy(spy: SinonSpy) {
    if (spy) {
        if (spy.restore) {
            spy.restore();
        }

        spy.reset();
    }
}