|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from 'modules/radsBidAdapter'; |
| 3 | +import { newBidder } from 'src/adapters/bidderFactory'; |
| 4 | + |
| 5 | +const RADS_ENDPOINT_URL = 'https://rads.recognified.net/md.request.php'; |
| 6 | + |
| 7 | +describe('radsAdapter', function () { |
| 8 | + const adapter = newBidder(spec); |
| 9 | + |
| 10 | + describe('isBidRequestValid', function () { |
| 11 | + let bid = { |
| 12 | + 'bidder': 'rads', |
| 13 | + 'params': { |
| 14 | + 'placement': '6682', |
| 15 | + 'pfilter': { |
| 16 | + 'floorprice': 1000000 |
| 17 | + }, |
| 18 | + 'bcat': 'IAB2,IAB4', |
| 19 | + 'dvt': 'desktop', |
| 20 | + 'ip': '1.1.1.1' |
| 21 | + }, |
| 22 | + 'sizes': [ |
| 23 | + [300, 250] |
| 24 | + ], |
| 25 | + 'bidId': '30b31c1838de1e', |
| 26 | + 'bidderRequestId': '22edbae2733bf6', |
| 27 | + 'auctionId': '1d1a030790a475' |
| 28 | + }; |
| 29 | + |
| 30 | + it('should return true when required params found', function () { |
| 31 | + expect(spec.isBidRequestValid(bid)).to.equal(true); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return false when required params are not passed', function () { |
| 35 | + let bid = Object.assign({}, bid); |
| 36 | + delete bid.params; |
| 37 | + bid.params = { |
| 38 | + 'someIncorrectParam': 0 |
| 39 | + }; |
| 40 | + expect(spec.isBidRequestValid(bid)).to.equal(false); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('buildRequests', function () { |
| 45 | + let bidRequests = [{ |
| 46 | + 'bidder': 'rads', |
| 47 | + 'params': { |
| 48 | + 'placement': '6682', |
| 49 | + 'pfilter': { |
| 50 | + 'floorprice': 1000000, |
| 51 | + 'geo': { |
| 52 | + 'country': 'DE' |
| 53 | + } |
| 54 | + }, |
| 55 | + 'bcat': 'IAB2,IAB4', |
| 56 | + 'dvt': 'desktop', |
| 57 | + 'ip': '1.1.1.1' |
| 58 | + }, |
| 59 | + 'sizes': [ |
| 60 | + [300, 250] |
| 61 | + ], |
| 62 | + 'bidId': '30b31c1838de1e', |
| 63 | + 'bidderRequestId': '22edbae2733bf6', |
| 64 | + 'auctionId': '1d1a030790a475' |
| 65 | + }, { |
| 66 | + 'bidder': 'rads', |
| 67 | + 'params': { |
| 68 | + 'placement': '6682', |
| 69 | + 'pfilter': { |
| 70 | + 'floorprice': 1000000, |
| 71 | + 'geo': { |
| 72 | + 'country': 'DE', |
| 73 | + 'region': 'DE-BE' |
| 74 | + }, |
| 75 | + }, |
| 76 | + 'bcat': 'IAB2,IAB4', |
| 77 | + 'dvt': 'desktop' |
| 78 | + }, |
| 79 | + 'mediaTypes': { |
| 80 | + 'video': { |
| 81 | + 'playerSize': [640, 480], |
| 82 | + 'context': 'instream' |
| 83 | + } |
| 84 | + }, |
| 85 | + 'bidId': '30b31c1838de1e', |
| 86 | + 'bidderRequestId': '22edbae2733bf6', |
| 87 | + 'auctionId': '1d1a030790a475' |
| 88 | + }]; |
| 89 | + |
| 90 | + let bidderRequest = { |
| 91 | + refererInfo: { |
| 92 | + referer: 'some_referrer.net' |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 97 | + it('sends bid request to our endpoint via GET', function () { |
| 98 | + expect(request[0].method).to.equal('GET'); |
| 99 | + let data = request[0].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid'); |
| 100 | + expect(data).to.equal('rt=bid-response&_f=prebid_js&_ps=6682&srw=300&srh=250&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop&i=1.1.1.1'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('sends bid video request to our rads endpoint via GET', function () { |
| 104 | + expect(request[1].method).to.equal('GET'); |
| 105 | + let data = request[1].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid'); |
| 106 | + expect(data).to.equal('rt=vast2&_f=prebid_js&_ps=6682&srw=640&srh=480&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgeo%5D%5Bregion%5D=DE-BE&bcat=IAB2%2CIAB4&dvt=desktop'); |
| 107 | + }); |
| 108 | + }); |
| 109 | + |
| 110 | + describe('interpretResponse', function () { |
| 111 | + let serverBannerResponse = { |
| 112 | + 'body': { |
| 113 | + 'cpm': 5000000, |
| 114 | + 'crid': 100500, |
| 115 | + 'width': '300', |
| 116 | + 'height': '250', |
| 117 | + 'adTag': '<!-- test creative -->', |
| 118 | + 'requestId': '220ed41385952a', |
| 119 | + 'currency': 'EUR', |
| 120 | + 'ttl': 60, |
| 121 | + 'netRevenue': true, |
| 122 | + 'zone': '6682' |
| 123 | + } |
| 124 | + }; |
| 125 | + let serverVideoResponse = { |
| 126 | + 'body': { |
| 127 | + 'cpm': 5000000, |
| 128 | + 'crid': 100500, |
| 129 | + 'width': '300', |
| 130 | + 'height': '250', |
| 131 | + 'vastXml': '{"reason":7001,"status":"accepted"}', |
| 132 | + 'requestId': '220ed41385952a', |
| 133 | + 'currency': 'EUR', |
| 134 | + 'ttl': 60, |
| 135 | + 'netRevenue': true, |
| 136 | + 'zone': '6682' |
| 137 | + } |
| 138 | + }; |
| 139 | + |
| 140 | + let expectedResponse = [{ |
| 141 | + requestId: '23beaa6af6cdde', |
| 142 | + cpm: 0.5, |
| 143 | + width: 0, |
| 144 | + height: 0, |
| 145 | + creativeId: 100500, |
| 146 | + dealId: '', |
| 147 | + currency: 'EUR', |
| 148 | + netRevenue: true, |
| 149 | + ttl: 300, |
| 150 | + ad: '<!-- test creative -->' |
| 151 | + }, { |
| 152 | + requestId: '23beaa6af6cdde', |
| 153 | + cpm: 0.5, |
| 154 | + width: 0, |
| 155 | + height: 0, |
| 156 | + creativeId: 100500, |
| 157 | + dealId: '', |
| 158 | + currency: 'EUR', |
| 159 | + netRevenue: true, |
| 160 | + ttl: 300, |
| 161 | + vastXml: '{"reason":7001,"status":"accepted"}', |
| 162 | + mediaType: 'video' |
| 163 | + }]; |
| 164 | + |
| 165 | + it('should get the correct bid response by display ad', function () { |
| 166 | + let bidRequest = [{ |
| 167 | + 'method': 'GET', |
| 168 | + 'url': RADS_ENDPOINT_URL, |
| 169 | + 'refererInfo': { |
| 170 | + 'referer': '' |
| 171 | + }, |
| 172 | + 'data': { |
| 173 | + 'bid_id': '30b31c1838de1e' |
| 174 | + } |
| 175 | + }]; |
| 176 | + let result = spec.interpretResponse(serverBannerResponse, bidRequest[0]); |
| 177 | + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); |
| 178 | + }); |
| 179 | + |
| 180 | + it('should get the correct rads video bid response by display ad', function () { |
| 181 | + let bidRequest = [{ |
| 182 | + 'method': 'GET', |
| 183 | + 'url': RADS_ENDPOINT_URL, |
| 184 | + 'mediaTypes': { |
| 185 | + 'video': { |
| 186 | + 'playerSize': [640, 480], |
| 187 | + 'context': 'instream' |
| 188 | + } |
| 189 | + }, |
| 190 | + 'data': { |
| 191 | + 'bid_id': '30b31c1838de1e' |
| 192 | + } |
| 193 | + }]; |
| 194 | + let result = spec.interpretResponse(serverVideoResponse, bidRequest[0]); |
| 195 | + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[1])); |
| 196 | + }); |
| 197 | + |
| 198 | + it('handles empty bid response', function () { |
| 199 | + let response = { |
| 200 | + body: {} |
| 201 | + }; |
| 202 | + let result = spec.interpretResponse(response); |
| 203 | + expect(result.length).to.equal(0); |
| 204 | + }); |
| 205 | + }); |
| 206 | +}); |
0 commit comments