Skip to content

Commit

Permalink
Test format changed for feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Oct 24, 2016
1 parent 87f94c0 commit f3d4ae4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
18 changes: 16 additions & 2 deletions api/v1/helpers/verbs/findUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
const u = require('./utils');
const constants = require('../../constants');
const defaults = require('../../../../config').api.defaults;
const filterSubjByTags = require('../../../../config').filterSubjByTags;
const conf = require('../../../../config');

const env = conf.environment[conf.nodeEnv];
const filterSubjByTags = env.filterSubjByTags;

/**
* Escapes all percent literals so they're not treated as wildcards.
Expand Down Expand Up @@ -185,7 +188,18 @@ function options(params, props) {
const keys = Object.keys(params);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const isFilterField = constants.NOT_FILTER_FIELDS.indexOf(key) < 0;

let isFilterField;
if (filterSubjByTags) {
isFilterField = constants.NOT_FILTER_FIELDS.indexOf(key) < 0;
} else {
// if filterSubjByTags is disabled and we do v1/subjects?tags=mytag, we
// get error because isFilterField resolves to true becuase of swagger
// changes, and I cannot apply feature flag to swagger.
isFilterField = constants.NOT_FILTER_FIELDS.indexOf(key) < 0 &&
key !== props.tagFilterName;
}

if (isFilterField && params[key].value !== undefined) {
filter[key] = params[key].value;
}
Expand Down
25 changes: 23 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ module.exports = {
useAccessToken: pe.USE_ACCESS_TOKEN || false,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
development: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -133,6 +134,7 @@ module.exports = {
useAccessToken: pe.USE_ACCESS_TOKEN || false,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
production: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -151,6 +153,7 @@ module.exports = {
useAccessToken: pe.USE_ACCESS_TOKEN || false,
tokenSecret: pe.SECRET_TOKEN ||
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
test: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -169,6 +172,7 @@ module.exports = {
useAccessToken: pe.USE_ACCESS_TOKEN || false,
tokenSecret: pe.SECRET_TOKEN ||
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
testDisableHttp: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -182,6 +186,7 @@ module.exports = {
useAccessToken: 'true',
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
testWhitelistLocalhost: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -195,6 +200,7 @@ module.exports = {
ipWhitelist: iplist,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
testBlockAllhosts: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -208,6 +214,7 @@ module.exports = {
ipWhitelist: [''],
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
testTokenReq: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -221,6 +228,7 @@ module.exports = {
useAccessToken: 'true',
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},
testTokenNotReq: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
Expand All @@ -234,8 +242,22 @@ module.exports = {
useAccessToken: false,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags,
},

testSubjTagFilter: {
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
DEFAULT_CHECK_TIMEOUT_INTERVAL_MILLIS,
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
disableHttp,
redisUrl: '//127.0.0.1:6379',
defaultNodePort: defaultPort,
host: '127.0.0.1',
useAccessToken: false,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
filterSubjByTags: true,
}
},

nodeEnv,
Expand All @@ -250,5 +272,4 @@ module.exports = {
optimizeUpsert,
enableCachePerspective,
enableClockDyno,
filterSubjByTags,
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"test-token-notreq": "NODE_ENV=testTokenNotReq mocha -R dot --recursive tests/tokenNotReq",
"test-db": "npm run resetdb && mocha -R dot --recursive tests/db",
"test-realtime": "mocha -R dot --recursive tests/realtime",
"test-subj-tag-filter": "NODE_ENV=testSubjTagFilter mocha -R dot --recursive tests/subjectTagFilter",
"test-view": "NODE_ENV=test mocha -R dot --recursive --compilers js:babel-core/register --require ./tests/view/setup.js tests/view",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/db && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-realtime && npm run test-token-req && npm run test-token-notreq && npm run test-disablehttp",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/db && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-realtime && npm run test-token-req && npm run test-token-notreq && npm run test-disablehttp && npm run test-subj-tag-filter",
"postinstall": "NODE_ENV=production gulp browserifyViews && gulp movecss && gulp movesocket && gulp movelensutil && npm run checkdb",
"prestart": "npm run checkprivatedb"
},
Expand Down
36 changes: 0 additions & 36 deletions tests/api/v1/subjects/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const u = require('./utils');
const Subject = tu.db.Subject;
const path = '/v1/subjects';
const expect = require('chai').expect;
const filterSubjByTags = require('../../../../config').filterSubjByTags;

describe(`api: GET ${path}`, () => {
let token;
Expand Down Expand Up @@ -188,41 +187,6 @@ describe(`api: GET ${path}`, () => {
});
});

if (filterSubjByTags) {
it('GET with tag filter :: one tag', (done) => {
api.get(`${path}/?tags=US`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res.body.length).to.equal(2);
expect(res.body[0].tags).to.eql(['US']);
expect(res.body[1].tags).to.eql(['US', 'NE']);

done();
});
});

it('GET with tag filter :: multiple tags', (done) => {
api.get(`${path}/?tags=NE,US`)
.set('Authorization', token)
.expect(constants.httpStatus.OK)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res.body.length).to.equal(1);
expect(res.body[0].tags).to.eql(['US', 'NE']);

done();
});
});
}

it('pagination tests');
it('childCount, descendentCount');
it('by id');
Expand Down

0 comments on commit f3d4ae4

Please sign in to comment.