|
1 | 1 | import {expect} from 'chai';
|
2 | 2 | import {spec} from 'modules/pubmaticBidAdapter';
|
3 | 3 | import * as utils from 'src/utils';
|
| 4 | +import {config} from 'src/config'; |
4 | 5 | const constants = require('src/constants.json');
|
5 | 6 |
|
6 | 7 | describe('PubMatic adapter', function () {
|
@@ -448,6 +449,197 @@ describe('PubMatic adapter', function () {
|
448 | 449 | expect(data.imp[0].ext.pmZoneId).to.equal(bidRequests[0].params.pmzoneid.split(',').slice(0, 50).map(id => id.trim()).join()); // pmzoneid
|
449 | 450 | });
|
450 | 451 |
|
| 452 | + it('Request should have digitrust params', function() { |
| 453 | + window.DigiTrust = { |
| 454 | + getUser: function () { |
| 455 | + } |
| 456 | + }; |
| 457 | + var bidRequest = {}; |
| 458 | + let sandbox = sinon.sandbox.create(); |
| 459 | + sandbox.stub(window.DigiTrust, 'getUser').callsFake(() => |
| 460 | + ({ |
| 461 | + success: true, |
| 462 | + identity: { |
| 463 | + privacy: {optout: false}, |
| 464 | + id: 'testId', |
| 465 | + keyv: 4 |
| 466 | + } |
| 467 | + }) |
| 468 | + ); |
| 469 | + |
| 470 | + let request = spec.buildRequests(bidRequests, bidRequest); |
| 471 | + let data = JSON.parse(request.data); |
| 472 | + expect(data.user.eids).to.deep.equal([{ |
| 473 | + 'source': 'digitru.st', |
| 474 | + 'uids': [{ |
| 475 | + 'id': 'testId', |
| 476 | + 'atype': 1, |
| 477 | + 'ext': { |
| 478 | + 'keyv': 4 |
| 479 | + } |
| 480 | + }] |
| 481 | + }]); |
| 482 | + sandbox.restore(); |
| 483 | + delete window.DigiTrust; |
| 484 | + }); |
| 485 | + |
| 486 | + it('Request should not have digitrust params when DigiTrust not loaded', function() { |
| 487 | + let request = spec.buildRequests(bidRequests, {}); |
| 488 | + let data = JSON.parse(request.data); |
| 489 | + expect(data.user.eids).to.deep.equal(undefined); |
| 490 | + }); |
| 491 | + |
| 492 | + it('Request should not have digitrust params due to optout', function() { |
| 493 | + window.DigiTrust = { |
| 494 | + getUser: function () { |
| 495 | + } |
| 496 | + }; |
| 497 | + let sandbox = sinon.sandbox.create(); |
| 498 | + sandbox.stub(window.DigiTrust, 'getUser').callsFake(() => |
| 499 | + ({ |
| 500 | + success: true, |
| 501 | + identity: { |
| 502 | + privacy: {optout: true}, |
| 503 | + id: 'testId', |
| 504 | + keyv: 4 |
| 505 | + } |
| 506 | + }) |
| 507 | + ); |
| 508 | + |
| 509 | + let request = spec.buildRequests(bidRequests, {}); |
| 510 | + let data = JSON.parse(request.data); |
| 511 | + expect(data.user.eids).to.deep.equal(undefined); |
| 512 | + sandbox.restore(); |
| 513 | + delete window.DigiTrust; |
| 514 | + }); |
| 515 | + |
| 516 | + it('Request should not have digitrust params due to failure', function() { |
| 517 | + window.DigiTrust = { |
| 518 | + getUser: function () { |
| 519 | + } |
| 520 | + }; |
| 521 | + let sandbox = sinon.sandbox.create(); |
| 522 | + sandbox.stub(window.DigiTrust, 'getUser').callsFake(() => |
| 523 | + ({ |
| 524 | + success: false, |
| 525 | + identity: { |
| 526 | + privacy: {optout: false}, |
| 527 | + id: 'testId', |
| 528 | + keyv: 4 |
| 529 | + } |
| 530 | + }) |
| 531 | + ); |
| 532 | + |
| 533 | + let request = spec.buildRequests(bidRequests, {}); |
| 534 | + let data = JSON.parse(request.data); |
| 535 | + expect(data.user.eids).to.deep.equal(undefined); |
| 536 | + sandbox.restore(); |
| 537 | + delete window.DigiTrust; |
| 538 | + }); |
| 539 | + |
| 540 | + describe('DigiTrustId from config', function() { |
| 541 | + var origGetConfig; |
| 542 | + let sandbox; |
| 543 | + beforeEach(() => { |
| 544 | + sandbox = sinon.sandbox.create(); |
| 545 | + window.DigiTrust = { |
| 546 | + getUser: sandbox.spy() |
| 547 | + }; |
| 548 | + }); |
| 549 | + |
| 550 | + afterEach(() => { |
| 551 | + sandbox.restore(); |
| 552 | + delete window.DigiTrust; |
| 553 | + }); |
| 554 | + |
| 555 | + it('Request should have digiTrustId config params', function() { |
| 556 | + sandbox.stub(config, 'getConfig').callsFake((key) => { |
| 557 | + var config = { |
| 558 | + digiTrustId: { |
| 559 | + success: true, |
| 560 | + identity: { |
| 561 | + privacy: {optout: false}, |
| 562 | + id: 'testId', |
| 563 | + keyv: 4 |
| 564 | + } |
| 565 | + } |
| 566 | + }; |
| 567 | + return config[key]; |
| 568 | + }); |
| 569 | + |
| 570 | + let request = spec.buildRequests(bidRequests, {}); |
| 571 | + let data = JSON.parse(request.data); |
| 572 | + expect(data.user.eids).to.deep.equal([{ |
| 573 | + 'source': 'digitru.st', |
| 574 | + 'uids': [{ |
| 575 | + 'id': 'testId', |
| 576 | + 'atype': 1, |
| 577 | + 'ext': { |
| 578 | + 'keyv': 4 |
| 579 | + } |
| 580 | + }] |
| 581 | + }]); |
| 582 | + // should not have called DigiTrust.getUser() |
| 583 | + expect(window.DigiTrust.getUser.notCalled).to.equal(true); |
| 584 | + }); |
| 585 | + |
| 586 | + it('Request should not have digiTrustId config params due to optout', function() { |
| 587 | + sandbox.stub(config, 'getConfig').callsFake((key) => { |
| 588 | + var config = { |
| 589 | + digiTrustId: { |
| 590 | + success: true, |
| 591 | + identity: { |
| 592 | + privacy: {optout: true}, |
| 593 | + id: 'testId', |
| 594 | + keyv: 4 |
| 595 | + } |
| 596 | + } |
| 597 | + } |
| 598 | + return config[key]; |
| 599 | + }); |
| 600 | + let request = spec.buildRequests(bidRequests, {}); |
| 601 | + let data = JSON.parse(request.data); |
| 602 | + expect(data.user.eids).to.deep.equal(undefined); |
| 603 | + // should not have called DigiTrust.getUser() |
| 604 | + expect(window.DigiTrust.getUser.notCalled).to.equal(true); |
| 605 | + }); |
| 606 | + |
| 607 | + it('Request should not have digiTrustId config params due to failure', function() { |
| 608 | + sandbox.stub(config, 'getConfig').callsFake((key) => { |
| 609 | + var config = { |
| 610 | + digiTrustId: { |
| 611 | + success: false, |
| 612 | + identity: { |
| 613 | + privacy: {optout: false}, |
| 614 | + id: 'testId', |
| 615 | + keyv: 4 |
| 616 | + } |
| 617 | + } |
| 618 | + } |
| 619 | + return config[key]; |
| 620 | + }); |
| 621 | + |
| 622 | + let request = spec.buildRequests(bidRequests, {}); |
| 623 | + let data = JSON.parse(request.data); |
| 624 | + expect(data.user.eids).to.deep.equal(undefined); |
| 625 | + // should not have called DigiTrust.getUser() |
| 626 | + expect(window.DigiTrust.getUser.notCalled).to.equal(true); |
| 627 | + }); |
| 628 | + |
| 629 | + it('Request should not have digiTrustId config params if they do not exist', function() { |
| 630 | + sandbox.stub(config, 'getConfig').callsFake((key) => { |
| 631 | + var config = {}; |
| 632 | + return config[key]; |
| 633 | + }); |
| 634 | + |
| 635 | + let request = spec.buildRequests(bidRequests, {}); |
| 636 | + let data = JSON.parse(request.data); |
| 637 | + expect(data.user.eids).to.deep.equal(undefined); |
| 638 | + // should have called DigiTrust.getUser() once |
| 639 | + expect(window.DigiTrust.getUser.calledOnce).to.equal(true); |
| 640 | + }); |
| 641 | + }); |
| 642 | + |
451 | 643 | it('Request params check for video ad', function () {
|
452 | 644 | let request = spec.buildRequests(videoBidRequests);
|
453 | 645 | let data = JSON.parse(request.data);
|
|
0 commit comments