|
| 1 | +import {expect} from 'chai'; |
| 2 | +import {spec} from 'modules/ipromBidAdapter.js'; |
| 3 | + |
| 4 | +describe('iPROM Adapter', function () { |
| 5 | + let bidRequests; |
| 6 | + let bidderRequest; |
| 7 | + |
| 8 | + beforeEach(function () { |
| 9 | + bidRequests = [ |
| 10 | + { |
| 11 | + bidder: 'iprom', |
| 12 | + params: { |
| 13 | + id: '1234', |
| 14 | + dimension: '300x250', |
| 15 | + }, |
| 16 | + adUnitCode: '/19966331/header-bid-tag-1', |
| 17 | + mediaTypes: { |
| 18 | + banner: { |
| 19 | + sizes: [[300, 250], [300, 600]], |
| 20 | + } |
| 21 | + }, |
| 22 | + bidId: '29a72b151f7bd3', |
| 23 | + auctionId: 'e36abb27-g3b1-1ad6-8a4c-701c8919d3hh', |
| 24 | + bidderRequestId: '2z76da40m1b3cb8', |
| 25 | + transactionId: 'j51lhf58-1ad6-g3b1-3j6s-912c9493g0gu' |
| 26 | + } |
| 27 | + ]; |
| 28 | + |
| 29 | + bidderRequest = { |
| 30 | + timeout: 3000, |
| 31 | + refererInfo: { |
| 32 | + referer: 'https://adserver.si/index.html', |
| 33 | + reachedTop: true, |
| 34 | + numIframes: 1, |
| 35 | + stack: [ |
| 36 | + 'https://adserver.si/index.html', |
| 37 | + 'https://adserver.si/iframe1.html', |
| 38 | + ] |
| 39 | + } |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + describe('validating bids', function () { |
| 44 | + it('should accept valid bid', function () { |
| 45 | + let validBid = { |
| 46 | + bidder: 'iprom', |
| 47 | + params: { |
| 48 | + id: '1234', |
| 49 | + dimension: '300x250', |
| 50 | + }, |
| 51 | + }; |
| 52 | + |
| 53 | + const isValid = spec.isBidRequestValid(validBid); |
| 54 | + |
| 55 | + expect(isValid).to.equal(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should reject bid if missing dimension and id', function () { |
| 59 | + let invalidBid = { |
| 60 | + bidder: 'iprom', |
| 61 | + params: {} |
| 62 | + }; |
| 63 | + |
| 64 | + const isValid = spec.isBidRequestValid(invalidBid); |
| 65 | + |
| 66 | + expect(isValid).to.equal(false); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should reject bid if missing dimension', function () { |
| 70 | + let invalidBid = { |
| 71 | + bidder: 'iprom', |
| 72 | + params: { |
| 73 | + id: '1234', |
| 74 | + } |
| 75 | + }; |
| 76 | + |
| 77 | + const isValid = spec.isBidRequestValid(invalidBid); |
| 78 | + |
| 79 | + expect(isValid).to.equal(false); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should reject bid if dimension is not a string', function () { |
| 83 | + let invalidBid = { |
| 84 | + bidder: 'iprom', |
| 85 | + params: { |
| 86 | + id: '1234', |
| 87 | + dimension: 404, |
| 88 | + } |
| 89 | + }; |
| 90 | + |
| 91 | + const isValid = spec.isBidRequestValid(invalidBid); |
| 92 | + |
| 93 | + expect(isValid).to.equal(false); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should reject bid if missing id', function () { |
| 97 | + let invalidBid = { |
| 98 | + bidder: 'iprom', |
| 99 | + params: { |
| 100 | + dimension: '300x250', |
| 101 | + } |
| 102 | + }; |
| 103 | + |
| 104 | + const isValid = spec.isBidRequestValid(invalidBid); |
| 105 | + |
| 106 | + expect(isValid).to.equal(false); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should reject bid if id is not a string', function () { |
| 110 | + let invalidBid = { |
| 111 | + bidder: 'iprom', |
| 112 | + params: { |
| 113 | + id: 1234, |
| 114 | + dimension: '300x250', |
| 115 | + } |
| 116 | + }; |
| 117 | + |
| 118 | + const isValid = spec.isBidRequestValid(invalidBid); |
| 119 | + |
| 120 | + expect(isValid).to.equal(false); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + describe('building requests', function () { |
| 125 | + it('should go to correct endpoint', function () { |
| 126 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 127 | + |
| 128 | + expect(request.method).to.exist; |
| 129 | + expect(request.method).to.equal('POST'); |
| 130 | + expect(request.url).to.exist; |
| 131 | + expect(request.url).to.equal('https://core.iprom.net/programmatic'); |
| 132 | + }); |
| 133 | + |
| 134 | + it('should add referer info', function () { |
| 135 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 136 | + const requestparse = JSON.parse(request.data); |
| 137 | + |
| 138 | + expect(requestparse.referer).to.exist; |
| 139 | + expect(requestparse.referer.referer).to.equal('https://adserver.si/index.html'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should add adapter version', function () { |
| 143 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 144 | + const requestparse = JSON.parse(request.data); |
| 145 | + |
| 146 | + expect(requestparse.version).to.exist; |
| 147 | + }); |
| 148 | + |
| 149 | + it('should contain id and dimension', function () { |
| 150 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 151 | + const requestparse = JSON.parse(request.data); |
| 152 | + |
| 153 | + expect(requestparse.bids[0].params.id).to.equal('1234'); |
| 154 | + expect(requestparse.bids[0].params.dimension).to.equal('300x250'); |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + describe('handling responses', function () { |
| 159 | + it('should return complete bid response', function () { |
| 160 | + const serverResponse = { |
| 161 | + body: [{ |
| 162 | + requestId: '29a72b151f7bd3', |
| 163 | + cpm: 0.5, |
| 164 | + width: '300', |
| 165 | + height: '250', |
| 166 | + creativeId: 1234, |
| 167 | + ad: '<html><head><title>Iprom Header bidding example</title></head><body><img src="https://iprom.si/files/2015/08/iprom-logo.svg"></body></html>' |
| 168 | + } |
| 169 | + ]}; |
| 170 | + |
| 171 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 172 | + const bids = spec.interpretResponse(serverResponse, request); |
| 173 | + |
| 174 | + expect(bids).to.be.lengthOf(1); |
| 175 | + expect(bids[0].requestId).to.equal('29a72b151f7bd3'); |
| 176 | + expect(bids[0].cpm).to.equal(0.5); |
| 177 | + expect(bids[0].width).to.equal('300'); |
| 178 | + expect(bids[0].height).to.equal('250'); |
| 179 | + expect(bids[0].ad).to.have.length.above(1); |
| 180 | + }); |
| 181 | + |
| 182 | + it('should return empty bid response', function () { |
| 183 | + const emptyServerResponse = { |
| 184 | + body: [] |
| 185 | + }; |
| 186 | + |
| 187 | + const request = spec.buildRequests(bidRequests, bidderRequest); |
| 188 | + const bids = spec.interpretResponse(emptyServerResponse, request); |
| 189 | + |
| 190 | + expect(bids).to.be.lengthOf(0); |
| 191 | + }); |
| 192 | + }); |
| 193 | +}); |
0 commit comments