[tests][analytics] rewrite analytics tests - now at 100% coverage
This commit is contained in:
parent
feec632306
commit
e4bac7bb67
|
@ -1,71 +1,193 @@
|
||||||
describe('analytics()', () => {
|
describe('analytics()', () => {
|
||||||
it('logEvent: it should log a text event without error', () =>
|
describe('logEvent()', () => {
|
||||||
new Promise(resolve => {
|
it('errors on using a reserved name', () => {
|
||||||
firebase.analytics().logEvent('test_event');
|
try {
|
||||||
resolve();
|
firebase.analytics().logEvent('session_start');
|
||||||
}));
|
} catch (e) {
|
||||||
|
e.message.should.containEql('reserved event');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('logEvent: it should log a text event with parameters without error', () =>
|
it('errors if name not alphanumeric', () => {
|
||||||
new Promise(resolve => {
|
try {
|
||||||
|
firebase.analytics().logEvent('!@£$%^&*');
|
||||||
|
} catch (e) {
|
||||||
|
e.message.should.containEql('is invalid');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if more than 25 params provided', () => {
|
||||||
|
try {
|
||||||
|
firebase.analytics().logEvent('fooby', {
|
||||||
|
1: 1,
|
||||||
|
2: 2,
|
||||||
|
3: 3,
|
||||||
|
4: 4,
|
||||||
|
5: 5,
|
||||||
|
6: 6,
|
||||||
|
7: 7,
|
||||||
|
8: 8,
|
||||||
|
9: 9,
|
||||||
|
10: 10,
|
||||||
|
11: 11,
|
||||||
|
12: 12,
|
||||||
|
13: 13,
|
||||||
|
14: 14,
|
||||||
|
15: 15,
|
||||||
|
16: 16,
|
||||||
|
17: 17,
|
||||||
|
18: 18,
|
||||||
|
19: 19,
|
||||||
|
20: 20,
|
||||||
|
21: 21,
|
||||||
|
22: 22,
|
||||||
|
23: 23,
|
||||||
|
24: 24,
|
||||||
|
25: 25,
|
||||||
|
26: 26,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
e.message.should.containEql('Maximum number of parameters exceeded');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if name is not a string', () => {
|
||||||
|
(() => {
|
||||||
|
firebase.analytics().logEvent(123456);
|
||||||
|
}).should.throw(
|
||||||
|
`analytics.logEvent(): First argument 'name' is required and must be a string value.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if params is not an object', () => {
|
||||||
|
(() => {
|
||||||
|
firebase.analytics().logEvent('test_event', 'this should be an object');
|
||||||
|
}).should.throw(
|
||||||
|
`analytics.logEvent(): Second optional argument 'params' must be an object if provided.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('log an event without parameters', () => {
|
||||||
|
firebase.analytics().logEvent('test_event');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('log an event with parameters', () => {
|
||||||
firebase.analytics().logEvent('test_event', {
|
firebase.analytics().logEvent('test_event', {
|
||||||
boolean: true,
|
boolean: true,
|
||||||
number: 1,
|
number: 1,
|
||||||
string: 'string',
|
string: 'string',
|
||||||
});
|
});
|
||||||
resolve();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('logEvent should error if name is not a string', () => {
|
|
||||||
(() => {
|
|
||||||
firebase.analytics().logEvent(123456);
|
|
||||||
}).should.throw(
|
|
||||||
`analytics.logEvent(): First argument 'name' is required and must be a string value.`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('logEvent should error if params is not an object', () => {
|
describe('setAnalyticsCollectionEnabled()', () => {
|
||||||
(() => {
|
it('true', () => {
|
||||||
firebase.analytics().logEvent('test_event', 'this should be an object');
|
|
||||||
}).should.throw(
|
|
||||||
`analytics.logEvent(): Second optional argument 'params' must be an object if provided.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('setAnalyticsCollectionEnabled: it should run without error', () =>
|
|
||||||
new Promise(resolve => {
|
|
||||||
firebase.analytics().setAnalyticsCollectionEnabled(true);
|
firebase.analytics().setAnalyticsCollectionEnabled(true);
|
||||||
resolve();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('setCurrentScreen: it should run without error', () =>
|
it('false', () => {
|
||||||
new Promise(resolve => {
|
firebase.analytics().setAnalyticsCollectionEnabled(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setCurrentScreen()', () => {
|
||||||
|
it('screenName only', () => {
|
||||||
|
firebase.analytics().setCurrentScreen('test screen');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('screenName with screenClassOverride', () => {
|
||||||
firebase
|
firebase
|
||||||
.analytics()
|
.analytics()
|
||||||
.setCurrentScreen('test screen', 'test class override');
|
.setCurrentScreen('test screen', 'test class override');
|
||||||
resolve();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('setMinimumSessionDuration: it should run without error', () =>
|
xit('errors if screenName not a string', () => {
|
||||||
new Promise(resolve => {
|
// TODO needs validations adding to lib
|
||||||
firebase.analytics().setMinimumSessionDuration(10000);
|
});
|
||||||
resolve();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('setSessionTimeoutDuration: it should run without error', () =>
|
xit('errors if screenClassOverride not a string', () => {
|
||||||
new Promise(resolve => {
|
// TODO needs validations adding to lib
|
||||||
firebase.analytics().setSessionTimeoutDuration(1800000);
|
});
|
||||||
resolve();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('setUserId: it should run without error', () =>
|
describe('setMinimumSessionDuration()', () => {
|
||||||
new Promise(resolve => {
|
it('default duration', () => {
|
||||||
|
firebase.analytics().setMinimumSessionDuration();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('custom duration', () => {
|
||||||
|
firebase.analytics().setMinimumSessionDuration(10001);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setSessionTimeoutDuration()', () => {
|
||||||
|
it('default duration', () => {
|
||||||
|
firebase.analytics().setSessionTimeoutDuration();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('custom duration', () => {
|
||||||
|
firebase.analytics().setSessionTimeoutDuration(1800001);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setUserId()', () => {
|
||||||
|
// nulls remove the field on firebase
|
||||||
|
it('allows a null values to be set', () => {
|
||||||
|
firebase.analytics().setUserId(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts string values', () => {
|
||||||
firebase.analytics().setUserId('test-id');
|
firebase.analytics().setUserId('test-id');
|
||||||
resolve();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('setUserProperty: it should run without error', () =>
|
it('rejects none string none null values', () => {
|
||||||
new Promise(resolve => {
|
try {
|
||||||
firebase.analytics().setUserProperty('test-property', 'test-value');
|
firebase.analytics().setUserId(33.3333);
|
||||||
resolve();
|
} catch (e) {
|
||||||
}));
|
e.message.should.containEql('must be a string');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setUserProperty()', () => {
|
||||||
|
// nulls remove the field on firebase
|
||||||
|
it('allows a null values to be set', () => {
|
||||||
|
firebase.analytics().setUserProperty('fooby', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts string values', () => {
|
||||||
|
firebase.analytics().setUserProperty('fooby2', 'test-id');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects none string none null values', () => {
|
||||||
|
try {
|
||||||
|
firebase.analytics().setUserProperty('fooby3', 33.3333);
|
||||||
|
} catch (e) {
|
||||||
|
e.message.should.containEql('must be a string');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('errors if property name not a string', () => {
|
||||||
|
// TODO needs validations adding to lib
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setUserProperties()', () => {
|
||||||
|
// nulls remove the field on firebase
|
||||||
|
it('allows a null values to be set', () => {
|
||||||
|
firebase.analytics().setUserProperties({ fooby: null });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts string values', () => {
|
||||||
|
firebase.analytics().setUserProperties({ fooby2: 'test-id' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects none string none null values', () => {
|
||||||
|
try {
|
||||||
|
firebase.analytics().setUserProperties({ fooby3: 33.3333 });
|
||||||
|
} catch (e) {
|
||||||
|
e.message.should.containEql('must be a string');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue