Skip to content

Commit e4b9d71

Browse files
committed
[remote-config] Add more tests
1 parent 85c9a16 commit e4b9d71

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

plugins/remote-config/api/parts/rc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ remoteConfig.processFilter = function(inpUser, inpQuery) {
5353

5454
if (parts[0] !== 'chr') {
5555
if (typeof (value) !== 'undefined') {
56-
if (prop === 'up.av') {
56+
const filterType = Object.keys(query[prop])[0];
57+
58+
if (prop === 'up.av' && /^\$(gt|lt)/.test(filterType)) {
5759
qResult = qResult && processAppVersionValues(user.av, { [prop]: query[prop] }, prop);
5860
}
5961
else {
@@ -139,6 +141,8 @@ function processPropertyValues(value, query, prop) {
139141
* @returns {Boolean} property value status
140142
*/
141143
function processAppVersionValues(inpUserAv, query, prop) {
144+
// app version is stored in mongo like 1:1:0 instead of 1.1.0
145+
// the colons have to be replaced with dots so that semver lib can compare the app version
142146
const userAv = inpUserAv.replace(/:/g, '.');
143147
const filterType = Object.keys(query[prop])[0];
144148
const targetAv = query[prop] && query[prop][filterType] && query[prop][filterType].replace(/:/g, '.');

plugins/remote-config/tests/fetch_remote_config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,29 +233,37 @@ describe('Fetch remote config', () => {
233233
const queryGte = { 'up.av': { $gte: '1:0:0' } };
234234
const queryLt = { 'up.av': { $lt: '2:0:0' } };
235235
const queryLte = { 'up.av': { $lte: '1:0:0' } };
236+
const queryIn = { 'up.av': { $in: ['1:0:0'] } };
237+
const queryNin = { 'up.av': { $nin: ['2:0:0'] } };
236238

237239
should(remoteConfig.processFilter(targetedUser, queryGt)).equal(true);
238240
should(remoteConfig.processFilter(targetedUser, queryGte)).equal(true);
239241
should(remoteConfig.processFilter(targetedUser, queryLt)).equal(true);
240242
should(remoteConfig.processFilter(targetedUser, queryLte)).equal(true);
243+
should(remoteConfig.processFilter(targetedUser, queryIn)).equal(true);
244+
should(remoteConfig.processFilter(targetedUser, queryNin)).equal(true);
241245
});
242246

243247
it('Should not match non targeted user (app version)', () => {
244248
const nonTargetedUser = {
245249
_id: '1c5c91e1dd594d457a656fad1e55d0cf2a3f0601',
246250
uid: '13',
247-
did: 'targeted_user',
251+
did: 'non_targeted_user',
248252
av: '1:0:0',
249253
};
250254
const queryGt = { 'up.av': { $gt: '1:0:0' } };
251255
const queryGte = { 'up.av': { $gte: '2:0:0' } };
252256
const queryLt = { 'up.av': { $lt: '1:0:0' } };
253257
const queryLte = { 'up.av': { $lte: '0:0:0' } };
258+
const queryIn = { 'up.av': { $in: ['2:0:0'] } };
259+
const queryNin = { 'up.av': { $nin: ['1:0:0'] } };
254260

255261
should(remoteConfig.processFilter(nonTargetedUser, queryGt)).equal(false);
256262
should(remoteConfig.processFilter(nonTargetedUser, queryGte)).equal(false);
257263
should(remoteConfig.processFilter(nonTargetedUser, queryLt)).equal(false);
258264
should(remoteConfig.processFilter(nonTargetedUser, queryLte)).equal(false);
265+
should(remoteConfig.processFilter(nonTargetedUser, queryIn)).equal(false);
266+
should(remoteConfig.processFilter(nonTargetedUser, queryNin)).equal(false);
259267
});
260268

261269
it('Should match targeted user ($and query)', () => {

0 commit comments

Comments
 (0)