kopia lustrzana https://github.com/c9/core
Merge pull request +10708 from c9/refactor-addtrait
Refactor addtraitpull/223/head
commit
a8599aafe4
|
@ -0,0 +1,22 @@
|
|||
if (define === undefined) {
|
||||
var define = function(fn) {
|
||||
fn(require, exports, module);
|
||||
};
|
||||
}
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var internalTestNames = ["c9test", "c9 test"];
|
||||
var regex = new RegExp("^(" + internalTestNames.join("|") + ")+");
|
||||
|
||||
function hasInternalTestName(user) {
|
||||
if (!user.name && !user.username) return false;
|
||||
|
||||
var testedName = user.name ? user.name : user.username;
|
||||
|
||||
return regex.test(testedName);
|
||||
}
|
||||
|
||||
module.exports = hasInternalTestName;
|
||||
});
|
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
"use mocha";
|
||||
|
||||
require("c9/inline-mocha")(module);
|
||||
var assert = require("assert");
|
||||
var faker = require("faker");
|
||||
var hasInternalTestName= require("c9/has-internal-test-name");
|
||||
|
||||
describe("has-internal-test-name", function() {
|
||||
|
||||
it("returns false when undefined name", function() {
|
||||
var name;
|
||||
|
||||
assert.equal(false, hasInternalTestName(name), "should return false when name undefined");
|
||||
});
|
||||
|
||||
it("returns true when name contains c9test", function() {
|
||||
var name = "c9testregnjkdfkfd";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9test");
|
||||
|
||||
name = "c9test01";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9test");
|
||||
|
||||
name = "c9testjhrrj ffjh";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9test");
|
||||
});
|
||||
|
||||
it("returns true when name contains c9 test", function() {
|
||||
var name = "c9 test dkjfdgjhfgdfk";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9 test");
|
||||
|
||||
name = "c9 test07";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9 test");
|
||||
|
||||
name = "c9 testdkjfdgjhfgdfk";
|
||||
assert.equal(true, hasInternalTestName(name), "should return true when name contains c9 test");
|
||||
});
|
||||
|
||||
it("returns false when not internal user test name", function() {
|
||||
var name = faker.name.firstName();
|
||||
|
||||
assert.equal(false, hasInternalTestName(name), "should return false when name is not for internal testing");
|
||||
});
|
||||
});
|
|
@ -6,12 +6,15 @@ if (define === undefined) {
|
|||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
|
||||
var hasInternalDomain = require("c9/has-internal-domain");
|
||||
var hasInternalTestName = require("c9/has-internal-test-name");
|
||||
|
||||
function skipAnalytics(user) {
|
||||
if (!user) return true;
|
||||
if (user.id === -1) return true;
|
||||
|
||||
if (hasInternalTestName(user)) return true;
|
||||
if (hasInternalDomain(user.email)) return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,25 @@ describe("skip-analytics", function() {
|
|||
assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user id is -1");
|
||||
});
|
||||
|
||||
|
||||
it("returns false when user does not have an internal test name and no email", function() {
|
||||
var user = {
|
||||
id: faker.random.uuid(),
|
||||
name: faker.name.firstName()
|
||||
};
|
||||
|
||||
assert.equal(false, skipAnalytics(user), "skipAnalytics should return false when user does not have an internal test name and no email");
|
||||
});
|
||||
|
||||
it("returns true when user has an internal test name and no email", function() {
|
||||
var user = {
|
||||
id: faker.random.uuid(),
|
||||
name: "c9test07"
|
||||
};
|
||||
|
||||
assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user has an internal test name and no email");
|
||||
});
|
||||
|
||||
it("returns false when user has no email", function() {
|
||||
var user = {
|
||||
id: faker.random.uuid()
|
||||
|
|
Ładowanie…
Reference in New Issue