setTimeout(() => {
      const localeOptions = wrapper.find('.breadcrumb-inner').find('#locale-options');
      expect(expectedLocaleOptions, localeOptions.find('select').html());

      const formTranslationContainer = wrapper.find('FormTranslationsContainer');

      sinon.assert.callOrder(store.dispatch.withArgs(
        updateTranslations({
          value: 'desc Examination Notes',
          type: 'concepts',
          translationKey: 'EXAMINATION_NOTES_18_DESC',
          locale: 'en',
        })),
        store.dispatch.withArgs(updateTranslations({
          value: 'Severe Undernutrition',
          type: 'concepts',
          translationKey: 'SEVERE_UNDERNUTRITION_13',
          locale: 'en',
        })));

      expect(formTranslationContainer.find('.info-message').html()).to
        .have.string('Please save the changes before selecting a locale.');
      expect(formTranslationContainer.find('FormTranslationsGrid')
        .props().translationData).to.eql(expectedTranslationData);
      const table = formTranslationContainer.find('table');
      expect(table.find('thead')).to.have.exactly(2).descendants('th');
      expect(table.find('tbody')).to.have.exactly(4).descendants('tr');
      sinon.assert.callOrder(
        mockHttp.get.withArgs('/bahmni_config/openmrs/apps/home/locale_languages.json'),
        mockHttp.get.withArgs('/openmrs/ws/rest/v1/form/form_uuid?v=custom:(id,uuid,name,version)'),
        mockHttp.get.withArgs('/openmrs/ws/rest/v1/bahmniie/form/translate?formName=' +
          'form_name&formVersion=2&locale=en')
      );
      done();
    }, 50);
Example #2
0
    it("adds 'all' to the chain, calls 'list' and throws an error", function() {
      var progressSpy = sinon.spy();
      var callbackSpy = sinon.spy();

      var listStub = sinon.stub(stripe._stripe.charges, "list");
      listStub.yields(null, {
        has_more: false,
        data: [
          {
            id: "ch_xxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      });

      var self = stripe
        .all()
        .charges()
        .until()
        .now()
        .list(progressSpy, callbackSpy);
      expect(stripe._chain).to.have.members(["all", "charges", "to", "now"]);
      expect(stripe._options.type).to.equal("charge");
      sinon.assert.calledOnce(progressSpy);
      sinon.assert.calledOnce(callbackSpy);
      sinon.assert.callOrder(progressSpy, callbackSpy);
      expect(self).to.equal(stripe);
    });
Example #3
0
    it("adds 'history' and 'charges' to the chain, calls progress twice and then callback once", function() {
      var progressSpy = sinon.spy();
      var callbackSpy = sinon.spy();

      var listStub = sinon.stub(stripe._stripe.balance, "listTransactions");
      listStub.onFirstCall().yields(null, {
        has_more: true,
        data: [
          {
            id: "txn_xxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      });
      listStub.onSecondCall().yields(null, {
        has_more: false,
        data: [
          {
            id: "txn_xxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      });

      var self = stripe
        .last(150)
        .charges()
        .history()
        .please(progressSpy, callbackSpy);

      expect(stripe._chain).to.have.members(["last", "charges", "history"]);
      expect(stripe._options.type).to.equal("charge");
      sinon.assert.calledTwice(progressSpy);
      sinon.assert.calledOnce(callbackSpy);
      sinon.assert.callOrder(progressSpy, progressSpy, callbackSpy);
      expect(self).to.equal(stripe);
    });
Example #4
0
    it("adds 'charges' to the chain, calls progress twice and then callback once", function() {
      var progressSpy = sinon.spy();
      var callbackSpy = sinon.spy();

      var listStub = sinon.stub(stripe._stripe.charges, "list");
      listStub.onFirstCall().yields(null, {
        has_more: true,
        data: [
          {
            id: "ch_xxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      });
      listStub.onSecondCall().yields(null, {
        has_more: false,
        data: [
          {
            id: "ch_xxxxxxxxxxxxxxxxxxxxxxxx"
          }
        ]
      });

      var self = stripe.all().charges(progressSpy, callbackSpy);

      expect(stripe._chain).to.have.members(["all", "charges"]);
      expect(stripe._options.type).to.equal("charge");
      sinon.assert.calledTwice(progressSpy);
      sinon.assert.calledOnce(callbackSpy);
      sinon.assert.callOrder(progressSpy, progressSpy, callbackSpy);
      expect(self).to.equal(stripe);
    });
Example #5
0
		it('should bind events to the socket which call through to the correct methods of callActions', function() {
			// This test ensures that when binding on() calls to socket, we don't accidentally bind all events to one call
			chatActions.firstNamespace = {
				firstAction: sinon.stub(),
				secondAction: sinon.stub()
			};
			chatActions.secondNamespace = {
				thirdAction: sinon.stub()
			};

			var connection = new Connection(socket);
			connection.userData = {}; // User is considered signed in when userData is set
			
			// Call all three actions
			socket.on.firstCall.args[1](data);
			socket.on.secondCall.args[1](data);
			socket.on.thirdCall.args[1](data);

			// Ensure all actions were called (rather than one action thrice)
			assert.ok(chatActions.firstNamespace.firstAction.calledOnce);
			assert.ok(chatActions.firstNamespace.secondAction.calledOnce);
			assert.ok(chatActions.secondNamespace.thirdAction.calledOnce);
			
			// Ensure the actions were called in the right order
			sinon.assert.callOrder(
					chatActions.firstNamespace.firstAction,
					chatActions.firstNamespace.secondAction,
					chatActions.secondNamespace.thirdAction);
		});
        .then(response => {
          try {
            should(kuzzle.validation.validationPromise).be.calledOnce();

            should(kuzzle.notifier.publish).be.calledOnce();
            should(kuzzle.notifier.publish).be.calledWith(request);

            should(engine.replace).be.calledOnce();
            should(engine.replace).be.calledWith(request);

            should(kuzzle.notifier.notifyDocumentReplace).be.calledOnce();
            should(kuzzle.notifier.notifyDocumentReplace).be.calledWith(request);

            sinon.assert.callOrder(
              engine.replace,
              kuzzle.notifier.notifyDocumentReplace
            );

            should(response).be.instanceof(Object);
            should(response).match(foo);

            return Bluebird.resolve();
          }
          catch(error) {
            return Bluebird.reject(error);
          }

        });
Example #7
0
        .then(() => {

          try {
            should(bootstrap.db.createInternalIndex)
              .be.calledOnce();

            should(bootstrap.createCollections)
              .be.calledOnce();

            should(bootstrap.db.refresh)
              .be.calledOnce();

            should(kuzzle.indexCache.add)
              .be.calledOnce()
              .be.calledWithExactly(bootstrap.db.index);

            sinon.assert.callOrder(
              bootstrap.db.createInternalIndex,
              bootstrap.createCollections,
              bootstrap.db.refresh,
              kuzzle.indexCache.add
            );

            return Promise.resolve();
          }
          catch(error) {
            return Promise.reject(error);
          }
        });
 it('should set the worldSize, then the containerSize, then reset the Zoom', () => {
   view.setDimensions(20, 21, 10, 11)
   sinon.assert.callOrder(wvMock.setWorldSize, wvMock.setContainerSize, wvMock.resetZoom)
   expect(wvMock.setWorldSize).to.have.been.calledWith(20, 21)
   expect(wvMock.setContainerSize).to.have.been.calledWith(10, 11)
   expect(wvMock.resetZoom).to.have.been.called
 })
 highLevelConsumer.on('rebalanced', function () {
   refreshMetadataStub.calledOnce.should.be.true;
   sendOffsetFetchRequestStub.calledOnce.should.be.true;
   sinon.assert.callOrder(refreshMetadataStub, sendOffsetFetchRequestStub);
   highLevelConsumer.rebalancing.should.be.false;
   done();
 });
Example #10
0
            bookshelf.Model.prototype.fetchPage(groupOptions).then(function () {
                sinon.assert.callOrder(
                    paginationUtils.parseOptions,
                    model.prototype.query,
                    mockQuery.clone,
                    mockQuery.select,
                    paginationUtils.addLimitAndOffset,
                    model.prototype.query,
                    model.prototype.fetchAll,
                    paginationUtils.formatResponse
                );

                paginationUtils.parseOptions.calledOnce.should.be.true();
                paginationUtils.parseOptions.calledWith(groupOptions).should.be.true();

                paginationUtils.addLimitAndOffset.calledOnce.should.be.true();
                paginationUtils.formatResponse.calledOnce.should.be.true();

                model.prototype.query.calledTwice.should.be.true();
                model.prototype.query.firstCall.calledWith().should.be.true();
                model.prototype.query.secondCall.calledWith('groupBy', 'posts.id').should.be.true();

                mockQuery.clone.calledOnce.should.be.true();
                mockQuery.clone.firstCall.calledWith().should.be.true();

                mockQuery.select.calledOnce.should.be.true();
                mockQuery.select.calledWith().should.be.true();

                model.prototype.fetchAll.calledOnce.should.be.true();
                model.prototype.fetchAll.calledWith(groupOptions).should.be.true();

                done();
            }).catch(done);
Example #11
0
                        fixtures004[6]({}, loggerStub).then(function () {
                            loggerStub.info.calledThrice.should.be.true();
                            loggerStub.warn.called.should.be.false();
                            postAllStub.calledOnce.should.be.true();
                            postCollStub.mapThen.calledOnce.should.be.true();
                            postObjStub.related.calledOnce.should.be.true();
                            tagObjStub.pivot.get.calledThrice.should.be.true();

                            postObjStub.tags.calledThrice.should.be.true();
                            postObjStub.updatePivot.calledThrice.should.be.true();

                            postObjStub.updatePivot.firstCall.args[0].should.eql({sort_order: 0});
                            postObjStub.updatePivot.secondCall.args[0].should.eql({sort_order: 1});
                            postObjStub.updatePivot.thirdCall.args[0].should.eql({sort_order: 2});

                            sinon.assert.callOrder(
                                loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.related,
                                tagObjStub.pivot.get, tagObjStub.pivot.get, tagObjStub.pivot.get,
                                loggerStub.info,
                                postObjStub.tags, postObjStub.updatePivot,
                                postObjStub.tags, postObjStub.updatePivot,
                                postObjStub.tags, postObjStub.updatePivot,
                                loggerStub.info
                            );

                            done();
                        }).catch(done);
    return wrapBuild(emptyFixturePath, beforeSpyFunc, afterSpyFunc).then(function(results) {
      expect(beforeSpyFunc.callCount).to.equal(1);
      expect(afterSpyFunc.callCount).to.equal(1);
      expect(afterSpyFunc.calledWith(sinon.match.string)).to.be.true;

      sinon.assert.callOrder(beforeSpyFunc, afterSpyFunc);
    });
        setTimeout(() => {
          const formTranslationContainer = wrapper.find('FormTranslationsContainer');
          expect(formTranslationContainer.find('FormTranslationsGrid')
            .props().translationData).to.eql(expectedTranslationData);


          const table = formTranslationContainer.find('table');
          expect(table.find('thead')).to.have.exactly(3).descendants('th');
          expect(table.find('tbody')).to.have.exactly(4).descendants('tr');

          sinon.assert.callOrder(
            mockHttp.get.withArgs('/bahmni_config/openmrs/apps/home/locale_languages.json'),
            mockHttp.get.withArgs('/openmrs/ws/rest/v1/form/form_uuid?v=custom:' +
              '(id,uuid,name,version)'),
            mockHttp.get.withArgs('/openmrs/ws/rest/v1/bahmniie/form/translate?formName=' +
              'form_name&formVersion=2&locale=en'),
            mockHttp.get.withArgs('/openmrs/ws/rest/v1/bahmniie/form/translate?formName=' +
              'form_name&formVersion=2&locale=es'),
            mockHttp.get.withArgs('/openmrs/ws/rest/v1/bahmniie/form/translate?formName=' +
              'form_name&formVersion=2&locale=fr')
          );
          sinon.assert.calledOnce(store.dispatch.withArgs(removeLocaleTranslation('es')));
          sinon.assert.calledOnce(store.dispatch.withArgs(removeLocaleTranslation()));
          done();
        }, 50);
Example #14
0
 "test handler can be an array": function() {
     var next = sinon.stub();
     var middleware1 = sinon.stub().callsArg(2);
     var middleware2 = sinon.stub().callsArg(2);
     var handler = sinon.stub();
     
     function reset() {
         next.reset();
         middleware1.reset();
         middleware2.reset();
         handler.reset();
     }
     
     var root = new Api();
     root.get("/juhu", [middleware1, middleware2, handler]);
     
     root.handle({
         method: "GET",
         url: "/juhu"
     }, this.res, next);
     sinon.assert.notCalled(next);
     sinon.assert.callOrder(middleware1, middleware2, handler);
     reset();    
     
     root.handle({
         method: "GET",
         url: "/nothing"
     }, this.res, next);
     sinon.assert.calledOnce(next);
     sinon.assert.notCalled(middleware1);
     sinon.assert.notCalled(middleware2);
     sinon.assert.notCalled(handler);
     reset();    
 },
Example #15
0
                    update('100', '102', logStub).then(function () {
                        // Before the update, it does some tasks...
                        // It should not show an error for these versions
                        errorStub.called.should.be.false();
                        // getMigrationVersions should be called with the correct versions
                        versionsSpy.calledOnce.should.be.true();
                        versionsSpy.calledWith('100', '102').should.be.true();
                        // It should attempt to do a backup
                        backupStub.calledOnce.should.be.true();

                        // Now it's going to try to actually do the update...
                        updateStub.calledOnce.should.be.true();
                        updateStub.calledWith(['101', '102'], logStub).should.be.true();

                        // And now there are some final tasks to wrap up...
                        // First, the ensure default settings task
                        settingsStub.calledOnce.should.be.true();
                        // Then fixture updates
                        fixturesStub.calledOnce.should.be.true();
                        // And finally, set the new DB version
                        setDbStub.calledOnce.should.be.true();

                        // Because we stubbed everything, logStub didn't get called
                        logStub.called.should.be.false();

                        // Just to be sure, lets assert the call order
                        sinon.assert.callOrder(
                            versionsSpy, backupStub, updateStub, settingsStub, fixturesStub, setDbStub
                        );

                        done();
                    }).catch(done);
Example #16
0
                        fixtures004[6]({}, loggerStub).then(function () {
                            loggerStub.info.calledOnce.should.be.true();
                            loggerStub.warn.calledOnce.should.be.true();
                            postAllStub.calledOnce.should.be.true();
                            sinon.assert.callOrder(loggerStub.info, postAllStub, loggerStub.warn);

                            done();
                        }).catch(done);
			it("signals when ICE gathering has completed", function () {
				expect(ice.called, "ICE event").to.be.true;
				expect(ice.firstCall.args[0], "ICE candidate")
				.to.be.an.instanceOf(ZombieRTCPeerConnectionIceEvent)
				.and.to.have.property("candidate").that.is.null;

				Sinon.assert.callOrder(success, ice);
			});
      consumer.close(function (error) {
        consumer.closing.should.be.true;
        consumer.ready.should.be.false;

        sinon.assert.calledOnce(leaveGroupStub);
        sinon.assert.calledOnce(clientCloseSpy);
        sinon.assert.callOrder(leaveGroupStub, clientCloseSpy);
        done(error);
      });
 h.call(() => {
   t.truthy(hotkeys.clearAll.calledWith());
   t.truthy(hotkeys.set.calledWith('Q'));
   t.truthy(hotkeys.set.calledWith('W'));
   t.truthy(hotkeys.set.calledWith('E'));
   sinon.assert.callOrder(hotkeys.clearAll, hotkeys.set);
   console.log = tmp;
   t.end();
 });
Example #20
0
                        fixtures004[7]({}, loggerStub).then(function () {
                            postOneStub.calledOnce.should.be.true();
                            loggerStub.info.calledOnce.should.be.true();
                            loggerStub.warn.called.should.be.false();
                            postAddStub.calledOnce.should.be.true();
                            sinon.assert.callOrder(postOneStub, loggerStub.info, postAddStub);

                            done();
                        }).catch(done);
Example #21
0
  'should be invoked after on if registered after on': function () {
    var spy1 = sinon.spy();
    var spy2 = sinon.spy();

    this.hub.on('test', spy1);
    this.hub.after('test', spy2);
    this.hub.emit('test');

    sinon.assert.callOrder(spy1, spy2);
  },
    it('does a huge stubbed method chain', function() {
      StubbedSigner.sign(query, secret);

      expect(crypto.createHmac.lastCall.args[0]).to.be('sha256');
      expect(crypto.createHmac.lastCall.args[1]).to.be(secret);
      expect(crypto.update).was.calledWith(query);
      expect(crypto.digest).was.calledWith('hex');

      sinon.assert.callOrder(crypto.createHmac, crypto.update, crypto.digest);
    });
Example #23
0
                ImportManager.importFromFile({}).then(function () {
                    loadFileSpy.calledOnce.should.be.true;
                    preProcessSpy.calledOnce.should.be.true;
                    doImportSpy.calledOnce.should.be.true;
                    generateReportSpy.calledOnce.should.be.true;
                    cleanupSpy.calledOnce.should.be.true;
                    sinon.assert.callOrder(loadFileSpy, preProcessSpy, doImportSpy, generateReportSpy, cleanupSpy);

                    done();
                }).catch(done);
Example #24
0
                        fixtures004[4]({}, loggerStub).then(function () {
                            clientOneStub.calledOnce.should.be.true();
                            clientOneStub.calledWith({slug: 'ghost-frontend'}).should.be.true();
                            clientAddStub.calledOnce.should.be.true();
                            loggerStub.info.calledOnce.should.be.true();
                            loggerStub.warn.called.should.be.false();
                            sinon.assert.callOrder(clientOneStub, loggerStub.info, clientAddStub);

                            done();
                        }).catch(done);
    it('should call functions in the expected order', function() {
      sinon.spy(browserstack, '_printSessionURL');

      browserstack.onReload(1, 2);
      sinon.assert.callOrder(
        browserstack._update,
        browserstack._printSessionURL
      );

      browserstack._printSessionURL.restore();
    });
Example #26
0
                        fixtures004[5]({}, loggerStub).then(function () {
                            tagAllStub.calledOnce.should.be.true();
                            tagCollStub.each.called.should.be.false();
                            tagObjStub.get.called.should.be.false();
                            tagObjStub.save.called.should.be.false();
                            loggerStub.info.called.should.be.false();
                            loggerStub.warn.calledOnce.should.be.true();
                            sinon.assert.callOrder(tagAllStub, loggerStub.warn);

                            done();
                        }).catch(done);
Example #27
0
                        fixtures004[2]({}, loggerStub).then(function () {
                            settingsOneStub.calledOnce.should.be.true();
                            settingsOneStub.calledWith('password').should.be.true();
                            settingsEditStub.calledOnce.should.be.true();
                            settingsEditStub.calledWith({key: 'password', type: 'private'}).should.be.true();
                            loggerStub.info.calledOnce.should.be.true();
                            loggerStub.warn.called.should.be.false();
                            sinon.assert.callOrder(settingsOneStub, loggerStub.info, settingsEditStub);

                            done();
                        }).catch(done);
    setTimeout(() => {
      sinon.assert.callOrder(
        mockHttp.get.withArgs('/bahmni_config/openmrs/apps/home/locale_languages.json'),
        mockHttp.get.withArgs('/openmrs/ws/rest/v1/form/form_uuid?v=custom:(id,uuid,name,version)'),
        mockHttp.get.withArgs('/openmrs/ws/rest/v1/bahmniie/form/translate?formName=' +
          'form_name&formVersion=2&locale=en')
      );

      expect(wrapper.find('NotificationContainer').props().notification)
        .to.eql({ message: 'Failed to fetch translation for [English] locale', type: 'error' });
      done();
    }, 50);
Example #29
0
  'should register before listener': function () {
    var spy1 = sinon.spy();
    var spy2 = sinon.spy();
    var spy3 = sinon.spy();

    this.hub.onceAfter('test', spy3);
    this.hub.once('test', spy2);
    this.hub.onceBefore('test', spy1);
    this.hub.emit('test');

    sinon.assert.callOrder(spy1, spy2, spy3);
  }
Example #30
0
                        fixtures004[6]({}, loggerStub).then(function () {
                            postAllStub.calledOnce.should.be.true();
                            postCollStub.mapThen.calledOnce.should.be.true();
                            postObjStub.load.calledOnce.should.be.true();
                            postObjStub.load.calledWith(['tags']).should.be.true();
                            loggerStub.info.calledOnce.should.be.true();
                            // gets called because we're stubbing to return an empty array
                            loggerStub.warn.calledOnce.should.be.true();
                            sinon.assert.callOrder(loggerStub.info, postAllStub, postCollStub.mapThen,  postObjStub.load);

                            done();
                        }).catch(done);