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

Smartyads Bid Adapter: add coppa field from config #6402

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/smartyadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'smartyads';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const spec = {
'secure': 1,
'host': location.host,
'page': location.pathname,
'coppa': config.getConfig('coppa') === true ? 1 : 0,
'placements': placements
};
request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])
Expand Down
21 changes: 20 additions & 1 deletion test/spec/modules/smartyadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import {spec} from '../../../modules/smartyadsBidAdapter.js';
import { config } from '../../../src/config.js';

describe('SmartyadsAdapter', function () {
let bid = {
Expand Down Expand Up @@ -38,9 +39,10 @@ describe('SmartyadsAdapter', function () {
it('Returns valid data if array of bids is valid', function () {
let data = serverRequest.data;
expect(data).to.be.an('object');
expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements');
expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'coppa');
expect(data.deviceWidth).to.be.a('number');
expect(data.deviceHeight).to.be.a('number');
expect(data.coppa).to.be.a('number');
expect(data.language).to.be.a('string');
expect(data.secure).to.be.within(0, 1);
expect(data.host).to.be.a('string');
Expand All @@ -57,6 +59,23 @@ describe('SmartyadsAdapter', function () {
expect(data.placements).to.be.an('array').that.is.empty;
});
});

describe('with COPPA', function() {
beforeEach(function() {
sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a better idea to set your stubs in beforeEach and reset them in afterEach.

If for some reason your test fails before the config.getConfig.restore(); then the next adapter tests which run will have this stubbed still which can cause flakey failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @robertrmartinez ! Thank you for your review! I will fix it!

});
afterEach(function() {
config.getConfig.restore();
});

it('should send the Coppa "required" flag set to "1" in the request', function () {
let serverRequest = spec.buildRequests([bid]);
expect(serverRequest.data.coppa).to.equal(1);
});
});

describe('interpretResponse', function () {
it('Should interpret banner response', function () {
const banner = {
Expand Down