const { handleCanFrame } = require('.');
function decimalToHex(d, padding) {
    var hex = Number(d).toString(16);
    padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;

    while (hex.length < padding) {
        hex = "0" + hex;
    }

    return hex;
}

describe('#handleCanFrame()', () => {
  const rpmValue = 5000;
  const speedValue = 240;

  const rpmHighByte = Math.floor(rpmValue / 256)
  const rpmLowByte = rpmValue % 256;

  const speedTenthsOfKph = Math.floor(speedValue * 10);
  const speedHighByte = Math.floor(speedTenthsOfKph / 256);
  const speedLowByte = speedTenthsOfKph % 256;

  const gear = 3;

  const canString = `433316|1056|N|8|${decimalToHex(rpmHighByte)}|${decimalToHex(rpmLowByte)}|${decimalToHex(speedHighByte)}|${decimalToHex(speedLowByte)}|${decimalToHex(gear)}|${decimalToHex(0)}|${decimalToHex(0)}|${decimalToHex(0)}`;
  it('Testing parse CAN data', () => {
      
    var reply = handleCanFrame(canString);
    console.log(canString)

    expect(true).toBe(true);
    // expect(reply.name).toBe('vss');
    // expect(reply.mode).toBe('41');
    // expect(reply.pid).toBe('0D');
    // expect(reply.min).toBe(0);
    // expect(reply.max).toBe(255);
    // expect(reply.unit).toBe('km/h');
  });
});
