Skip to content

Commit

Permalink
remove reference to garm in output of mobian brand-safety (prebid#12014)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehb-mtk authored Jul 22, 2024
1 parent 264db8c commit 996b235
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 95 deletions.
20 changes: 4 additions & 16 deletions modules/mobianRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@ function getBidRequestData(bidReqConfig, callback, config) {
return;
}

let mobianGarmRisk = response.garm_risk || 'unknown';
let mobianRisk = response.garm_risk || 'unknown';

if (mobianGarmRisk === 'unknown') {
const risks = ['garm_high_risk', 'garm_medium_risk', 'garm_low_risk', 'garm_no_risk'];
const riskLevels = ['high', 'medium', 'low', 'none'];

for (let i = 0; i < risks.length; i++) {
if (response[risks[i]]) {
mobianGarmRisk = riskLevels[i];
break;
}
}
}

const garmCategories = Object.keys(response)
const categories = Object.keys(response)
.filter(key => key.startsWith('garm_content_category_') && response[key])
.map(key => key.replace('garm_content_category_', ''));

Expand All @@ -67,8 +55,8 @@ function getBidRequestData(bidReqConfig, callback, config) {
.map(key => key.replace('emotion_', ''));

const risk = {
'mobianGarmRisk': mobianGarmRisk,
'garmContentCategories': garmCategories,
'risk': mobianRisk,
'contentCategories': categories,
'sentiment': sentiment,
'emotions': emotions
};
Expand Down
110 changes: 31 additions & 79 deletions test/spec/modules/mobianRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,63 @@ describe('Mobian RTD Submodule', function () {
ajaxStub.restore();
});

it('should return no_risk when server responds with garm_no_risk', function () {
it('should return risk level when server responds with garm_risk', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_no_risk: true,
garm_low_risk: false,
garm_medium_risk: false,
garm_high_risk: false
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.have.property('mobianGarmRisk');
expect(risk['mobianGarmRisk']).to.equal('none');
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk);
});
});

it('should return low_risk when server responds with garm_low_risk', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_no_risk: false,
garm_low_risk: true,
garm_medium_risk: false,
garm_high_risk: false
garm_risk: 'low',
sentiment_positive: true,
emotion_joy: true
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.have.property('mobianGarmRisk');
expect(risk['mobianGarmRisk']).to.equal('low');
expect(risk).to.deep.equal({
risk: 'low',
contentCategories: [],
sentiment: 'positive',
emotions: ['joy']
});
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk);
});
});

it('should return medium_risk when server responds with garm_medium_risk', function () {
it('should handle response with GARM content categories, sentiment, and emotions', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_no_risk: false,
garm_low_risk: false,
garm_medium_risk: true,
garm_high_risk: false
garm_risk: 'medium',
garm_content_category_arms: true,
garm_content_category_crime: true,
sentiment_negative: true,
emotion_anger: true,
emotion_fear: true
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.have.property('mobianGarmRisk');
expect(risk['mobianGarmRisk']).to.equal('medium');
expect(risk).to.deep.equal({
risk: 'medium',
contentCategories: ['arms', 'crime'],
sentiment: 'negative',
emotions: ['anger', 'fear']
});
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk);
});
});

it('should return high_risk when server responds with garm_high_risk', function () {
it('should return unknown risk when garm_risk is not present', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_no_risk: false,
garm_low_risk: false,
garm_medium_risk: false,
garm_high_risk: true
sentiment_neutral: true
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.have.property('mobianGarmRisk');
expect(risk['mobianGarmRisk']).to.equal('high');
expect(risk).to.deep.equal({
risk: 'unknown',
contentCategories: [],
sentiment: 'neutral',
emotions: []
});
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk);
});
});
Expand All @@ -103,47 +96,6 @@ describe('Mobian RTD Submodule', function () {
});
});

it('should handle response with direct garm_risk field', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_risk: 'low',
sentiment_positive: true,
emotion_joy: true
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.deep.equal({
mobianGarmRisk: 'low',
garmContentCategories: [],
sentiment: 'positive',
emotions: ['joy']
});
});
});

it('should handle response with GARM content categories, sentiment, and emotions', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.success(JSON.stringify({
garm_risk: 'medium',
garm_content_category_arms: true,
garm_content_category_crime: true,
sentiment_negative: true,
emotion_anger: true,
emotion_fear: true
}));
});

return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => {
expect(risk).to.deep.equal({
mobianGarmRisk: 'medium',
garmContentCategories: ['arms', 'crime'],
sentiment: 'negative',
emotions: ['anger', 'fear']
});
});
});

it('should handle error response', function () {
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) {
callbacks.error();
Expand Down

0 comments on commit 996b235

Please sign in to comment.