(args)
| 111 | |
| 112 | describe('#execute_', () => { |
| 113 | function executeTest(args) { |
| 114 | const { |
| 115 | calloutCount, |
| 116 | expectedCalloutUrls, |
| 117 | expectedRtcArray, |
| 118 | failXhr, |
| 119 | responseIsString, |
| 120 | rtcCalloutResponses, |
| 121 | timeoutMillis, |
| 122 | urls, |
| 123 | vendors, |
| 124 | } = args; |
| 125 | setRtcConfig({urls, vendors, timeoutMillis}); |
| 126 | (expectedCalloutUrls || []).forEach((expectedUrl, i) => { |
| 127 | setFetchJsonStubBehavior( |
| 128 | expectedUrl, |
| 129 | rtcCalloutResponses[i], |
| 130 | responseIsString, |
| 131 | failXhr |
| 132 | ); |
| 133 | }); |
| 134 | const customMacros = args['customMacros'] || {}; |
| 135 | const rtcResponsePromiseArray = execute_( |
| 136 | element, |
| 137 | customMacros, |
| 138 | /* consentState */ undefined, |
| 139 | /* consentString */ undefined, |
| 140 | /* consentMetadata */ undefined, |
| 141 | () => {} |
| 142 | ); |
| 143 | return rtcResponsePromiseArray.then((rtcResponseArray) => { |
| 144 | expect(rtcResponseArray.length).to.equal(expectedRtcArray.length); |
| 145 | expect(fetchJsonStub.callCount).to.equal(calloutCount); |
| 146 | (expectedCalloutUrls || []).forEach((url) => { |
| 147 | expect(fetchJsonStub).to.have.been.calledWith(url); |
| 148 | }); |
| 149 | rtcResponseArray.forEach((rtcResponse, i) => { |
| 150 | expect(rtcResponse.response).to.deep.equal( |
| 151 | expectedRtcArray[i].response |
| 152 | ); |
| 153 | expect(rtcResponse.callout).to.equal(expectedRtcArray[i].callout); |
| 154 | expect(rtcResponse.error).to.equal(expectedRtcArray[i].error); |
| 155 | expect(Object.keys(rtcResponse).sort()).to.deep.equal( |
| 156 | Object.keys(expectedRtcArray[i]).sort() |
| 157 | ); |
| 158 | expect(isFiniteNumber(rtcResponse.rtcTime)).to.be.true; |
| 159 | }); |
| 160 | }); |
| 161 | } |
| 162 | |
| 163 | const urlMacros = [ |
| 164 | 'slot_id=SLOT_ID', |
no test coverage detected