it('should return false when only one of placementKey and publisherId is present', function () {
   let bid = {
     params: {
       publisherId: 1234
     }
   };
   expect(spec.isBidRequestValid(bid)).to.equal(false);
   bid = {
     params: {
       placementKey: 'xyz'
     }
   };
   expect(spec.isBidRequestValid(bid)).to.equal(false);
 });
 it('should return 2 requests', function () {
   const requests = spec.buildRequests([
     simpleBidRequest,
     simpleSmartTagBidRequest
   ]);
   expect(requests).to.be.an('array');
   expect(requests.length).to.equal(2);
 });
 it('should add currency', function () {
   const bidRequest = Object.assign({}, simpleBidRequest);
   const getConfigStub = sinon.stub(config, 'getConfig').returns('JPY');
   const request = spec.buildRequests([bidRequest])[0];
   const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.imp[0].currency).to.equal('JPY');
   getConfigStub.restore();
 });
 it('should return user syncs', function () {
   const syncs = spec.getUserSyncs({ pixelEnabled: true }, serverResponses);
   const expected = [
     { type: 'image', url: 'http://link1' },
     { type: 'image', url: 'http://link2' },
     { type: 'image', url: 'http://link3' }
   ];
   expect(syncs).to.deep.equal(expected);
 });
    it('should set dealId correctly', () => {
      let response = JSON.parse(JSON.stringify(serverResponse));
      let bids;

      response.body.bid[0].lid = 'xyz';
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = 268515;
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.equal(268515);

      response.body.bid[0].lid = {
        1: 268515
      };
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.equal(268515);
    });
 it('should return one request in a single request mode', function () {
   const getConfigStub = sinon.stub(config, 'getConfig');
   getConfigStub.withArgs('improvedigital.singleRequest').returns(true);
   const requests = spec.buildRequests([
     simpleBidRequest,
     simpleSmartTagBidRequest
   ]);
   expect(requests).to.be.an('array');
   expect(requests.length).to.equal(1);
   getConfigStub.restore();
 });
 it('should add size', () => {
   let bidRequest = Object.assign({}, simpleBidRequest);
   const size = {
     w: 800,
     h: 600
   };
   bidRequest.params.size = size;
   const request = spec.buildRequests([bidRequest])[0];
   const params = JSON.parse(request.data.substring(PARAM_PREFIX.length));
   expect(params.bid_request.imp[0].banner).to.deep.equal(size);
 });
 it('should add keyValues', function () {
   let bidRequest = Object.assign({}, simpleBidRequest);
   const keyValues = {
     testKey: [
       'testValue'
     ]
   };
   bidRequest.params.keyValues = keyValues;
   const request = spec.buildRequests([bidRequest])[0];
   const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.imp[0].kvw).to.deep.equal(keyValues);
 });
    it('should return empty array for bad response or no price', function () {
      let response = JSON.parse(JSON.stringify(serverResponse));
      let bids;

      // Price missing or 0
      response.body.bid[0].price = 0;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);
      delete response.body.bid[0].price;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);
      response.body.bid[0].price = null;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);

      // errorCode present
      response = JSON.parse(JSON.stringify(serverResponse));
      response.body.bid[0].errorCode = undefined;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);

      // adm and native missing
      response = JSON.parse(JSON.stringify(serverResponse));
      delete response.body.bid[0].adm;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);
      response.body.bid[0].adm = null;
      bids = spec.interpretResponse(response);
      expect(bids).to.deep.equal([]);
    });
 it('should set Prebid sizes in bid request', function () {
   const getConfigStub = sinon.stub(config, 'getConfig');
   getConfigStub.withArgs('improvedigital.usePrebidSizes').returns(true);
   const request = spec.buildRequests([simpleBidRequest])[0];
   const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.imp[0].banner).to.deep.equal({
     format: [
       { w: 300, h: 250 },
       { w: 160, h: 600 }
     ]
   });
   getConfigStub.restore();
 });
 it('should add single size filter', function () {
   let bidRequest = Object.assign({}, simpleBidRequest);
   const size = {
     w: 800,
     h: 600
   };
   bidRequest.params.size = size;
   const request = spec.buildRequests([bidRequest])[0];
   const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.imp[0].banner).to.deep.equal(size);
   // When single size filter is set, format shouldn't be populated. This
   // is to maintain backward compatibily
   expect(params.bid_request.imp[0].banner.format).to.not.exist;
 });
    it('should make a well-formed request objects', function () {
      const requests = spec.buildRequests([simpleBidRequest]);
      expect(requests).to.be.an('array');
      expect(requests.length).to.equal(1);

      const request = requests[0];
      expect(request.method).to.equal(METHOD);
      expect(request.url).to.equal(URL);
      expect(request.data.substring(0, PARAM_PREFIX.length)).to.equal(PARAM_PREFIX);

      const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
      expect(params.bid_request).to.be.an('object');
      expect(params.bid_request.id).to.be.a('string');
      expect(params.bid_request.version).to.equal(`${spec.version}-${idClient.CONSTANTS.CLIENT_VERSION}`);
      expect(params.bid_request.imp).to.deep.equal([
        {
          id: '33e9500b21129f',
          pid: 1053688,
          tid: 'f183e871-fbed-45f0-a427-c8a63c4c01eb',
          banner: {}
        }
      ]);
    });
    it('should set dealId correctly', function () {
      let response = JSON.parse(JSON.stringify(serverResponse));
      let bids;

      delete response.body.bid[0].lid;
      response.body.bid[0].buying_type = 'deal_id';
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = 268515;
      delete response.body.bid[0].buying_type;
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = 268515;
      response.body.bid[0].buying_type = 'classic';
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = 268515;
      response.body.bid[0].buying_type = 'deal_id';
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.equal(268515);

      response.body.bid[0].lid = [ 268515, 12456, 34567 ];
      response.body.bid[0].buying_type = 'deal_id';
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = [ 268515, 12456, 34567 ];
      response.body.bid[0].buying_type = [ 'deal_id', 'classic' ];
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.not.exist;

      response.body.bid[0].lid = [ 268515, 12456, 34567 ];
      response.body.bid[0].buying_type = [ 'classic', 'deal_id', 'deal_id' ];
      bids = spec.interpretResponse(response);
      expect(bids[0].dealId).to.equal(12456);
    });
 it('should return true when placementId is passed', function () {
   let bid = { 'params': {} };
   expect(spec.isBidRequestValid(simpleBidRequest)).to.equal(true);
 });
 it('should return true when both placementKey and publisherId are passed', function () {
   let bid = { 'params': {} };
   expect(spec.isBidRequestValid(simpleSmartTagBidRequest)).to.equal(true);
 });
 it('should add GDPR consent string', function () {
   const bidRequest = Object.assign({}, simpleBidRequest);
   const request = spec.buildRequests([bidRequest], bidderRequest)[0];
   const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.gdpr).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
 });
 it('should set placementKey and publisherId for smart tags', function () {
   const requests = spec.buildRequests([simpleSmartTagBidRequest]);
   const params = JSON.parse(decodeURIComponent(requests[0].data.substring(PARAM_PREFIX.length)));
   expect(params.bid_request.imp[0].pubid).to.equal(1032);
   expect(params.bid_request.imp[0].pkey).to.equal('data_team_test_hb_smoke_test');
 });
 it('should return a well-formed native ad bid', function () {
   const bids = spec.interpretResponse(serverResponseNative);
   expect(bids).to.deep.equal(expectedBidNative);
 });
 it('should return no syncs when pixel syncing is disabled', function () {
   const syncs = spec.getUserSyncs({ pixelEnabled: false }, serverResponses);
   expect(syncs).to.deep.equal([]);
 });
 it('should set netRevenue', function () {
   let response = JSON.parse(JSON.stringify(serverResponse));
   response.body.bid[0].isNet = true;
   const bids = spec.interpretResponse(response);
   expect(bids[0].netRevenue).to.equal(true);
 });
 it('should return false when both placementId and placementKey + publisherId are missing', function () {
   let bid = { 'params': {} };
   expect(spec.isBidRequestValid(bid)).to.equal(false);
 });
 it('should return false when no bid', function () {
   expect(spec.isBidRequestValid()).to.equal(false);
 });
 it('should set currency', function () {
   let response = JSON.parse(JSON.stringify(serverResponse));
   response.body.bid[0].currency = 'eur';
   const bids = spec.interpretResponse(response);
   expect(bids[0].currency).to.equal('EUR');
 });
 it('should return false when no bid.params', function () {
   let bid = {};
   expect(spec.isBidRequestValid(bid)).to.equal(false);
 });
 it('should return a well-formed bid', () => {
   const bids = spec.interpretResponse(serverResponse);
   expect(bids).to.deep.equal(expectedBid);
 });
 it('should return two bids', function () {
   const bids = spec.interpretResponse(serverResponseTwoBids);
   expect(bids).to.deep.equal(expectedTwoBids);
 });