const Connection = require('../../src/connection');
const Request = require('../../src/request');
const TYPES = require('../../src/data-type').typeByName;

const fs = require('fs');
const { assert } = require('chai');

const config = JSON.parse(
  fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8')
).config;

config.options.debug = {
  packet: true,
  data: true,
  payload: true,
  token: true,
  log: true
};

config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION;

describe('inserting binary data', function() {
  this.timeout(60000);

  beforeEach(function(done) {
    this.connection = new Connection(config);
    this.connection.connect(done);
  });

  afterEach(function(done) {
    if (!this.connection.closed) {
      this.connection.on('end', done);
      this.connection.close();
    } else {
      done();
    }
  });

  it('should correctly insert the binary data', function(done) {
    const request = new Request('CREATE TABLE #test ([data] binary(4))', (err) => {
      if (err) {
        return done(err);
      }

      const request = new Request('INSERT INTO #test ([data]) VALUES (@p1)', (err) => {
        if (err) {
          return done(err);
        }

        const values = [];
        const request = new Request('SELECT [data] FROM #test', (err) => {
          if (err) {
            return done(err);
          }

          assert.deepEqual(values, [Buffer.from([0x12, 0x34, 0x00, 0xce])]);

          done();
        });

        request.on('row', function(columns) {
          values.push(columns[0].value);
        });

        this.connection.execSql(request);
      });

      request.addParameter('p1', TYPES.Binary, Buffer.from([0x12, 0x34, 0x00, 0xce]));
      this.connection.execSql(request);
    });

    this.connection.execSqlBatch(request);
  });
});

@@ -1,102 +1,81 @@
-const Connection = require('../../src/connection');%0Aconst Request = require('../../src/request
+// @ts-check%0A%0Aconst fs = require('fs');%0Aconst %7B assert %7D = require('chai
 ');%0A
+%0A
 cons
@@ -132,68 +132,94 @@
 e;%0A%0A
-const fs = require('fs');%0Aconst %7B assert %7D = require('chai')
+import Connection from '../../src/connection';%0Aimport Request from '../../src/request'
 ;%0A%0Ac
@@ -1208,32 +1208,65 @@
 rr);%0A        %7D%0A%0A
+        /** @type %7Bunknown%5B%5D%7D */%0A
         const va
@@ -1276,16 +1276,17 @@
 s = %5B%5D;%0A
+%0A
         

enable type checking for `test/integration/binary-insert-test.js`