Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to use CMP in e2e tests #6377

Closed
giniyat202 opened this issue Mar 2, 2021 · 4 comments
Closed

Proposal to use CMP in e2e tests #6377

giniyat202 opened this issue Mar 2, 2021 · 4 comments
Labels

Comments

@giniyat202
Copy link

Type of issue

Proposal

Description

We want to improve the consent management testing by introducing e2e tests that make use of actual CMP code, as the currently available tests only mock __tcfapi calls with predefined responses. The new tests could help avoid bugs such as #5792.

We want to discuss the possibility of implementing these tests and the implementation details.

Sample code

The code below provides a way to initialize iubenda CMP in the test environment with a predefined scenario:

function initializeCMP(callbacks) {
  window._iub = window._iub || {};
  _iub.csConfiguration = {
    cookiePolicyId: 417383,
    siteId: 1,
    logLevel: 'error',
    lang: 'en',
    enableTcf: true,
  };

  if (callbacks) {
    _iub.csConfiguration.callback = callbacks
  }

  var stubScript = document.createElement('script');
  stubScript.src = '//cdn.iubenda.com/cs/tcf/beta/stub.js';
  document.body.insertBefore(stubScript, document.body.firstChild);

  var cmpScript = document.createElement('script');
  cmpScript.src = '//cdn.iubenda.com/cs/beta/iubenda_cs.js';
  cmpScript.setAttributeNode(document.createAttribute('async'));
  document.body.insertBefore(cmpScript, stubScript.nextSibling);
}

// Note: more scenarios can be produced by following this link: https://iabtcf.com/#/encode
const scenarios = {
  'everything rejected': 'CPAQjlJPAQlAKB7D3CENBJCgAAAAAAAAAAAAHPQAAOfgAAAA',
  'everything accepted': 'CPAQjlJPAQmKhB7D3CENBJCsAP_AAH_AAAAAHPNd_X_fb39j-_59_9t0eY1f9_7_v-0zjgeds-8Nyd_X_L8X42M7vF36pq4KuR4Eu3LBIQFlHOHUTUmw6okVrTPsak2Mr7NKJ7PEinMbe2dYGHtfn9VTuZKYr97s___z__-__v__79f_r-3_3_vp9X---_e_UDnwCTDUvgIsxLHAkmjSqFECEK4kOgFABRQjC0TWEBK4KdlcBH6CBgAgNQEYEQIMQUYsAgAAAACSiICQA8EAiAIgEAAIAVICEABGgCCwAkDAIABQDQsAIoAhAkIMjgqOUwICJFooJ5KwBKLvYwwhDKLACgUf0VAA',
  'purpose 1 accepted': 'CPAQjlJPAQmF8B7D3CENBJCgAIAAAAAAAAAAHPNd_X_fb39je_59f9t0eY1P997_v-wjjgeds-8NyV_W_L8X42M7vF36pqoKuQ4EuzJBIQFlGOHURUmw6okVpSPMak2Mq5NKJ7PEinMbO2dYGGlfndVDuQKYr97sftrz_9-6_v__79f-r-33z_vJUX-u8tO9UAAAAAAA',
  'purpose 2 accepted with leg int': 'CPAQjlJPAQmfeB7D3CENBJCgAEAAAEAAAAAAHPNRZQ2AbmsDuR4ViZN0YQBXAOyivwQxhgcZE4wFwNPDGBcF4AM4nFnwJCYCORgEGGDAIAFlCKEQDQkwCokBrCCsaE2IAqJCBYKAikMaWwBIGGFdH9VROZKQhtqo55jSbPwtQGucJocUKqhOGfPhhBS4clQXUDn4AAAA',
  'purpose 2 rejected but leg int accepted': 'CPAQjlJPAQmo9B7D3CENBJCgAAAAAEAAAAAAHPQAAAAAAAAA',
  'special feature 1 accepted': 'CPAQjlJPAQmyVB7D3CENBJCoAAAAAAAAAAAAHGBJUGJETCJAi5pZIBAwYAhOA-SDFw0QiAIJEoEEgJqAdBIEgEIRFBjIoKgKgAgEqiBAAABBCKGADQgAIIkACQKMAkGADQNABgBAAFELA2FAACFLEsBToQAAjFgEJavQQIwhqGEFIBAAAUCQAIAABUwKOkAAAAAA',
  'vendor 826 accepted': 'CPAQjlJPAQnAkB7D3CENBJCgAAAAAAAAAAAAHGQAQE6AAAAA',
  'vendor 92 accepted with leg int': 'CPAQjlJPAQnJFB7D3CENBJCgAAAAAAAAAAAAAuQAQAuAC5ABAC4AAAAA',
  'vendor 92 rejected but leg int accepted': 'CPAQjlJPAQnPkB7D3CENBJCgAAAAAAAAAAAAAuQAABcgAgBcAAAA'
};

export function initializeCMPWithScenario(scenario, cb) {
  var callbacks = {
    onBeforePreload: function() {
      // This function is used to store a user's consent programmatically
      _iub.cs.api.storeConsent({
        consent: true,
        tcfv2: scenarios[scenario]
      });
    }
  };

  if (cb) {
    callbacks.onReady = cb;
  }

  initializeCMP(callbacks);
}

It can be used in tests e.g. like this:

initializeCMPWithScenario('everything accepted', function() {
  // __tcfapi should be available. the rest of the test logic can go here
});

Steps to reproduce

Test page

Expected results

Actual results

Platform details

Other information

@patmmccann
Copy link
Collaborator

patmmccann commented Mar 2, 2021

Seems like it would be straightforward to write some unit tests that use the iab stub to start with. This Iubenda cmp script is not open source, not locked to a version, and has a ton of extraneous functionality not required for testing. How about we just stub the response to getTCData?

If i run all the code above in console (deleting 'export'), then the everything accepted scenario, and then this line i get something we could use for tests on getTCData:
__tcfapi('getTCData', 2, function(data,success){console.log(data);}); l {cmpId: 123, cmpVersion: 249, gdprApplies: true, tcfPolicyVersion: 2, eventStatus: "tcloaded", …} cmpId: 123 cmpStatus: "loaded" cmpVersion: 249 eventStatus: "tcloaded" gdprApplies: true isServiceSpecific: true listenerId: null publisher: {consents: {…}, legitimateInterests: {…}, customPurpose: {…}, restrictions: {…}} publisherCC: "AA" purpose: {consents: {…}, legitimateInterests: {…}} purposeOneTreatment: false specialFeatureOptins: {1: true, 2: true} tcString: "CPAQjlJPAQmKhB7D3CENBJCsAP_AAH_AAAAAHPNd_X_fb39j-_59_9t0eY1f9_7_v-0zjgeds-8Nyd_X_L8X42M7vF36pq4KuR4Eu3LBIQFlHOHUTUmw6okVrTPsak2Mr7NKJ7PEinMbe2dYGHtfn9VTuZKYr97s___z__-__v__79f_r-3_3_vp9X---_e_UDnwCTDUvgIsxLHAkmjSqFECEK4kOgFABRQjC0TWEBK4KdlcBH6CBgAgNQEYEQIMQUYsAgAAAACSiICQA8EAiAIgEAAIAVICEABGgCCwAkDAIABQDQsAIoAhAkIMjgqOUwICJFooJ5KwBKLvYwwhDKLACgUf0VAA" tcfPolicyVersion: 2 useNonStandardStacks: false vendor: consents: {1: true, 2: true, 3: false, 4: true, 5: false, 6: true, 7: true, 8: true, 9: false, 10: true, 11: true, 12: true, 13: true, 14: true, 15: true, 16: true, 17: false, 18: true, 19: false, 20: true, 21: true, 22: true, 23: true, 24: true, 25: true, 26: true, 27: true, 28: true, 29: false, 30: true, 31: true, 32: true, 33: true, 34: true, 35: false, 36: true, 37: true, 38: false, 39: true, 40: true, 41: true, 42: true, 43: false, 44: true, 45: true, 46: true, 47: true, 48: true, 49: true, 50: true, 51: false, 52: true, 53: true, 54: false, 55: false, 56: false, 57: true, 58: true, 59: true, 60: true, 61: true, 62: true, 63: true, 64: false, 65: true, 66: true, 67: true, 68: true, 69: true, 70: true, 71: true, 72: true, 73: true, 74: false, 75: false, 76: true, 77: true, 78: true, 79: true, 80: true, 81: false, 82: true, 83: true, 84: true, 85: true, 86: true, 87: true, 88: true, 89: true, 90: true, 91: true, 92: true, 93: false, 94: true, 95: true, 96: false, 97: true, 98: true, 99: false, 100: true, …} legitimateInterests: {1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: false, 8: true, 9: false, 10: false, 11: true, 12: false, 13: false, 14: true, 15: true, 16: false, 17: false, 18: false, 19: false, 20: true, 21: true, 22: false, 23: true, 24: false, 25: true, 26: false, 27: false, 28: true, 29: false, 30: true, 31: true, 32: true, 33: true, 34: true, 35: false, 36: false, 37: false, 38: false, 39: false, 40: false, 41: false, 42: true, 43: false, 44: false, 45: false, 46: true, 47: false, 48: true, 49: true, 50: false, 51: false, 52: true, 53: true, 54: false, 55: false, 56: false, 57: true, 58: false, 59: false, 60: true, 61: false, 62: true, 63: true, 64: false, 65: false, 66: false, 67: true, 68: true, 69: true, 70: false, 71: false, 72: false, 73: false, 74: false, 75: false, 76: true, 77: false, 78: false, 79: true, 80: false, 81: false, 82: true, 83: false, 84: false, 85: true, 86: true, 87: false, 88: true, 89: false, 90: false, 91: false, 92: true, 93: true, 94: false, 95: true, 96: false, 97: false, 98: true, 99: false, 100: true, …} __proto__: Object __proto__: t.Response

@gglas
Copy link

gglas commented Apr 12, 2021

@ChrisHuie working on a PR to implement the stub, simultaneously, after discussing today, it also might be good to update the examples with a CMP implemented. This should help with manual testing, and we will publish a generic version with the relevant JS for publishers / CMPs to swap out the CMP being called.

@patmmccann
Copy link
Collaborator

This is a 3 phase to do:

  1. update some doc examples
  2. add a bunch of unit tests added to cm.js
  3. feature to enable tests by adapters that run in cmp stub mode or where this tcf api exists.

@ChrisHuie ChrisHuie removed their assignment Nov 10, 2021
@dgirardi dgirardi moved this from Open to Ready for Dev in Prebid.js Tactical Issues table Mar 9, 2022
@dgirardi dgirardi moved this from Ready for Dev to Blocked in Prebid.js Tactical Issues table Mar 11, 2022
@dgirardi dgirardi moved this from Blocked to Ready for Dev in Prebid.js Tactical Issues table Sep 28, 2022
@patmmccann patmmccann closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2023
@github-project-automation github-project-automation bot moved this from Ready for Dev to Done in Prebid.js Tactical Issues table Jul 25, 2023
@patmmccann patmmccann reopened this Jul 25, 2023
@patmmccann patmmccann moved this from Open to Ready for Dev in Prebid.js Tactical Issues table Jul 25, 2023
@patmmccann
Copy link
Collaborator

closing as stale

@patmmccann patmmccann closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@github-project-automation github-project-automation bot moved this from Ready for Dev to Done in Prebid.js Tactical Issues table Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

4 participants