import { expect } from 'chai';
import Adapter from 'modules/ucfunnelBidAdapter';
import adapterManager from 'src/adaptermanager';
import bidManager from 'src/bidmanager';
import CONSTANTS from 'src/constants.json';

describe('ucfunnel adapter tests', function () {
  let sandbox;
  const adUnit = { // TODO CHANGE
    code: 'ucfunnel',
    sizes: [[300, 250]],
    bids: [{
      bidder: 'ucfunnel',
      params: {
        adid: 'test-ad-83444226E44368D1E32E49EEBE6D29',
        width: 300,
        height: 250
      }
    }]
  };

  const response = {
    ad_id: 'ad-83444226E44368D1E32E49EEBE6D29',
    adm: '<html style="height:100%"><body style="width:300px;height: 100%;padding:0;margin:0 auto;"><div style="width:100%;height:100%;display:table;"><div style="width:100%;height:100%;display:table-cell;text-align:center;vertical-align:middle;"><a href="//www.ucfunnel.com/" target="_blank"><img src="//cdn.aralego.net/ucfad/house/ucf/AdGent-300x250.jpg" width="300px" height="250px" align="middle" style="border:none"></a></div></div></body></html>',
    cpm: 0.01,
    height: 250,
    width: 300
  };

  beforeEach(() => {
    sandbox = sinon.sandbox.create();
  });

  afterEach(() => {
    sandbox.restore();
  });

  describe('ucfunnel callBids validation', () => {
    let bids,
      server;

    beforeEach(() => {
      bids = [];
      server = sinon.fakeServer.create();

      sandbox.stub(bidManager, 'addBidResponse', (elemId, bid) => {
        bids.push(bid);
      });
    });

    afterEach(() => {
      server.restore();
    });

    let adapter = adapterManager.bidderRegistry['ucfunnel'];

    it('Valid bid-request', () => {
      sandbox.stub(adapter, 'callBids');
      adapterManager.callBids({
        adUnits: [clone(adUnit)]
      });

      let bidderRequest = adapter.callBids.getCall(0).args[0];

      expect(bidderRequest).to.have.property('bids')
                .that.is.an('array')
                .with.lengthOf(1);

      expect(bidderRequest).to.have.deep.property('bids[0]')
                .to.have.property('bidder', 'ucfunnel');

      expect(bidderRequest).to.have.deep.property('bids[0]')
                .with.property('sizes')
                .that.is.an('array')
                .with.lengthOf(1)
                .that.deep.equals(adUnit.sizes);
      expect(bidderRequest).to.have.deep.property('bids[0]')
                .with.property('params')
                .to.have.property('adid', 'test-ad-83444226E44368D1E32E49EEBE6D29');
      expect(bidderRequest).to.have.deep.property('bids[0]')
                .with.property('params')
                .to.have.property('width', 300);
    });

    it('Valid bid-response', () => {
      server.respondWith(JSON.stringify(
        response
      ));
      adapterManager.callBids({
        adUnits: [clone(adUnit)]
      });
      server.respond();

      expect(bids).to.be.lengthOf(1);
      expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD);
      expect(bids[0].bidderCode).to.equal('ucfunnel');
      expect(bids[0].width).to.equal(300);
      expect(bids[0].height).to.equal(250);
      expect(bids[0].cpm).to.equal(0.01);
    });
  });
});

function clone(obj) {
  try {
    return JSON.parse(JSON.stringify(obj));
  } catch (e) {
    return {};
  }
}

@@ -1875,32 +1875,24 @@
 rty('bids')%0A
-        
         .tha
@@ -1904,32 +1904,24 @@
 an('array')%0A
-        
         .wit
@@ -1993,32 +1993,24 @@
 ('bids%5B0%5D')%0A
-        
         .to.
@@ -2104,32 +2104,24 @@
 ('bids%5B0%5D')%0A
-        
         .wit
@@ -2144,32 +2144,24 @@
 s')%0A        
-    
-    
 .that.is.an(
@@ -2169,24 +2169,16 @@
 array')%0A
-        
         
@@ -2195,24 +2195,16 @@
 thOf(1)%0A
-        
         
@@ -2293,32 +2293,24 @@
 ('bids%5B0%5D')%0A
-        
         .wit
@@ -2326,32 +2326,24 @@
 y('params')%0A
-        
         .to.
@@ -2468,24 +2468,16 @@
 ds%5B0%5D')%0A
-        
         
@@ -2501,24 +2501,16 @@
 arams')%0A
-        
         

Fix spacing for lint rules (#1366)