Пример #1
0
    it('should call response.json with models with and without tasks', function() {
      var response = {
        json: chai.spy()
      };
      var next = chai.spy();
      var runStatus = 'done';
      var taskUrl = 'url';
      var expectedModelArray = [{
        taskUrl: taskUrl,
        runStatus: runStatus
      }];
      var modelsResult = [{
        taskUrl: taskUrl
      }];
      var pataviResult = [{
        id: taskUrl,
        runStatus: runStatus
      }];
      var partitionResult = {
        modelsWithTask: [modelsResult[0]],
        modelsWithoutTask: []
      };
      modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);
      modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);

      pataviTaskRepositoryStub.getPataviTasksStatus = sinon.fake.yields(null, pataviResult);

      modelHandlers.find(request, response, next);
      expect(response.json).to.have.been.called.with(expectedModelArray);
    });
Пример #2
0
 it('should call next with an error if the funnel plot can not be created', function(done) {
   var next = function(thrownError) {
     expect(thrownError).to.deep.equal(error500);
     done();
   };
   var response = {};
   modelRepositoryStub.get = sinon.fake.yields(null, model);
   funnelPlotRepositoryStub.create = sinon.fake.yields(errorMessage);
   modelHandlers.addFunnelPlot(request, response, next);
 });
Пример #3
0
 it('should call next with an error if the archived status could not be set', function(done) {
   var response;
   var next = function(thrownError) {
     expect(thrownError).to.deep.equal(error500);
     done();
   };
   modelRepositoryStub.get = sinon.fake.yields(null, model);
   modelRepositoryStub.setArchive = sinon.fake.yields(errorMessage);
   modelHandlers.setAttributes(request, response, next);
 });
Пример #4
0
 it('should call next with an error if the coordinates do not match', function(done) {
   var response = {};
   var next = function(thrownError) {
     expect(thrownError).to.deep.equal(coordinateError);
     done();
   };
   modelRepositoryStub.get = sinon.fake.yields(null, 'someModel');
   modelBaselineRepositoryStub.get = sinon.fake.yields(errorMessage);
   modelHandlers.setBaseline(request, response, next);
 });
Пример #5
0
    beforeEach(() => {
      mockReq = new events.EventEmitter()
      mockReq.on = sinon.fake(mockReq.on)
      mockReq.end = sinon.fake()
      mockReq.write = sinon.fake()

      mockHttpRequest = sinon.fake.returns(mockReq)
      sinon.replace(http, 'request', mockHttpRequest)
      mockHttpsRequest = sinon.fake.returns(mockReq)
      sinon.replace(https, 'request', mockHttpsRequest)
    })
Пример #6
0
    it('should call next with an error if the model cannot be updated', function(done) {
      var next = function(thrownError) {
        expect(thrownError).to.deep.equal(error500);
        done();
      };
      var response = {};
      modelRepositoryStub.get = sinon.fake.yields(null, model);
      modelServiceStub.update = sinon.fake.yields(errorMessage);

      modelHandlers.extendRunLength(request, response, next);
    });
Пример #7
0
 it('should set the model attributes and call response.sendStatus when successful', function(done) {
   var next = chai.spy();
   var expectations = function(status) {
     expect(status).to.equal(200);
     expect(next).to.not.have.been.called();
     done();
   };
   var response = {
     sendStatus: expectations
   };
   modelRepositoryStub.get = sinon.fake.yields(null, model);
   modelRepositoryStub.setArchive = sinon.fake.yields(null);
   modelHandlers.setAttributes(request, response, next);
 });
Пример #8
0
 it('should call next with an error if the coordinates do not match', function(done) {
   var response;
   var next = function(thrownError) {
     expect(thrownError).to.deep.equal(coordinateError);
     done();
   };
   var modelWithWrongAnalysis = {
     analysisId: 1337,
     modelId: modelId
   };
   modelRepositoryStub.get = sinon.fake.yields(null, modelWithWrongAnalysis);
   modelRepositoryStub.setArchive = sinon.fake.yields(errorMessage);
   modelHandlers.setAttributes(request, response, next);
 });
Пример #9
0
    it('should pass an error to next when attempting to get patavi result', function(done) {
      var taskUrl = 'url';
      var next = function(thrownError) {
        expect(thrownError).to.deep.equal(error500);
        done();
      };
      var modelResult = {
        taskUrl: taskUrl
      };
      modelRepositoryStub.get = sinon.fake.yields(null, modelResult);
      pataviTaskRepositoryStub.getResult = sinon.fake.yields(errorMessage);

      modelHandlers.getResult(request, response, next);
    });
Пример #10
0
 it('onChange', () => {
   const fake = sinon.fake.returns(null)
   const onChange = sinon.fake()
   Renderer.create(<SetValue children={fake} onChange={onChange} />)
   fake.lastArg.set(new Set([1]))
   assert.deepEqual(onChange.lastArg, new Set([1]))
 })
Пример #11
0
		beforeEach(function() {
			this.app = new Pluggi({plugName: this.globalOptions});
			this.options = {localOpt: 2};
			this.res = {resProp: 3};
			this.plugin = sinon.fake.returns(this.res);
			this.ret = this.app.plugin('plugName', this.plugin, this.options);
		});
Пример #12
0
		beforeEach(function() {
			// NB name of function returned by `sinon.fake()` is 'proxy'
			this.app = new Pluggi({proxy: this.globalOptions});
			this.res = {resProp: 3};
			this.plugin = sinon.fake.returns(this.res);
			this.ret = this.app.plugin(this.plugin);
		});
Пример #13
0
 it('should call next with an error object when an error occurs while retrieving models from the repository', function() {
   var response = {};
   var next = chai.spy();
   modelRepositoryStub.findByAnalysis = sinon.fake.yields(errorMessage);
   modelHandlers.find(request, response, next);
   expect(next).to.have.been.called.with(error500);
 });
Пример #14
0
 it('should query the modelBaseline repository', function(done) {
   var response = {
     sendStatus: function(result) {
       expect(result).to.equal(200);
       done();
     }
   };
   var next = chai.spy();
   var model = {
     analysisId: -1
   };
   modelRepositoryStub.get = sinon.fake.yields(null, model);
   modelBaselineRepositoryStub.set = sinon.fake.yields(null);
   modelHandlers.setBaseline(request, response, next);
   expect(next).to.not.have.been.called();
 });
Пример #15
0
 it('should call next with an error if one occurs', function() {
   var response = {};
   var next = chai.spy();
   modelRepositoryStub.deleteModel = sinon.fake.yields(errorMessage);
   modelHandlers.deleteModel(request, response, next);
   expect(next).to.have.been.called.with(error500);
 });
Пример #16
0
 it('should call next with an error', function() {
   var response = {};
   var next = chai.spy();
   funnelPlotRepositoryStub.findByPlotId = sinon.fake.yields(errorMessage);
   modelHandlers.getFunnelPlot(request, response, next);
   expect(next).to.have.been.called.with(error500);
 });
Пример #17
0
    it('should add a funnel plot and call response.sendStatus when successful', function(done) {
      var next = chai.spy();
      var expectations = function(status) {
        expect(status).to.equal(201);
        expect(next).to.have.not.been.called();
        done();
      };
      var response = {
        sendStatus: expectations
      };

      modelRepositoryStub.get = sinon.fake.yields(null, model);
      funnelPlotRepositoryStub.create = sinon.fake.yields(null);

      modelHandlers.addFunnelPlot(request, response, next);
    });
Пример #18
0
 it('reset()', () => {
   const fake = sinon.fake.returns(null)
   Renderer.create(<BooleanValue children={fake} defaultValue />)
   fake.lastArg.set(false)
   fake.lastArg.reset()
   assert.equal(fake.lastArg.value, true)
 })
Пример #19
0
    it('should, if an error occurs, pass it to next', function() {
      var response = {};
      var next = chai.spy();
      modelBaselineRepositoryStub.get = sinon.fake.yields(errorMessage);
      modelHandlers.getBaseline(request, response, next);

      expect(next).to.have.been.called.with(error500);
    });
Пример #20
0
 it('set(value)', () => {
   const fake = sinon.fake.returns(null)
   Renderer.create(<SetValue children={fake} />)
   fake.lastArg.set(new Set([1]))
   assert.deepEqual(fake.lastArg.value, new Set([1]))
   fake.lastArg.set(new Set([2]))
   assert.deepEqual(fake.lastArg.value, new Set([2]))
 })
Пример #21
0
    it('should update an existing model to have more iterations and call response.sendStatus when successful', function(done) {
      var next = chai.spy();
      var expectations = function(status) {
        expect(status).to.equal(200);
        expect(next).to.have.not.been.called();
        done();
      };
      var response = {
        sendStatus: expectations
      };

      modelRepositoryStub.get = sinon.fake.yields(null, model);
      modelServiceStub.update = sinon.fake.yields(null);
      pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(null);

      modelHandlers.extendRunLength(request, response, next);
    });
Пример #22
0
 it('toggle(val, boolean)', () => {
   const fake = sinon.fake.returns(null)
   Renderer.create(<SetValue children={fake} defaultValue={new Set([1, 2])} />)
   fake.lastArg.toggle(1, false)
   assert.deepEqual(fake.lastArg.value, new Set([2]))
   fake.lastArg.toggle(1, true)
   assert.deepEqual(fake.lastArg.value, new Set([2, 1]))
 })
Пример #23
0
    it('should call next with an error object when an error occurs while gettig the status of Patavi tasks', function() {
      var response = {};
      var next = chai.spy();
      var modelsResult = [
        { taskUrl: 'taskUrl' }
      ];
      var partitionResult = {
        modelsWithTask: [modelsResult[0]],
        modelsWithoutTask: []
      };
      modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);
      modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);
      pataviTaskRepositoryStub.getPataviTasksStatus = sinon.fake.yields(errorMessage);

      modelHandlers.find(request, response, next);
      expect(next).to.have.been.called.with(error500);
    });
Пример #24
0
 it('toggle()', () => {
   const fake = sinon.fake.returns(null)
   Renderer.create(<BooleanValue children={fake} />)
   fake.lastArg.toggle()
   assert.equal(fake.lastArg.value, true)
   fake.lastArg.toggle()
   assert.equal(fake.lastArg.value, false)
 })
Пример #25
0
    it('should call response.json with models without tasks', function() {
      var response = {
        json: chai.spy()
      };
      var next = chai.spy();
      var expectedModelArray = [{}];
      var modelsResult = [{}];
      var partitionResult = {
        modelsWithTask: [],
        modelsWithoutTask: [modelsResult[0]]
      };
      modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);
      modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);

      modelHandlers.find(request, response, next);
      expect(response.json).to.have.been.called.with(expectedModelArray);
    });
Пример #26
0
 it('should call the repository.deleteModel', function() {
   var response = {
     sendStatus: chai.spy()
   };
   var next = chai.spy();
   modelRepositoryStub.deleteModel = sinon.fake.yields(null);
   modelHandlers.deleteModel(request, response, next);
   expect(response.sendStatus).to.have.been.called.with(200);
 });
Пример #27
0
    it('calls the errorCallback if request returned an error', () => {
      const mockRequest = sinon.fake.yields('Request Error')
      sinon.replace(vimeo, 'request', mockRequest)

      vimeo.replace(FILE_NAME, VIDEO_URI, {}, mockCompleteCallback, mockProgressCallback, mockErrorCallback)

      sinon.assert.calledOnce(mockErrorCallback)
      sinon.assert.calledWith(mockErrorCallback, sinon.match('Request Error'))
    })
Пример #28
0
    it('should pass an error to next when attempting to get a model from the repository', function(done) {
      var next = function(thrownError) {
        expect(thrownError).to.deep.equal(error500);
        done();
      };
      modelRepositoryStub.get = sinon.fake.yields(errorMessage);

      modelHandlers.getResult(request, response, next);
    });
Пример #29
0
 it('remove(val) (alias) (mutates)', () => {
   const fake = sinon.fake.returns(null)
   Renderer.create(<SetValue children={fake} defaultValue={new Set([1, 2])} />)
   const previous = fake.lastArg.value
   fake.lastArg.remove(1)
   const { value } = fake.lastArg
   assert.deepEqual(value, new Set([2]))
   assert.notEqual(value, previous)
 })
Пример #30
0
 it('should call next with an error if the model can\'t be created', function(done) {
   var next = function(thrownError) {
     expect(thrownError).to.deep.equal(error500);
     done();
   };
   var response = {};
   modelRepositoryStub.create = sinon.fake.yields(errorMessage);
   modelHandlers.createModel(request, response, next);
 });