|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from '../../../modules/loopmeBidAdapter'; |
| 3 | +import * as utils from 'src/utils'; |
| 4 | + |
| 5 | +describe('LoopMeAdapter', function () { |
| 6 | + const bidRequests = [{ |
| 7 | + bidder: 'loopme', |
| 8 | + params: { |
| 9 | + ak: 'b510d5bcda' |
| 10 | + }, |
| 11 | + mediaTypes: { |
| 12 | + banner: { |
| 13 | + sizes: [[300, 250]] |
| 14 | + } |
| 15 | + }, |
| 16 | + adUnitCode: 'ad-1', |
| 17 | + bidId: '2652ca954bce9' |
| 18 | + }]; |
| 19 | + |
| 20 | + describe('isBidRequestValid', function () { |
| 21 | + it('should return true if the ak parameter is present', function () { |
| 22 | + expect(spec.isBidRequestValid(bidRequests[0])).to.be.true; |
| 23 | + }); |
| 24 | + |
| 25 | + it('should return false if the ak parameter is not present', function () { |
| 26 | + let bidRequest = utils.deepClone(bidRequests[0]); |
| 27 | + delete bidRequest.params.ak; |
| 28 | + expect(spec.isBidRequestValid(bidRequest)).to.be.false; |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return false if the params object is not present', function () { |
| 32 | + let bidRequest = utils.deepClone(bidRequests); |
| 33 | + delete bidRequest[0].params; |
| 34 | + expect(spec.isBidRequestValid(bidRequest)).to.be.false; |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('buildRequests', function () { |
| 39 | + it('should generate a valid single GET request for multiple bid requests', function () { |
| 40 | + const request = spec.buildRequests(bidRequests)[0]; |
| 41 | + expect(request.method).to.equal('GET'); |
| 42 | + expect(request.url).to.equal('https://loopme.me/api/hb'); |
| 43 | + expect(request.bidId).to.equal('2652ca954bce9'); |
| 44 | + expect(request.data).to.exist; |
| 45 | + |
| 46 | + const requestData = request.data; |
| 47 | + expect(requestData).to.contain('ak=b510d5bcda'); |
| 48 | + expect(requestData).to.contain('sizes=300x250'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should add GDPR data to request if available', function () { |
| 52 | + const bidderRequest = { |
| 53 | + gdprConsent: { |
| 54 | + consentString: 'AAABBB' |
| 55 | + } |
| 56 | + }; |
| 57 | + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; |
| 58 | + const requestData = request.data; |
| 59 | + |
| 60 | + expect(requestData).to.contain('user_consent=AAABBB'); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + describe('interpretResponse', function () { |
| 65 | + it('should return an empty array if an invalid response is passed', function () { |
| 66 | + const interpretedResponse = spec.interpretResponse({}); |
| 67 | + expect(interpretedResponse).to.be.an('array').that.is.empty; |
| 68 | + }); |
| 69 | + |
| 70 | + it('should return valid response when passed valid server response', function () { |
| 71 | + const serverResponse = { |
| 72 | + body: { |
| 73 | + 'requestId': '2652ca954bce9', |
| 74 | + 'cpm': 1, |
| 75 | + 'width': 480, |
| 76 | + 'height': 320, |
| 77 | + 'creativeId': '20154', |
| 78 | + 'currency': 'USD', |
| 79 | + 'netRevenue': false, |
| 80 | + 'ttl': 360, |
| 81 | + 'ad': `<div>Hello</div>` |
| 82 | + } |
| 83 | + }; |
| 84 | + |
| 85 | + const request = spec.buildRequests(bidRequests)[0]; |
| 86 | + const interpretedResponse = spec.interpretResponse(serverResponse, request); |
| 87 | + |
| 88 | + expect(interpretedResponse).to.have.lengthOf(1); |
| 89 | + |
| 90 | + expect(interpretedResponse[0].requestId).to.equal(serverResponse.body.requestId); |
| 91 | + expect(interpretedResponse[0].cpm).to.equal(serverResponse.body.cpm); |
| 92 | + expect(interpretedResponse[0].width).to.equal(serverResponse.body.width); |
| 93 | + expect(interpretedResponse[0].height).to.equal(serverResponse.body.height); |
| 94 | + expect(interpretedResponse[0].creativeId).to.equal(serverResponse.body.creativeId); |
| 95 | + expect(interpretedResponse[0].currency).to.equal(serverResponse.body.currency); |
| 96 | + expect(interpretedResponse[0].netRevenue).to.equal(serverResponse.body.netRevenue); |
| 97 | + expect(interpretedResponse[0].ad).to.equal(serverResponse.body.ad); |
| 98 | + expect(interpretedResponse[0].ttl).to.equal(serverResponse.body.ttl); |
| 99 | + }); |
| 100 | + }); |
| 101 | +}); |
0 commit comments