/**
 * @fileOverview Test initialization of the KafkaAvro lib, SR related.
 */
var chai = require('chai');
var expect = chai.expect;

var KafkaAvro = require('../..');

var srUrl = 'http://schema-registry-confluent.internal.dev.waldo.photos';

describe('Initialization of RS', function() {
  it('should initialize properly', function() {
    var kafkaAvro = new KafkaAvro({
      schemaRegistry: srUrl,
    });

    return kafkaAvro.init()
      .map((res) => {
        expect(res).to.have.keys([
          'schemaType',
          'topic',
          'schemaRaw',
          'schemaTopicRaw',
          'type',
        ]);
      })
      .then((all) => {
        expect(all).to.have.length.of.at.least(1);
      });
  });
});

/**
 * @fileOverview Test initialization of the KafkaAvro lib, SR related.
 */
var chai = require('chai');
var expect = chai.expect;

var KafkaAvro = require('../..');

// var srUrl = 'http://schema-registry-confluent.internal.dev.waldo.photos';
var srUrl = 'http://localhost:8081';

describe('Initialization of SR', function() {
  it('should initialize properly', function() {
    var kafkaAvro = new KafkaAvro({
      schemaRegistry: srUrl,
    });

    return kafkaAvro.init()
      .map((res) => {
        expect(res).to.have.keys([
          'responseRaw',
          'schemaType',
          'topic',
          'schemaRaw',
          'schemaTopicRaw',
          'type',
        ]);

        expect(res.responseRaw).to.have.keys([
          'subject',
          'version',
          'id',
          'schema',
        ]);
      })
      .then((all) => {
        expect(all).to.have.length.of.at.least(1);
      });
  });
  it('kafkaAvro instance should contain expected values after init', function() {
    var kafkaAvro = new KafkaAvro({
      schemaRegistry: srUrl,
    });

    return kafkaAvro.init()
      .map((res) => {
        if (res.schemaType.toLowerCase() === 'value') {
          expect(kafkaAvro.valueSchemas[res.topic]).to.be.an('object');
          expect(kafkaAvro.schemaMeta[res.topic]).to.be.an('object');

          expect(kafkaAvro.schemaMeta[res.topic]).to.have.keys([
            'subject',
            'version',
            'id',
            'schema',
          ]);

        } else {
          expect(kafkaAvro.keySchemas[res.topic]).to.be.an('object');
        }
      })
      .then((all) => {
        expect(all).to.have.length.of.at.least(1);
      });
  });

});

tweak SR tests and add one more for ids