|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spec } from 'modules/smilewantedBidAdapter'; |
| 3 | +import { newBidder } from 'src/adapters/bidderFactory'; |
| 4 | +import { config } from 'src/config'; |
| 5 | +import * as utils from 'src/utils'; |
| 6 | +import { requestBidsHook } from 'modules/consentManagement'; |
| 7 | + |
| 8 | +// Default params with optional ones |
| 9 | +describe('smilewantedBidAdapterTests', function () { |
| 10 | + var DEFAULT_PARAMS = [{ |
| 11 | + adUnitCode: 'sw_300x250', |
| 12 | + bidId: '12345', |
| 13 | + sizes: [ |
| 14 | + [300, 250], |
| 15 | + [300, 200] |
| 16 | + ], |
| 17 | + bidder: 'smilewanted', |
| 18 | + params: { |
| 19 | + zoneId: '1234', |
| 20 | + bidfloor: 2.50 |
| 21 | + }, |
| 22 | + requestId: 'request_abcd1234', |
| 23 | + transactionId: 'trans_abcd1234' |
| 24 | + }]; |
| 25 | + |
| 26 | + var BID_RESPONSE = { |
| 27 | + body: { |
| 28 | + cpm: 3, |
| 29 | + width: 300, |
| 30 | + height: 250, |
| 31 | + creativeId: 'crea_sw_1', |
| 32 | + currency: 'EUR', |
| 33 | + isNetCpm: true, |
| 34 | + ttl: 300, |
| 35 | + adUrl: 'https://www.smilewanted.com', |
| 36 | + ad: '< --- sw script --- >', |
| 37 | + cSyncUrl: 'https://csync.smilewanted.com' |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + it('SmileWanted - Verify build request', function () { |
| 42 | + config.setConfig({ |
| 43 | + 'currency': { |
| 44 | + 'adServerCurrency': 'EUR' |
| 45 | + } |
| 46 | + }); |
| 47 | + const request = spec.buildRequests(DEFAULT_PARAMS); |
| 48 | + expect(request[0]).to.have.property('url').and.to.equal('https://prebid.smilewanted.com'); |
| 49 | + expect(request[0]).to.have.property('method').and.to.equal('POST'); |
| 50 | + const requestContent = JSON.parse(request[0].data); |
| 51 | + expect(requestContent).to.have.property('zoneId').and.to.equal('1234'); |
| 52 | + expect(requestContent).to.have.property('currencyCode').and.to.equal('EUR'); |
| 53 | + expect(requestContent).to.have.property('bidfloor').and.to.equal(2.50); |
| 54 | + expect(requestContent).to.have.property('sizes'); |
| 55 | + expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(300); |
| 56 | + expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(250); |
| 57 | + expect(requestContent.sizes[1]).to.have.property('w').and.to.equal(300); |
| 58 | + expect(requestContent.sizes[1]).to.have.property('h').and.to.equal(200); |
| 59 | + expect(requestContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; |
| 60 | + }); |
| 61 | + |
| 62 | + it('SmileWanted - Verify build request with referrer', function () { |
| 63 | + const request = spec.buildRequests(DEFAULT_PARAMS, { |
| 64 | + refererInfo: { |
| 65 | + referer: 'http://localhost/Prebid.js/integrationExamples/gpt/hello_world.html' |
| 66 | + } |
| 67 | + }); |
| 68 | + const requestContent = JSON.parse(request[0].data); |
| 69 | + expect(requestContent).to.have.property('pageDomain').and.to.equal('http://localhost/Prebid.js/integrationExamples/gpt/hello_world.html'); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('gdpr tests', function () { |
| 73 | + afterEach(function () { |
| 74 | + config.resetConfig(); |
| 75 | + $$PREBID_GLOBAL$$.requestBids.removeAll(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('SmileWanted - Verify build request with GDPR', function () { |
| 79 | + config.setConfig({ |
| 80 | + 'currency': { |
| 81 | + 'adServerCurrency': 'EUR' |
| 82 | + }, |
| 83 | + consentManagement: { |
| 84 | + cmp: 'iab', |
| 85 | + consentRequired: true, |
| 86 | + timeout: 1000, |
| 87 | + allowAuctionWithoutConsent: true |
| 88 | + } |
| 89 | + }); |
| 90 | + const request = spec.buildRequests(DEFAULT_PARAMS, { |
| 91 | + gdprConsent: { |
| 92 | + consentString: 'BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA', |
| 93 | + gdprApplies: true |
| 94 | + } |
| 95 | + }); |
| 96 | + const requestContent = JSON.parse(request[0].data); |
| 97 | + expect(requestContent).to.have.property('gdpr').and.to.equal(true); |
| 98 | + expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA'); |
| 99 | + }); |
| 100 | + |
| 101 | + it('SmileWanted - Verify build request with GDPR without gdprApplies', function () { |
| 102 | + config.setConfig({ |
| 103 | + 'currency': { |
| 104 | + 'adServerCurrency': 'EUR' |
| 105 | + }, |
| 106 | + consentManagement: { |
| 107 | + cmp: 'iab', |
| 108 | + consentRequired: true, |
| 109 | + timeout: 1000, |
| 110 | + allowAuctionWithoutConsent: true |
| 111 | + } |
| 112 | + }); |
| 113 | + const request = spec.buildRequests(DEFAULT_PARAMS, { |
| 114 | + gdprConsent: { |
| 115 | + consentString: 'BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA' |
| 116 | + } |
| 117 | + }); |
| 118 | + const requestContent = JSON.parse(request[0].data); |
| 119 | + expect(requestContent).to.not.have.property('gdpr'); |
| 120 | + expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA'); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + it('SmileWanted - Verify parse response', function () { |
| 125 | + const request = spec.buildRequests(DEFAULT_PARAMS); |
| 126 | + const bids = spec.interpretResponse(BID_RESPONSE, request[0]); |
| 127 | + expect(bids).to.have.lengthOf(1); |
| 128 | + const bid = bids[0]; |
| 129 | + expect(bid.cpm).to.equal(3); |
| 130 | + expect(bid.adUrl).to.equal('https://www.smilewanted.com'); |
| 131 | + expect(bid.ad).to.equal('< --- sw script --- >'); |
| 132 | + expect(bid.width).to.equal(300); |
| 133 | + expect(bid.height).to.equal(250); |
| 134 | + expect(bid.creativeId).to.equal('crea_sw_1'); |
| 135 | + expect(bid.currency).to.equal('EUR'); |
| 136 | + expect(bid.netRevenue).to.equal(true); |
| 137 | + expect(bid.ttl).to.equal(300); |
| 138 | + expect(bid.requestId).to.equal(DEFAULT_PARAMS[0].bidId); |
| 139 | + |
| 140 | + expect(function () { |
| 141 | + spec.interpretResponse(BID_RESPONSE, { |
| 142 | + data: 'invalid Json' |
| 143 | + }) |
| 144 | + }).to.not.throw(); |
| 145 | + }); |
| 146 | + |
| 147 | + it('SmileWanted - Verify bidder code', function () { |
| 148 | + expect(spec.code).to.equal('smilewanted'); |
| 149 | + }); |
| 150 | + |
| 151 | + it('SmileWanted - Verify bidder aliases', function () { |
| 152 | + expect(spec.aliases).to.have.lengthOf(2); |
| 153 | + expect(spec.aliases[0]).to.equal('smile'); |
| 154 | + expect(spec.aliases[1]).to.equal('sw'); |
| 155 | + }); |
| 156 | + |
| 157 | + it('SmileWanted - Verify if bid request valid', function () { |
| 158 | + expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true); |
| 159 | + expect(spec.isBidRequestValid({ |
| 160 | + params: { |
| 161 | + zoneId: 1234 |
| 162 | + } |
| 163 | + })).to.equal(true); |
| 164 | + }); |
| 165 | + |
| 166 | + it('SmileWanted - Verify if params(zoneId) is not passed', function () { |
| 167 | + expect(spec.isBidRequestValid({})).to.equal(false); |
| 168 | + expect(spec.isBidRequestValid({ |
| 169 | + params: {} |
| 170 | + })).to.equal(false); |
| 171 | + }); |
| 172 | + |
| 173 | + it('SmileWanted - Verify user sync', function () { |
| 174 | + var syncs = spec.getUserSyncs({ |
| 175 | + iframeEnabled: true |
| 176 | + }, [BID_RESPONSE]); |
| 177 | + expect(syncs).to.have.lengthOf(1); |
| 178 | + expect(syncs[0].type).to.equal('iframe'); |
| 179 | + expect(syncs[0].url).to.equal('https://csync.smilewanted.com'); |
| 180 | + |
| 181 | + syncs = spec.getUserSyncs({ |
| 182 | + iframeEnabled: false |
| 183 | + }, [BID_RESPONSE]); |
| 184 | + expect(syncs).to.have.lengthOf(0); |
| 185 | + |
| 186 | + syncs = spec.getUserSyncs({ |
| 187 | + iframeEnabled: true |
| 188 | + }, []); |
| 189 | + expect(syncs).to.have.lengthOf(0); |
| 190 | + }); |
| 191 | +}); |
0 commit comments