|
| 1 | +import {expect} from 'chai'; |
| 2 | +import {spec} from '../../../modules/collectcentBidAdapter'; |
| 3 | + |
| 4 | +describe('Collectcent', function () { |
| 5 | + let bid = { |
| 6 | + bidId: '2dd581a2b6281d', |
| 7 | + bidder: 'collectcent', |
| 8 | + bidderRequestId: '145e1d6a7837c9', |
| 9 | + params: { |
| 10 | + placementId: 123, |
| 11 | + traffic: 'banner' |
| 12 | + }, |
| 13 | + placementCode: 'placement_0', |
| 14 | + auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', |
| 15 | + sizes: [[300, 250]], |
| 16 | + transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' |
| 17 | + }; |
| 18 | + |
| 19 | + describe('isBidRequestValid', function () { |
| 20 | + it('Should return true when placementId can be cast to a number', function () { |
| 21 | + expect(spec.isBidRequestValid(bid)).to.be.true; |
| 22 | + }); |
| 23 | + it('Should return false when placementId is not a number', function () { |
| 24 | + bid.params.placementId = 'aaa'; |
| 25 | + expect(spec.isBidRequestValid(bid)).to.be.false; |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('buildRequests', function () { |
| 30 | + let serverRequest = spec.buildRequests([bid]); |
| 31 | + it('Creates a ServerRequest object with method, URL and data', function () { |
| 32 | + expect(serverRequest).to.exist; |
| 33 | + expect(serverRequest.method).to.exist; |
| 34 | + expect(serverRequest.url).to.exist; |
| 35 | + expect(serverRequest.data).to.exist; |
| 36 | + }); |
| 37 | + it('Returns POST method', function () { |
| 38 | + expect(serverRequest.method).to.equal('POST'); |
| 39 | + }); |
| 40 | + it('Returns valid URL', function () { |
| 41 | + expect(serverRequest.url).to.equal('//publishers.motionspots.com/?c=o&m=multi'); |
| 42 | + }); |
| 43 | + it('Returns valid data if array of bids is valid', function () { |
| 44 | + let data = serverRequest.data; |
| 45 | + expect(data).to.be.an('object'); |
| 46 | + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'secure', 'host', 'page', 'placements'); |
| 47 | + expect(data.deviceWidth).to.be.a('number'); |
| 48 | + expect(data.deviceHeight).to.be.a('number'); |
| 49 | + expect(data.secure).to.be.within(0, 1); |
| 50 | + expect(data.host).to.be.a('string'); |
| 51 | + expect(data.page).to.be.a('string'); |
| 52 | + let placements = data['placements']; |
| 53 | + for (let i = 0; i < placements.length; i++) { |
| 54 | + let placement = placements[i]; |
| 55 | + expect(placement).to.have.all.keys('placementId', 'bidId', 'traffic', 'sizes'); |
| 56 | + expect(placement.placementId).to.be.a('number'); |
| 57 | + expect(placement.bidId).to.be.a('string'); |
| 58 | + expect(placement.traffic).to.be.a('string'); |
| 59 | + expect(placement.sizes).to.be.an('array'); |
| 60 | + } |
| 61 | + }); |
| 62 | + it('Returns empty data if no valid requests are passed', function () { |
| 63 | + serverRequest = spec.buildRequests([]); |
| 64 | + let data = serverRequest.data; |
| 65 | + expect(data.placements).to.be.an('array').that.is.empty; |
| 66 | + }); |
| 67 | + }); |
| 68 | + describe('interpretResponse', function () { |
| 69 | + let resObject = { |
| 70 | + body: [ { |
| 71 | + requestId: '123', |
| 72 | + mediaType: 'banner', |
| 73 | + cpm: 0.3, |
| 74 | + width: 320, |
| 75 | + height: 50, |
| 76 | + ad: '<h1>Hello ad</h1>', |
| 77 | + ttl: 1000, |
| 78 | + creativeId: '123asd', |
| 79 | + netRevenue: true, |
| 80 | + currency: 'USD' |
| 81 | + } ] |
| 82 | + }; |
| 83 | + let serverResponses = spec.interpretResponse(resObject); |
| 84 | + it('Returns an array of valid server responses if response object is valid', function () { |
| 85 | + expect(serverResponses).to.be.an('array').that.is.not.empty; |
| 86 | + for (let i = 0; i < serverResponses.length; i++) { |
| 87 | + let dataItem = serverResponses[i]; |
| 88 | + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', |
| 89 | + 'netRevenue', 'currency', 'mediaType'); |
| 90 | + expect(dataItem.requestId).to.be.a('string'); |
| 91 | + expect(dataItem.cpm).to.be.a('number'); |
| 92 | + expect(dataItem.width).to.be.a('number'); |
| 93 | + expect(dataItem.height).to.be.a('number'); |
| 94 | + expect(dataItem.ad).to.be.a('string'); |
| 95 | + expect(dataItem.ttl).to.be.a('number'); |
| 96 | + expect(dataItem.creativeId).to.be.a('string'); |
| 97 | + expect(dataItem.netRevenue).to.be.a('boolean'); |
| 98 | + expect(dataItem.currency).to.be.a('string'); |
| 99 | + expect(dataItem.mediaType).to.be.a('string'); |
| 100 | + } |
| 101 | + it('Returns an empty array if invalid response is passed', function () { |
| 102 | + serverResponses = spec.interpretResponse('invalid_response'); |
| 103 | + expect(serverResponses).to.be.an('array').that.is.empty; |
| 104 | + }); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('getUserSyncs', function () { |
| 109 | + let userSync = spec.getUserSyncs(); |
| 110 | + it('Returns valid URL and `', function () { |
| 111 | + expect(userSync).to.be.an('array').with.lengthOf(1); |
| 112 | + expect(userSync[0].type).to.exist; |
| 113 | + expect(userSync[0].url).to.exist; |
| 114 | + expect(userSync[0].type).to.be.equal('image'); |
| 115 | + expect(userSync[0].url).to.be.equal('//publishers.motionspots.com/?c=o&m=cookie'); |
| 116 | + }); |
| 117 | + }); |
| 118 | +}); |
0 commit comments