|
1 | 1 | import * as equativUtils from "../../../../libraries/equativUtils/equativUtils.js"; |
| 2 | +import { storage } from "../../../../modules/equativBidAdapter.js"; |
2 | 3 |
|
3 | 4 | describe('equativUtils', () => { |
4 | 5 | describe('prepareSplitImps', () => { |
@@ -40,4 +41,146 @@ describe('equativUtils', () => { |
40 | 41 | expect(result.banner.topframe).to.equal(1); |
41 | 42 | }) |
42 | 43 | }) |
| 44 | + |
| 45 | + describe('handleCookieSync', () => { |
| 46 | + let setDataInLocalStorageStub; |
| 47 | + let addEventListenerStub; |
| 48 | + let messageHandler; |
| 49 | + |
| 50 | + const SAMPLE_RESPONSE = { |
| 51 | + body: { |
| 52 | + id: '12h712u7-k22g-8124-ab7a-h268s22dy271', |
| 53 | + seatbid: [ |
| 54 | + { |
| 55 | + bid: [ |
| 56 | + { |
| 57 | + id: '1bh7jku7-ko2g-8654-ab72-h268shvwy271', |
| 58 | + impid: 'r12gwgf231', |
| 59 | + price: 0.6565, |
| 60 | + adm: '<h1>AD</h1>', |
| 61 | + adomain: ['abc.com'], |
| 62 | + cid: '1242512', |
| 63 | + crid: '535231', |
| 64 | + w: 300, |
| 65 | + h: 600, |
| 66 | + mtype: 1, |
| 67 | + cat: ['IAB19', 'IAB19-1'], |
| 68 | + cattax: 1, |
| 69 | + }, |
| 70 | + ], |
| 71 | + seat: '4212', |
| 72 | + }, |
| 73 | + ], |
| 74 | + cur: 'USD', |
| 75 | + statuscode: 0, |
| 76 | + }, |
| 77 | + }; |
| 78 | + |
| 79 | + beforeEach(() => { |
| 80 | + setDataInLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage'); |
| 81 | + addEventListenerStub = sinon.stub(window, 'addEventListener').callsFake((type, handler) => { |
| 82 | + if (type === 'message') { |
| 83 | + messageHandler = handler; |
| 84 | + } |
| 85 | + return addEventListenerStub.wrappedMethod.call(this, type, handler); |
| 86 | + }); |
| 87 | + }); |
| 88 | + afterEach(() => { |
| 89 | + setDataInLocalStorageStub.restore(); |
| 90 | + addEventListenerStub.restore(); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should return empty array if iframe sync not enabled', () => { |
| 94 | + const syncs = equativUtils.handleCookieSync({}, SAMPLE_RESPONSE, {}, 73, storage); |
| 95 | + expect(syncs).to.deep.equal([]); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should retrieve and save user pid', (done) => { |
| 99 | + equativUtils.handleCookieSync( |
| 100 | + { iframeEnabled: true }, |
| 101 | + SAMPLE_RESPONSE, |
| 102 | + { gdprApplies: true, vendorData: { vendor: { consents: {} } } }, |
| 103 | + 73, |
| 104 | + storage |
| 105 | + ); |
| 106 | + |
| 107 | + messageHandler.call(window, { |
| 108 | + origin: 'https://apps.smartadserver.com', |
| 109 | + data: { action: 'getConsent', pid: '7767825890726' }, |
| 110 | + source: { postMessage: sinon.stub() } |
| 111 | + }); |
| 112 | + |
| 113 | + expect(setDataInLocalStorageStub.calledOnce).to.be.true; |
| 114 | + expect(setDataInLocalStorageStub.calledWith('eqt_pid', '7767825890726')).to.be.true; |
| 115 | + done(); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should not save user pid coming from incorrect origin', (done) => { |
| 119 | + equativUtils.handleCookieSync( |
| 120 | + { iframeEnabled: true }, |
| 121 | + SAMPLE_RESPONSE, |
| 122 | + { gdprApplies: true, vendorData: { vendor: { consents: {} } } }, |
| 123 | + 73, |
| 124 | + storage |
| 125 | + ); |
| 126 | + |
| 127 | + messageHandler.call(window, { |
| 128 | + origin: 'https://another-origin.com', |
| 129 | + data: { action: 'getConsent', pid: '7767825890726' }, |
| 130 | + source: { postMessage: sinon.stub() } |
| 131 | + }); |
| 132 | + |
| 133 | + expect(setDataInLocalStorageStub.notCalled).to.be.true; |
| 134 | + done(); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should not save empty pid', (done) => { |
| 138 | + equativUtils.handleCookieSync( |
| 139 | + { iframeEnabled: true }, |
| 140 | + SAMPLE_RESPONSE, |
| 141 | + { gdprApplies: true, vendorData: { vendor: { consents: {} } } }, |
| 142 | + 73, |
| 143 | + storage |
| 144 | + ); |
| 145 | + |
| 146 | + messageHandler.call(window, { |
| 147 | + origin: 'https://apps.smartadserver.com', |
| 148 | + data: { action: 'getConsent', pid: '' }, |
| 149 | + source: { postMessage: sinon.stub() } |
| 150 | + }); |
| 151 | + |
| 152 | + expect(setDataInLocalStorageStub.notCalled).to.be.true; |
| 153 | + done(); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should return array including iframe cookie sync object (gdprApplies=true)', () => { |
| 157 | + const syncs = equativUtils.handleCookieSync( |
| 158 | + { iframeEnabled: true }, |
| 159 | + SAMPLE_RESPONSE, |
| 160 | + { gdprApplies: true }, |
| 161 | + 73, |
| 162 | + storage |
| 163 | + ); |
| 164 | + expect(syncs).to.have.lengthOf(1); |
| 165 | + expect(syncs[0]).to.deep.equal({ |
| 166 | + type: 'iframe', |
| 167 | + url: 'https://apps.smartadserver.com/diff/templates/asset/csync.html?nwid=73&gdpr=1&' |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + it('should return array including iframe cookie sync object (gdprApplies=false)', () => { |
| 172 | + const syncs = equativUtils.handleCookieSync( |
| 173 | + { iframeEnabled: true }, |
| 174 | + SAMPLE_RESPONSE, |
| 175 | + { gdprApplies: false }, |
| 176 | + 73, |
| 177 | + storage |
| 178 | + ); |
| 179 | + expect(syncs).to.have.lengthOf(1); |
| 180 | + expect(syncs[0]).to.deep.equal({ |
| 181 | + type: 'iframe', |
| 182 | + url: 'https://apps.smartadserver.com/diff/templates/asset/csync.html?nwid=73&gdpr=0&' |
| 183 | + }); |
| 184 | + }); |
| 185 | + }); |
43 | 186 | }) |
0 commit comments