diff --git a/modules/mobianRtdProvider.js b/modules/mobianRtdProvider.js index 76626a7c020..71b6ed2d51d 100644 --- a/modules/mobianRtdProvider.js +++ b/modules/mobianRtdProvider.js @@ -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_', '')); @@ -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 }; diff --git a/test/spec/modules/mobianRtdProvider_spec.js b/test/spec/modules/mobianRtdProvider_spec.js index 6f7da8888fc..43f6cbaf569 100644 --- a/test/spec/modules/mobianRtdProvider_spec.js +++ b/test/spec/modules/mobianRtdProvider_spec.js @@ -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); }); }); @@ -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();