Ejemplo n.º 1
0
    it("should return an instance of ReportSlaveIdResponse if the function code is not an exception", function()
    {
      var req = new ReportSlaveIdRequest();
      var res = req.createResponse(new Buffer([0x11, 0x05, 0x02, 0x00, 0x01, 0x01, 0x01 ]));

      res.should.be.an.instanceOf(ReportSlaveIdResponse);
      res.getCode().should.be.equal(0x11);
    });
Ejemplo n.º 2
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new WriteFifo8Request(0x01, [0, 1]);
      var res = req.createResponse(new Buffer([0xC2, 0x02]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x42);
      res.getExceptionCode().should.be.equal(2);
    });
Ejemplo n.º 3
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new ReadDiagnosticsRequest(0x0001, 2);
      var res = req.createResponse(new Buffer([0x88, 0x02]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x08);
      res.getExceptionCode().should.be.equal(2);
    });
Ejemplo n.º 4
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new CommandRequest(2);
      var res = req.createResponse(new Buffer([0xC7, 0x22]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x47);
      res.getExceptionCode().should.be.equal(0x22);
    });
Ejemplo n.º 5
0
    it("should return an instance of ReadInputRegistersResponse if the function code is not an exception", function()
    {
      var req = new ReadInputRegistersRequest(0x0001, 2);
      var res = req.createResponse(new Buffer([0x04, 0x02, 0x00, 0x01]));

      res.should.be.an.instanceOf(ReadInputRegistersResponse);
      res.getCode().should.be.equal(0x04);
      res.getCount().should.be.equal(1);
    });
Ejemplo n.º 6
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new ReportSlaveIdRequest();
      var res = req.createResponse(new Buffer([0x91, 0x03]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x11);
      res.getExceptionCode().should.be.equal(3);
    });
Ejemplo n.º 7
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new WriteFileRecordRequest([{recordData: new Buffer([0x11, 0x11])}]);
      var res = req.createResponse(new Buffer([0x95, 0x02]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x15);
      res.getExceptionCode().should.be.equal(2);
    });
Ejemplo n.º 8
0
    it("should return an instance of WriteMemoryResponse if the function code is not an exception", function()
    {
      var req = new WriteMemoryRequest(0x01,0,0, new Buffer([0x00, 0x01]));
      var res = req.createResponse(new Buffer([0x46, 0x01]));

      res.should.be.an.instanceOf(WriteMemoryResponse);
      res.getCode().should.be.equal(0x46);
      res.getStatus().should.be.equal(1);
    });
Ejemplo n.º 9
0
    it("should return an instance of WriteFifo8Response if the function code is not an exception", function()
    {
      var req = new WriteFifo8Request(0x01, new Buffer([0x00, 0x01]));
      var res = req.createResponse(new Buffer([0x42, 0x01]));

      res.should.be.an.instanceOf(WriteFifo8Response);
      res.getCode().should.be.equal(0x42);
      res.getQuantity().should.be.equal(1);
    });
Ejemplo n.º 10
0
    it("should return an instance of ExceptionResponse if the function code is an exception", function()
    {
      var req = new WriteSingleRegisterRequest(0x0001, 0x1337);
      var res = req.createResponse(new Buffer([0x86, 0x02]));

      res.should.be.an.instanceOf(ExceptionResponse);
      res.getCode().should.be.equal(0x06);
      res.getExceptionCode().should.be.equal(2);
    });
Ejemplo n.º 11
0
    it("should return an instance of ReadDiagnosticsResponse if the function code is not an exception", function()
    {
      var req = new ReadDiagnosticsRequest(0x01, 2);
      var res = req.createResponse(new Buffer([0x08, 0x02, 0x01, 0x01]));

      res.should.be.an.instanceOf(ReadDiagnosticsResponse);
      res.getCode().should.be.equal(0x08);
      res.getCount().should.be.equal(1);
      res.getValues().length.should.be.equal(1);
    });
Ejemplo n.º 12
0
    it("should return an instance of WriteSingleRegisterResponse if the function code is not an exception", function()
    {
      var req = new WriteSingleRegisterRequest(0x0001, 0x1337);
      var res = req.createResponse(new Buffer([0x06, 0x00, 0x01, 0x13, 0x37]));

      res.should.be.an.instanceOf(WriteSingleRegisterResponse);
      res.getCode().should.be.equal(0x06);
      res.getAddress().should.be.equal(0x0001);
      res.getValue().should.be.equal(0x1337);
    });
Ejemplo n.º 13
0
    it("should return an instance of ReadFileRecordResponse if the function code is not an exception", function()
    {
      var req = new ReadFileRecordRequest([
        {fileNumber: 4, recordNumber: 1, recordLength: 2},
        {fileNumber: 3, recordNumber: 9, recordLength: 2}
      ]);
      var res = req.createResponse(new Buffer([0x14, 0x0C, 0x05, 0x06, 0x0D, 0xFE, 0x00, 0x20, 0x05, 0x06, 0x33, 0xCD, 0x00, 0x40]));

      res.should.be.an.instanceOf(ReadFileRecordResponse);
      res.getCode().should.be.equal(0x14);
    });
Ejemplo n.º 14
0
    it("should return an instance of CommandResponse if the function code is not an exception", function()
    {
      var req = new CommandRequest(2);
      var res = req.createResponse(new Buffer([0x47, 0x02, 0x01, 0x01]));

      res.should.be.an.instanceOf(CommandResponse);
      res.getCode().should.be.equal(0x47);
      res.getId().should.be.equal(0x02);
      res.getCount().should.be.equal(2);
      res.getValues().length.should.be.equal(2);
    });
Ejemplo n.º 15
0
 return new Promise(function (resolve, reject) {
     var req = httpMock.createRequest({
         body: trial
     });
     var res = httpMock.createResponse();
     res.on('end', function () {
         return resolve(res);
     }).on('error', function (err) {
         return reject(err);
     });
     controller.create(req, res);
 }).then(function (res) {
Ejemplo n.º 16
0
 return new Promise(function (resolve, reject) {
     var req = httpMock.createRequest({
         params: {
             trial_id: trial_id,
             group_label: group_label
         }
     });
     var res = httpMock.createResponse();
     res.on('end', function () {
         return resolve(res);
     }).on('error', function (err) {
         return reject(err);
     });
     controller.get(req, res);
 }).then(function (res) {
Ejemplo n.º 17
0
    it("should return an instance of WriteFileRecordResponse if the function code is not an exception", function()
    {
      var req = new WriteFileRecordRequest([
        {fileNumber: 1, recordNumber: 0, recordData: new Buffer([0x11, 0x11])},
        {fileNumber: 2, recordNumber: 4, recordData: new Buffer([0x22, 0x22])}
      ]);
      var res = req.createResponse(new Buffer([
        0x15, 0x12,
        0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x11, 0x11,
        0x06, 0x00, 0x02, 0x00, 0x04, 0x00, 0x01, 0x22, 0x22
      ]));

      res.should.be.an.instanceOf(WriteFileRecordResponse);
      res.getCode().should.be.equal(0x15);
    });
Ejemplo n.º 18
0
	it("should return 'API server is working'", function (done) {

		var req = httpMock.createRequest({
			method: 'GET'
		});
		var res = httpMock.createResponse();
		controller.ping(req, res);
		
		assert.equal(200, res.statusCode);
		assert.isTrue(res._isJSON());
		
		var result = JSON.parse(res._getData());
		assert.equal(result.message, 'API server is working');
		
		done();
	})
Ejemplo n.º 19
0
        return new Promise(function (resolve, reject) {
            var req = httpMock.createRequest({
                params: {
                    trial_id: invalid_id
                }
            });
            var res = httpMock.createResponse();
            res.on('end', function () {
                return resolve(res);
            }).on('error', function (err) {
                return reject(err);
            });
            controller.find_or_four0four(req, res, function (trial) {
                done(new Error("should not next function"));

            });
        }).then(function (res) {
Ejemplo n.º 20
0
        return new Promise(function (resolve, reject) {
            var req = httpMock.createRequest({
                params: {
                    trial_id: trial_id
                }
            });
            var res = httpMock.createResponse();
            res.on('end', function () {
                return resolve(res);
            }).on('error', function (err) {
                return reject(err);
            });
            controller.find_or_four0four(req, res, function (trial) {
                assert.isNotNull(trial, "no data returned");

                done();
            });
        }).then(function (res) {
Ejemplo n.º 21
0
 return new Promise(function (resolve, reject) {
     var req = httpMock.createRequest({
         params: {
             trial_id: trial_id,
             group_label: group_label
         },
         body: {
             dosage: {
                 quantity: 1,
                 regularity: 'every day'
             }
         }
     });
     var res = httpMock.createResponse();
     res.on('end', function () {
         return resolve(res);
     }).on('error', function (err) {
         return reject(err);
     });
     controller.dosage(req, res);
 }).then(function (res) {
Ejemplo n.º 22
0
 return new Promise(function (resolve, reject) {
     var req = httpMock.createRequest({
         params: {
             trial_id: trial_id
         },
         body: {
             name: newName,
             medication: {
                 name: newMedicationName,
                 dosage: {
                     quantity: newDosageQuantity,
                     regularity: newDosageRegularity
                 }
             }
         }
     });
     var res = httpMock.createResponse();
     res.on('end', function () {
         return resolve(res);
     }).on('error', function (err) {
         return reject(err);
     });
     controller.update(req, res);
 }).then(function (res) {
Ejemplo n.º 23
0
Controller.prototype.respondWith = function(res, data) {
  var response = Route.createResponse(data.status, data.content, data.msg);
  res.send(response);
};