|
| 1 | +import {expect} from 'chai'; |
| 2 | +import {spec} from 'modules/smarticoBidAdapter.js'; |
| 3 | +import {newBidder} from 'src/adapters/bidderFactory.js'; |
| 4 | + |
| 5 | +describe('smarticoBidAdapter', function () { |
| 6 | + const adapter = newBidder(spec); |
| 7 | + let bid = { |
| 8 | + adUnitCode: 'adunit-code', |
| 9 | + auctionId: '5kaj89l8-3456-2s56-c455-4g6h78jsdfgf', |
| 10 | + bidRequestsCount: 1, |
| 11 | + bidder: 'smartico', |
| 12 | + bidderRequestId: '24081afs940568', |
| 13 | + bidderRequestsCount: 1, |
| 14 | + bidderWinsCount: 0, |
| 15 | + bidId: '22499d052045', |
| 16 | + mediaTypes: {banner: {sizes: [[300, 250]]}}, |
| 17 | + params: { |
| 18 | + token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', |
| 19 | + placementId: 'testPlacementId' |
| 20 | + }, |
| 21 | + sizes: [ |
| 22 | + [300, 250] |
| 23 | + ], |
| 24 | + transactionId: '34562345-4dg7-46g7-4sg6-45gdsdj8fd56' |
| 25 | + } |
| 26 | + let bidderRequests = { |
| 27 | + auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', |
| 28 | + auctionStart: 1579746300522, |
| 29 | + bidderCode: 'myBidderCode', |
| 30 | + bidderRequestId: '15246a574e859f', |
| 31 | + bids: [bid], |
| 32 | + refererInfo: { |
| 33 | + canonicalUrl: '', |
| 34 | + numIframes: 0, |
| 35 | + reachedTop: true |
| 36 | + } |
| 37 | + } |
| 38 | + describe('isBidRequestValid', function () { |
| 39 | + it('should return true where required params found', function () { |
| 40 | + expect(spec.isBidRequestValid(bid)).to.equal(true); |
| 41 | + }); |
| 42 | + }); |
| 43 | + describe('buildRequests', function () { |
| 44 | + let bidRequests = [ bid ]; |
| 45 | + let request = spec.buildRequests(bidRequests, bidderRequests); |
| 46 | + it('sends bid request via POST', function () { |
| 47 | + expect(request.method).to.equal('POST'); |
| 48 | + }); |
| 49 | + it('must contain token', function() { |
| 50 | + expect(request.data.bidParams[0].token).to.equal('FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya'); |
| 51 | + }); |
| 52 | + it('must contain auctionId', function() { |
| 53 | + expect(request.data.auctionId).to.exist.and.to.be.a('string') |
| 54 | + }); |
| 55 | + it('must contain valid width and height', function() { |
| 56 | + expect(request.data.bidParams[0]['banner-format-width']).to.exist.and.to.be.a('number') |
| 57 | + expect(request.data.bidParams[0]['banner-format-height']).to.exist.and.to.be.a('number') |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('interpretResponse', function () { |
| 62 | + let bidRequest = { |
| 63 | + method: 'POST', |
| 64 | + url: 'https://trmads.eu/preBidRequest', |
| 65 | + bids: [bid], |
| 66 | + data: [{ |
| 67 | + token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', |
| 68 | + bidId: '22499d052045', |
| 69 | + 'banner-format-width': 300, |
| 70 | + 'banner-format-height': 250, |
| 71 | + placementId: 'testPlacementId', |
| 72 | + }] |
| 73 | + }; |
| 74 | + let serverResponse = { |
| 75 | + body: [{ |
| 76 | + bidId: '22499d052045', |
| 77 | + id: 987654, |
| 78 | + cpm: 10, |
| 79 | + netRevenue: 0, |
| 80 | + currency: 'EUR', |
| 81 | + ttl: 30, |
| 82 | + bannerFormatWidth: 300, |
| 83 | + bannerFormatHeight: 250, |
| 84 | + bannerFormatAlias: 'medium_rectangle' |
| 85 | + }] |
| 86 | + }; |
| 87 | + let expectedResponse = [{ |
| 88 | + requestId: bid.bidId, |
| 89 | + cpm: 10, |
| 90 | + width: 300, |
| 91 | + height: 250, |
| 92 | + creativeId: 987654, |
| 93 | + currency: 'EUR', |
| 94 | + netRevenue: false, // gross |
| 95 | + ttl: 30, |
| 96 | + ad: '<script id="smartico-widget-testPlacementId-0" async defer type="text/javascript" src="https://trmads.eu/get?token=FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya&auction-id=5kaj89l8-3456-2s56-c455-4g6h78jsdfgf&from-auction-buffer=1&own_session=1&ad=987654&scriptid=smartico-widget-testPlacementId-0&banner-format=medium_rectangle"><\/script>'}]; |
| 97 | + let result = spec.interpretResponse(serverResponse, bidRequest); |
| 98 | + it('should contain correct creativeId', function () { |
| 99 | + expect(result[0].creativeId).to.equal(expectedResponse[0].creativeId) |
| 100 | + }); |
| 101 | + it('should contain correct cpm', function () { |
| 102 | + expect(result[0].cpm).to.equal(expectedResponse[0].cpm) |
| 103 | + }); |
| 104 | + it('should contain correct width', function () { |
| 105 | + expect(result[0].width).to.equal(expectedResponse[0].width) |
| 106 | + }); |
| 107 | + it('should contain correct height', function () { |
| 108 | + expect(result[0].height).to.equal(expectedResponse[0].height) |
| 109 | + }); |
| 110 | + it('should contain correct requestId', function () { |
| 111 | + expect(result[0].requestId).to.equal(expectedResponse[0].requestId) |
| 112 | + }); |
| 113 | + it('should contain correct ttl', function () { |
| 114 | + expect(result[0].ttl).to.equal(expectedResponse[0].ttl) |
| 115 | + }); |
| 116 | + it('should contain correct netRevenue', function () { |
| 117 | + expect(result[0].netRevenue).to.equal(expectedResponse[0].netRevenue) |
| 118 | + }); |
| 119 | + it('should contain correct netRevenue', function () { |
| 120 | + expect(result[0].currency).to.equal(expectedResponse[0].currency) |
| 121 | + }); |
| 122 | + it('should contain correct ad content', function () { |
| 123 | + expect(result[0].ad).to.equal(expectedResponse[0].ad) |
| 124 | + }); |
| 125 | + }); |
| 126 | +}); |
0 commit comments