All files adobeDMP.js

100% Statements 14/14
100% Branches 6/6
100% Functions 5/5
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  4x           4x 23x 23x   21x 21x 21x 21x                   4x 82x     82x         23x    
/* Temporary internal state that avoids blocking tracking until getting DMP */
export const dmpState = {isDmpReady: undefined}
 
/**
 * Check if DMP is consented by the user using boros API
 * @return {Promise<boolean>}
 */
export const checkIsDMPReady = () => {
  return new Promise(resolve => {
    if (window.__borosTcf === undefined) return resolve()
 
    window.__borosTcf.push(api => {
      api('isDmpAccepted', ({success, value}) => {
        dmpState.isDmpReady = success && value
        return resolve(dmpState.isDmpReady)
      })
    })
  })
}
 
/**
 * Get if DMP is consented value
 * @return {Promise<boolean>}
 */
export const getIsDMPReady = () => {
  const {isDmpReady} = dmpState
  // if we have some value defined for isDmpReady
  // we returning it and don't check anything else
  if (isDmpReady !== undefined) return Promise.resolve(isDmpReady)
 
  // if we don't have any value, we must check async
  // but as we don't want to block anything yet
  // we assume we don't have the consent and return false
  return checkIsDMPReady()
}