From 98c6c332a91ba09ad0307eb130c6a8ecc03114c5 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 26 May 2016 09:33:38 +0000 Subject: [PATCH] Improve braintree id checking --- node_modules/c9/is-zuora-id.js | 8 ++++++ node_modules/c9/is-zuora-id_test.js | 42 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 node_modules/c9/is-zuora-id.js create mode 100644 node_modules/c9/is-zuora-id_test.js diff --git a/node_modules/c9/is-zuora-id.js b/node_modules/c9/is-zuora-id.js new file mode 100644 index 00000000..7d5dea3f --- /dev/null +++ b/node_modules/c9/is-zuora-id.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = function isZuoraId(value){ + if (/^\d+$/.test(value)) + return false; + + return /^[a-z0-9]{32}$/.test(value); +}; \ No newline at end of file diff --git a/node_modules/c9/is-zuora-id_test.js b/node_modules/c9/is-zuora-id_test.js new file mode 100644 index 00000000..557e5940 --- /dev/null +++ b/node_modules/c9/is-zuora-id_test.js @@ -0,0 +1,42 @@ +"use strict"; +"use mocha"; + +require("c9/inline-mocha")(module); +var assert = require("assert"); +var isZuoraId= require("c9/is-zuora-id"); + +describe("iz-zuora-id-test", function() { + + it("returns false when account id undefined", function() { + assert.equal(false, isZuoraId(undefined), "should return false when account id undefined"); + }); + + it("returns false when account id null", function() { + assert.equal(false, isZuoraId(null), "should return false when account id null"); + }); + + it("returns false when account id is an empty string", function() { + assert.equal(false, isZuoraId(""), "should return false when account id is an empty string"); + }); + + it("returns false when account id contains only digits", function() { + var accountId = "12345700674455"; + assert.equal(false, isZuoraId(accountId), "should return false when account id contains only digits"); + }); + + it("returns false when account id contains only digits and has the correct length", function() { + var accountId = "123456789101112131415161718192021"; + assert.equal(false, isZuoraId(accountId), "should return false when account id contains only digits and has the correct length"); + }); + + it("returns false when account id contains both digits and letters but does not have the correct length", function() { + var accountId = "78654hjfgf764674h87634876g7h89h"; + assert.equal(false, isZuoraId(accountId), "should return false"); + }); + + it("returns true when account id has both letters and digits and correct length", function() { + var accountId = "2c92a0f850a7a1b50150c672fa3a6ddd"; + + assert.equal(true, isZuoraId(accountId), "should return true when account id has both letters and digits and correct length"); + }); +}); \ No newline at end of file