Merge "Only add country field when it's in the schema"

This commit is contained in:
jenkins-bot 2014-09-29 14:05:25 +00:00 committed by Gerrit Code Review
commit 22966d4358
3 changed files with 16 additions and 1 deletions

View file

@ -102,6 +102,16 @@
return Math.floor( Math.random() * this.samplingFactor ) === 0;
};
/**
* True if the schema has a country field. Broken out in a separate function so it's easy to mock.
* @returns {boolean}
*/
L.schemaSupportsCountry = function () {
return this.eventLog && this.eventLog.schemas && // don't die if eventLog is a mock
this.schema in this.eventLog.schemas && // don't die if schema is not loaded
'country' in this.eventLog.schemas[this.schema].schema.properties;
};
/**
* Logs EventLogging data while including Geo data if any
* @param {Object} data
@ -113,7 +123,10 @@
if ( self.isInSample() ) {
return this.loadDependencies().then( function() {
// Add Geo information if there's any
if ( self.Geo && self.Geo.country !== undefined ) {
if (
self.Geo && self.Geo.country !== undefined &&
self.schemaSupportsCountry()
) {
data.country = self.Geo.country;
}

View file

@ -39,6 +39,7 @@
durationLogger = new mw.mmv.durationLogger.constructor();
durationLogger.samplingFactor = 1;
durationLogger.schemaSupportsCountry = this.sandbox.stub().returns( true );
this.sandbox.stub( mw.user, 'isAnon' ).returns( false );
this.sandbox.stub( durationLogger, 'loadDependencies' ).returns( dependenciesDeferred.promise() );

View file

@ -118,6 +118,7 @@
this.sandbox.stub( performance, 'loadDependencies' ).returns( $.Deferred().resolve() );
performance.setEventLog( fakeEventLog );
performance.schemaSupportsCountry = this.sandbox.stub().returns( true );
this.sandbox.stub( performance, 'getWindowPerformance' ).returns( {
getEntriesByName: function () {