|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from 'modules/audiencerunBidAdapter'; |
| 3 | +import { newBidder } from 'src/adapters/bidderFactory'; |
| 4 | + |
| 5 | +const ENDPOINT = 'https://d.audiencerun.com/prebid'; |
| 6 | + |
| 7 | +const BID_SERVER_RESPONSE = { |
| 8 | + body: { |
| 9 | + bid: [ |
| 10 | + { |
| 11 | + 'bidId': '51ef8751f9aead', |
| 12 | + 'zoneId': '12345abcde', |
| 13 | + 'adId': '1234', |
| 14 | + 'crid': '5678', |
| 15 | + 'cpm': 8.021951999999999999, |
| 16 | + 'currency': 'USD', |
| 17 | + 'w': 728, |
| 18 | + 'h': 90, |
| 19 | + 'isNet': false, |
| 20 | + 'buying_type': 'rtb', |
| 21 | + 'syncUrl': 'https://ac.audiencerun.com/f/sync.html', |
| 22 | + 'adm': '<!-- test creative -->' |
| 23 | + } |
| 24 | + ] |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +describe('AudienceRun bid adapter tests', function() { |
| 29 | + const adapter = newBidder(spec); |
| 30 | + |
| 31 | + describe('inherited functions', function() { |
| 32 | + it('exists and is a function', function() { |
| 33 | + expect(adapter.callBids).to.exist.and.to.be.a('function'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('isBidRequestValid', function() { |
| 38 | + let bid = { |
| 39 | + 'bidder': 'audiencerun', |
| 40 | + 'params': { |
| 41 | + 'zoneId': '12345abcde' |
| 42 | + }, |
| 43 | + 'adUnitCode': 'adunit-code', |
| 44 | + 'mediaTypes': { |
| 45 | + 'banner': { |
| 46 | + 'sizes': [[300, 250], [300, 600]] |
| 47 | + } |
| 48 | + }, |
| 49 | + 'bidId': '30b31c1838de1e', |
| 50 | + 'bidderRequestId': '22edbae2733bf6', |
| 51 | + 'auctionId': '1d1a030790a475', |
| 52 | + 'creativeId': 'er2ee' |
| 53 | + }; |
| 54 | + |
| 55 | + it('should return true when required params found', function() { |
| 56 | + expect(spec.isBidRequestValid(bid)).to.equal(true); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should return true when zoneId is valid', function() { |
| 60 | + let bid = Object.assign({}, bid); |
| 61 | + delete bid.params; |
| 62 | + bid.params = { |
| 63 | + 'zoneId': '12345abcde' |
| 64 | + }; |
| 65 | + |
| 66 | + expect(spec.isBidRequestValid(bid)).to.equal(true); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return false when required params are not passed', function() { |
| 70 | + let bid = Object.assign({}, bid); |
| 71 | + delete bid.params; |
| 72 | + |
| 73 | + bid.params = {}; |
| 74 | + |
| 75 | + expect(spec.isBidRequestValid(bid)).to.equal(false); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('buildRequests', function() { |
| 80 | + let bidRequests = [ |
| 81 | + { |
| 82 | + 'bidder': 'audiencerun', |
| 83 | + 'bidId': '51ef8751f9aead', |
| 84 | + 'params': { |
| 85 | + 'zoneId': '12345abcde' |
| 86 | + }, |
| 87 | + 'adUnitCode': 'div-gpt-ad-1460505748561-0', |
| 88 | + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', |
| 89 | + 'mediaTypes': { |
| 90 | + 'banner': { |
| 91 | + 'sizes': [[320, 50], [300, 250], [300, 600]] |
| 92 | + } |
| 93 | + }, |
| 94 | + 'bidderRequestId': '418b37f85e772c', |
| 95 | + 'auctionId': '18fd8b8b0bd757', |
| 96 | + 'bidRequestsCount': 1 |
| 97 | + } |
| 98 | + ]; |
| 99 | + |
| 100 | + it('sends a valid bid request to ENDPOINT via POST', function() { |
| 101 | + const request = spec.buildRequests(bidRequests, { |
| 102 | + gdprConsent: { |
| 103 | + consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', |
| 104 | + gdprApplies: true |
| 105 | + }, |
| 106 | + refererInfo: { |
| 107 | + canonicalUrl: 'https://example.com/canonical', |
| 108 | + referer: 'https://example.com' |
| 109 | + } |
| 110 | + }); |
| 111 | + |
| 112 | + expect(request.url).to.equal(ENDPOINT); |
| 113 | + expect(request.method).to.equal('POST'); |
| 114 | + |
| 115 | + const payload = JSON.parse(request.data); |
| 116 | + expect(payload.gdpr).to.exist; |
| 117 | + |
| 118 | + expect(payload.bids).to.exist.and.to.be.an('array').and.to.have.lengthOf(1); |
| 119 | + expect(payload.referer).to.exist; |
| 120 | + |
| 121 | + const bid = payload.bids[0]; |
| 122 | + expect(bid).to.exist; |
| 123 | + expect(bid).to.have.property('bidId'); |
| 124 | + expect(bid).to.have.property('zoneId'); |
| 125 | + expect(bid).to.have.property('sizes'); |
| 126 | + expect(bid.sizes[0].w).to.be.a('number'); |
| 127 | + expect(bid.sizes[0].h).to.be.a('number'); |
| 128 | + }); |
| 129 | + |
| 130 | + it('should send GDPR to endpoint and honor gdprApplies value', function() { |
| 131 | + let consentString = 'bogusConsent'; |
| 132 | + let bidderRequest = { |
| 133 | + 'gdprConsent': { |
| 134 | + 'consentString': consentString, |
| 135 | + 'gdprApplies': true |
| 136 | + } |
| 137 | + }; |
| 138 | + |
| 139 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 140 | + const payload = JSON.parse(request.data); |
| 141 | + expect(payload.gdpr).to.exist; |
| 142 | + expect(payload.gdpr.consent).to.equal(consentString); |
| 143 | + expect(payload.gdpr.applies).to.equal(true); |
| 144 | + |
| 145 | + let bidderRequest2 = { |
| 146 | + 'gdprConsent': { |
| 147 | + 'consentString': consentString, |
| 148 | + 'gdprApplies': false |
| 149 | + } |
| 150 | + }; |
| 151 | + |
| 152 | + const request2 = spec.buildRequests(bidRequests, bidderRequest2); |
| 153 | + const payload2 = JSON.parse(request2.data); |
| 154 | + |
| 155 | + expect(payload2.gdpr).to.exist; |
| 156 | + expect(payload2.gdpr.consent).to.equal(consentString); |
| 157 | + expect(payload2.gdpr.applies).to.equal(false); |
| 158 | + }); |
| 159 | + }); |
| 160 | + |
| 161 | + describe('interpretResponse', function () { |
| 162 | + const expectedResponse = [{ |
| 163 | + 'requestId': '51ef8751f9aead', |
| 164 | + 'adId': '12345abcde', |
| 165 | + 'cpm': 8.021951999999999999, |
| 166 | + 'width': '728', |
| 167 | + 'height': '90', |
| 168 | + 'creativeId': '5678', |
| 169 | + 'currency': 'USD', |
| 170 | + 'netRevenue': false, |
| 171 | + 'ttl': 300, |
| 172 | + 'ad': '<!-- test creative -->', |
| 173 | + 'mediaType': 'banner' |
| 174 | + }]; |
| 175 | + |
| 176 | + it('should get the correct bid response by display ad', function () { |
| 177 | + let result = spec.interpretResponse(BID_SERVER_RESPONSE); |
| 178 | + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); |
| 179 | + }); |
| 180 | + |
| 181 | + it('handles empty bid response', function () { |
| 182 | + const response = { |
| 183 | + body: {} |
| 184 | + }; |
| 185 | + let result = spec.interpretResponse(response); |
| 186 | + expect(result.length).to.equal(0); |
| 187 | + }); |
| 188 | + }); |
| 189 | + |
| 190 | + describe('getUserSyncs', function () { |
| 191 | + const serverResponses = [ BID_SERVER_RESPONSE ]; |
| 192 | + const syncOptions = { iframeEnabled: true }; |
| 193 | + |
| 194 | + it('should return empty if no server responses', function() { |
| 195 | + const syncs = spec.getUserSyncs(syncOptions, []); |
| 196 | + expect(syncs).to.deep.equal([]) |
| 197 | + }); |
| 198 | + |
| 199 | + it('should return user syncs', function () { |
| 200 | + const syncs = spec.getUserSyncs(syncOptions, serverResponses); |
| 201 | + expect(syncs).to.deep.equal([{type: 'iframe', url: 'https://ac.audiencerun.com/f/sync.html'}]) |
| 202 | + }); |
| 203 | + }); |
| 204 | +}); |
0 commit comments