|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from 'modules/gjirafaBidAdapter'; |
| 3 | + |
| 4 | +describe('gjirafaAdapterTest', () => { |
| 5 | + describe('bidRequestValidity', () => { |
| 6 | + it('bidRequest with placementId, minCPM and minCPC params', () => { |
| 7 | + expect(spec.isBidRequestValid({ |
| 8 | + bidder: 'gjirafa', |
| 9 | + params: { |
| 10 | + placementId: 'test-div', |
| 11 | + minCPM: 0.0001, |
| 12 | + minCPC: 0.001 |
| 13 | + } |
| 14 | + })).to.equal(true); |
| 15 | + }); |
| 16 | + |
| 17 | + it('bidRequest with only placementId param', () => { |
| 18 | + expect(spec.isBidRequestValid({ |
| 19 | + bidder: 'gjirafa', |
| 20 | + params: { |
| 21 | + placementId: 'test-div' |
| 22 | + } |
| 23 | + })).to.equal(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('bidRequest with minCPM and minCPC params', () => { |
| 27 | + expect(spec.isBidRequestValid({ |
| 28 | + bidder: 'gjirafa', |
| 29 | + params: { |
| 30 | + minCPM: 0.0001, |
| 31 | + minCPC: 0.001 |
| 32 | + } |
| 33 | + })).to.equal(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it('bidRequest with no placementId, minCPM or minCPC params', () => { |
| 37 | + expect(spec.isBidRequestValid({ |
| 38 | + bidder: 'gjirafa', |
| 39 | + params: { |
| 40 | + } |
| 41 | + })).to.equal(false); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('bidRequest', () => { |
| 46 | + const bidRequests = [{ |
| 47 | + 'bidder': 'gjirafa', |
| 48 | + 'params': { |
| 49 | + 'placementId': '71-3' |
| 50 | + }, |
| 51 | + 'adUnitCode': 'hb-leaderboard', |
| 52 | + 'transactionId': 'b6b889bb-776c-48fd-bc7b-d11a1cf0425e', |
| 53 | + 'sizes': [[728, 90], [980, 200], [980, 150], [970, 90], [970, 250]], |
| 54 | + 'bidId': '10bdc36fe0b48c8', |
| 55 | + 'bidderRequestId': '70deaff71c281d', |
| 56 | + 'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' |
| 57 | + }, |
| 58 | + { |
| 59 | + 'bidder': 'gjirafa', |
| 60 | + 'params': { |
| 61 | + 'minCPM': 0.0001, |
| 62 | + 'minCPC': 0.001, |
| 63 | + 'explicit': true |
| 64 | + }, |
| 65 | + 'adUnitCode': 'hb-inarticle', |
| 66 | + 'transactionId': '8757194d-ea7e-4c06-abc0-cfe92bfc5295', |
| 67 | + 'sizes': [[300, 250]], |
| 68 | + 'bidId': '81a6dcb65e2bd9', |
| 69 | + 'bidderRequestId': '70deaff71c281d', |
| 70 | + 'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' |
| 71 | + }]; |
| 72 | + |
| 73 | + it('bidRequest HTTP method', () => { |
| 74 | + const requests = spec.buildRequests(bidRequests); |
| 75 | + requests.forEach(function(requestItem) { |
| 76 | + expect(requestItem.method).to.equal('GET'); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + it('bidRequest url', () => { |
| 81 | + const endpointUrl = 'https://gjc.gjirafa.com/Home/GetBid'; |
| 82 | + const requests = spec.buildRequests(bidRequests); |
| 83 | + requests.forEach(function(requestItem) { |
| 84 | + expect(requestItem.url).to.match(new RegExp(`${endpointUrl}`)); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + it('bidRequest data', () => { |
| 89 | + const requests = spec.buildRequests(bidRequests); |
| 90 | + requests.forEach(function(requestItem) { |
| 91 | + expect(requestItem.data).to.exists; |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + it('bidRequest sizes', () => { |
| 96 | + const requests = spec.buildRequests(bidRequests); |
| 97 | + expect(requests[0].data.sizes).to.equal('728x90;980x200;980x150;970x90;970x250'); |
| 98 | + expect(requests[1].data.sizes).to.equal('300x250'); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + describe('interpretResponse', () => { |
| 103 | + const bidRequest = { |
| 104 | + 'method': 'GET', |
| 105 | + 'url': 'https://gjc.gjirafa.com/Home/GetBid', |
| 106 | + 'data': { |
| 107 | + 'gjid': 2323007, |
| 108 | + 'sizes': '728x90;980x200;980x150;970x90;970x250', |
| 109 | + 'configId': '71-3', |
| 110 | + 'minCPM': 0, |
| 111 | + 'minCPC': 0, |
| 112 | + 'allowExplicit': 0, |
| 113 | + 'referrer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', |
| 114 | + 'requestid': '26ee8fe87940da7', |
| 115 | + 'bidid': '2962dbedc4768bf' |
| 116 | + } |
| 117 | + }; |
| 118 | + |
| 119 | + const bidResponse = { |
| 120 | + body: [{ |
| 121 | + 'CPM': 1, |
| 122 | + 'Width': 728, |
| 123 | + 'Height': 90, |
| 124 | + 'Referrer': 'https://example.com/', |
| 125 | + 'Ad': 'test ad', |
| 126 | + 'CreativeId': '123abc', |
| 127 | + 'NetRevenue': false, |
| 128 | + 'Currency': 'EUR', |
| 129 | + 'TTL': 360 |
| 130 | + }], |
| 131 | + headers: {} |
| 132 | + }; |
| 133 | + |
| 134 | + it('all keys present', () => { |
| 135 | + const result = spec.interpretResponse(bidResponse, bidRequest); |
| 136 | + |
| 137 | + let keys = [ |
| 138 | + 'requestId', |
| 139 | + 'cpm', |
| 140 | + 'width', |
| 141 | + 'height', |
| 142 | + 'creativeId', |
| 143 | + 'currency', |
| 144 | + 'netRevenue', |
| 145 | + 'ttl', |
| 146 | + 'referrer', |
| 147 | + 'ad' |
| 148 | + ]; |
| 149 | + |
| 150 | + let resultKeys = Object.keys(result[0]); |
| 151 | + resultKeys.forEach(function(key) { |
| 152 | + expect(keys.indexOf(key) !== -1).to.equal(true); |
| 153 | + }); |
| 154 | + }) |
| 155 | + }); |
| 156 | +}); |
0 commit comments