|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from 'modules/beopBidAdapter.js'; |
| 3 | +import { newBidder } from 'src/adapters/bidderFactory.js'; |
| 4 | +const utils = require('src/utils'); |
| 5 | + |
| 6 | +const ENDPOINT = 'https://hb.beop.io/bid'; |
| 7 | + |
| 8 | +let validBid = { |
| 9 | + 'bidder': 'beop', |
| 10 | + 'params': { |
| 11 | + 'accountId': '5a8af500c9e77c00017e4cad' |
| 12 | + }, |
| 13 | + 'adUnitCode': 'bellow-article', |
| 14 | + 'mediaTypes': { |
| 15 | + 'banner': { |
| 16 | + 'sizes': [[1, 1]] |
| 17 | + } |
| 18 | + }, |
| 19 | + 'bidId': '30b31c1838de1e', |
| 20 | + 'bidderRequestId': '22edbae2733bf6', |
| 21 | + 'auctionId': '1d1a030790a475', |
| 22 | + 'transactionId': '04f2659e-c005-4eb1-a57c-fa93145e3843', |
| 23 | + 'creativeId': 'er2ee' |
| 24 | +}; |
| 25 | + |
| 26 | +describe('BeOp Bid Adapter tests', () => { |
| 27 | + const adapter = newBidder(spec); |
| 28 | + |
| 29 | + describe('inherited functions', () => { |
| 30 | + it('exists and is a function', () => { |
| 31 | + expect(adapter.callBids).to.exist.and.to.be.a('function'); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('isBidRequestValid', function() { |
| 36 | + it('should return true when accountId params found', function () { |
| 37 | + expect(spec.isBidRequestValid(validBid)).to.equal(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return true if no accountId but networkId', function () { |
| 41 | + let bid = Object.assign({}, validBid); |
| 42 | + delete bid.params; |
| 43 | + bid.params = { |
| 44 | + 'networkId': '5a8af500c9e77c00017e4aaa' |
| 45 | + }; |
| 46 | + expect(spec.isBidRequestValid(bid)).to.equal(true); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return false if neither account or network id param found', function () { |
| 50 | + let bid = Object.assign({}, validBid); |
| 51 | + delete bid.params; |
| 52 | + bid.params = { |
| 53 | + 'someId': '5a8af500c9e77c00017e4aaa' |
| 54 | + }; |
| 55 | + expect(spec.isBidRequestValid(bid)).to.equal(false); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return false if account Id param is not an ObjectId', function () { |
| 59 | + let bid = Object.assign({}, validBid); |
| 60 | + delete bid.params; |
| 61 | + bid.params = { |
| 62 | + 'someId': '12345' |
| 63 | + }; |
| 64 | + expect(spec.isBidRequestValid(bid)).to.equal(false); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should return false if there is no banner media type', function () { |
| 68 | + let bid = Object.assign({}, validBid); |
| 69 | + delete bid.mediaTypes; |
| 70 | + bid.mediaTypes = { |
| 71 | + 'native': { |
| 72 | + 'sizes': [[1, 1]] |
| 73 | + } |
| 74 | + }; |
| 75 | + expect(spec.isBidRequestValid(bid)).to.equal(false); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('buildRequests', function () { |
| 80 | + let bidRequests = []; |
| 81 | + bidRequests.push(validBid); |
| 82 | + |
| 83 | + it('should build the request', function () { |
| 84 | + const request = spec.buildRequests(bidRequests, {}); |
| 85 | + const payload = JSON.parse(request.data); |
| 86 | + const url = request.url; |
| 87 | + expect(url).to.equal(ENDPOINT); |
| 88 | + expect(payload.pid).to.exist; |
| 89 | + expect(payload.pid).to.equal('5a8af500c9e77c00017e4cad'); |
| 90 | + expect(payload.slts[0].name).to.exist; |
| 91 | + expect(payload.slts[0].name).to.equal('bellow-article'); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should call the endpoint with GDPR consent and pageURL info if found', function () { |
| 95 | + let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; |
| 96 | + let bidderRequest = |
| 97 | + { |
| 98 | + 'gdprConsent': |
| 99 | + { |
| 100 | + 'gdprApplies': true, |
| 101 | + 'consentString': consentString |
| 102 | + }, |
| 103 | + 'refererInfo': |
| 104 | + { |
| 105 | + 'canonicalUrl': 'http://test.te' |
| 106 | + } |
| 107 | + }; |
| 108 | + |
| 109 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 110 | + const payload = JSON.parse(request.data); |
| 111 | + expect(payload.tc_string).to.exist; |
| 112 | + expect(payload.tc_string).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='); |
| 113 | + expect(payload.url).to.exist; |
| 114 | + expect(payload.url).to.equal('http://test.te'); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + describe('interpretResponse', function() { |
| 119 | + let serverResponse = { |
| 120 | + 'body': { |
| 121 | + 'bids': [ |
| 122 | + { |
| 123 | + 'requestId': 'aaaa', |
| 124 | + 'cpm': 1.0, |
| 125 | + 'currency': 'EUR', |
| 126 | + 'creativeId': '60f691be1515670a2a09aea2', |
| 127 | + 'netRevenue': true, |
| 128 | + 'width': 1, |
| 129 | + 'height': 1, |
| 130 | + 'ad': '<div class="BeOpWidget" data-content-id="60f691be1515670a2a09aea2" data-campaign-id="60f691bf1515670a2a09aea6" data-display-account-id="60f691be1515670a2a09aea1"></div>', |
| 131 | + 'meta': { |
| 132 | + 'advertiserId': '60f691be1515670a2a09aea1' |
| 133 | + } |
| 134 | + } |
| 135 | + ] |
| 136 | + } |
| 137 | + } |
| 138 | + it('should interpret the response by pushing it in the bids elem', function () { |
| 139 | + const response = spec.interpretResponse(serverResponse, validBid); |
| 140 | + |
| 141 | + expect(response[0].ad).to.exist; |
| 142 | + expect(response[0].requestId).to.exist; |
| 143 | + expect(response[0].requestId).to.equal('aaaa'); |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + describe('timeout and bid won pixel trigger', function () { |
| 148 | + let triggerPixelStub; |
| 149 | + |
| 150 | + beforeEach(function () { |
| 151 | + triggerPixelStub = sinon.stub(utils, 'triggerPixel'); |
| 152 | + }); |
| 153 | + |
| 154 | + afterEach(function () { |
| 155 | + utils.triggerPixel.restore(); |
| 156 | + }); |
| 157 | + |
| 158 | + it('should call triggerPixel utils function when timed out is filled', function () { |
| 159 | + spec.onTimeout({}); |
| 160 | + spec.onTimeout(); |
| 161 | + expect(triggerPixelStub.getCall(0)).to.be.null; |
| 162 | + spec.onTimeout({params: {accountId: '5a8af500c9e77c00017e4cad'}, timeout: 2000}); |
| 163 | + expect(triggerPixelStub.getCall(0)).to.not.be.null; |
| 164 | + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://t.beop.io'); |
| 165 | + expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ca=bid'); |
| 166 | + expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ac=timeout'); |
| 167 | + expect(triggerPixelStub.getCall(0).args[0]).to.include('pid=5a8af500c9e77c00017e4cad'); |
| 168 | + }); |
| 169 | + |
| 170 | + it('should call triggerPixel utils function on bid won', function () { |
| 171 | + spec.onBidWon({}); |
| 172 | + spec.onBidWon(); |
| 173 | + expect(triggerPixelStub.getCall(0)).to.be.null; |
| 174 | + spec.onBidWon({params: {accountId: '5a8af500c9e77c00017e4cad'}, cpm: 1.2}); |
| 175 | + expect(triggerPixelStub.getCall(0)).to.not.be.null; |
| 176 | + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://t.beop.io'); |
| 177 | + expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ca=bid'); |
| 178 | + expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ac=won'); |
| 179 | + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad'); |
| 180 | + }); |
| 181 | + }); |
| 182 | +}); |
0 commit comments