Skip to content
Browse files

Add UT

  • Loading branch information...
1 parent bde09a2 commit bdb69aec34acbcd15ca8e98cac41711dca1c2a6a @andrerod andrerod committed
Showing with 162 additions and 67 deletions.
  1. +31 −28 lib/cli/commands/siteconfig.js
  2. +25 −23 lib/cli/commands/siteconfig_.js
  3. +106 −16 test/cli/commands/cli.siteconfig-tests.js
View
59 lib/cli/commands/siteconfig.js
@@ -85,9 +85,7 @@ exports.init = function(cli) {
return site.doSiteConfigGet(context, __cb(_, __frame, 10, 31, function ___(__0, __1) { siteConfigurations = __1;
if (siteConfigurations.AppSettings.NameValuePair) {
- if (siteConfigurations.AppSettings.NameValuePair.Name) {
- siteConfigurations.AppSettings.NameValuePair = [siteConfigurations.AppSettings.NameValuePair,]; } ;
-
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
log.table(siteConfigurations.AppSettings.NameValuePair, function(row, item) {
row.cell("Name", item.Name);
@@ -98,7 +96,7 @@ exports.init = function(cli) {
- siteConfig.command("add <keyvaluepair> [name]").usage("[options] <keyvaluepair> [name]").description("Adds an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __2(keyvaluepair, name, options, _) { var context, settings, siteConfigurations, setting; var __frame = { name: "__2", line: 105 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
+ siteConfig.command("add <keyvaluepair> [name]").usage("[options] <keyvaluepair> [name]").description("Adds an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __2(keyvaluepair, name, options, _) { var context, settings, siteConfigurations, setting; var __frame = { name: "__2", line: 103 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
@@ -117,11 +115,7 @@ exports.init = function(cli) {
return site.doSiteConfigGet(context, __cb(_, __frame, 12, 31, function ___(__0, __1) { siteConfigurations = __1;
if ((Object.keys(settings).length > 0)) {
- if (!siteConfigurations.AppSettings.NameValuePair) {
- siteConfigurations.AppSettings.NameValuePair = []; } else {
- if (siteConfigurations.AppSettings.NameValuePair.Name) {
- siteConfigurations.AppSettings.NamevaluePair = [siteConfigurations.AppSettings.NamevaluePair,]; } ; } ;
-
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
for (setting in settings) {
if (settings.hasOwnProperty(setting)) {
@@ -140,10 +134,10 @@ exports.init = function(cli) {
- return site.doSiteConfigPUT(siteConfigurations, context, __cb(_, __frame, 38, 6, _, true)); }, true)); }, true)); }); });
+ return site.doSiteConfigPUT(siteConfigurations, context, __cb(_, __frame, 34, 6, _, true)); }, true)); }, true)); }); });
- siteConfig.command("clear <key> [name]").usage("[options] <key> [name]").description("Clears an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __3(key, name, options, _) { var context, siteConfigurations, found, settings, i; var __frame = { name: "__3", line: 150 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
+ siteConfig.command("clear <key> [name]").usage("[options] <key> [name]").description("Clears an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __3(key, name, options, _) { var context, siteConfigurations, found, i; var __frame = { name: "__3", line: 144 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
@@ -161,21 +155,21 @@ exports.init = function(cli) {
found = false; return (function __$__3(__then) {
if (siteConfigurations.AppSettings.NameValuePair) {
- settings = siteConfigurations.AppSettings.NameValuePair;
- if (settings.Name) {
- settings = [settings,]; } ;
-
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
- for (i = 0; (i < settings.length); i++) {
- if ((settings[i].Name === key)) {
- settings.splice(i, 1);
+ for (i = 0; (i < siteConfigurations.AppSettings.NameValuePair.length); i++) {
+ if ((siteConfigurations.AppSettings.NameValuePair[i].Name === key)) {
+ siteConfigurations.AppSettings.NameValuePair.splice(i, 1);
found = true;
i--; } ; }; return (function __$__3(__then) {
if (found) {
- siteConfigurations.AppSettings.NameValuePair = settings;
+ if ((siteConfigurations.AppSettings.NameValuePair.length === 0)) {
+ siteConfigurations.AppSettings = { }; } ;
+
+
return site.doSiteConfigPUT(siteConfigurations, context, __cb(_, __frame, 29, 10, __then, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$__3() {
@@ -185,7 +179,7 @@ exports.init = function(cli) {
- siteConfig.command("get <key> [name]").usage("[options] <key> [name]").description("Gets an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __4(key, name, options, _) { var context, siteConfigurations, found, settings, i; var __frame = { name: "__4", line: 192 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
+ siteConfig.command("get <key> [name]").usage("[options] <key> [name]").description("Gets an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __4(key, name, options, _) { var context, siteConfigurations, found, i; var __frame = { name: "__4", line: 186 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
@@ -203,18 +197,27 @@ exports.init = function(cli) {
found = false;
if (siteConfigurations.AppSettings.NameValuePair) {
- settings = siteConfigurations.AppSettings.NameValuePair;
- if (settings.Name) {
- settings = [settings,]; } ;
-
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
- for (i = 0; (i < settings.length); i++) {
- if ((settings[i].Name === key)) {
- log.data("Value: ", settings[i].Value); return _(null); } ; }; } ;
+ for (i = 0; (i < siteConfigurations.AppSettings.NameValuePair.length); i++) {
+ if ((siteConfigurations.AppSettings.NameValuePair[i].Name === key)) {
+ log.data("Value: ", siteConfigurations.AppSettings.NameValuePair[i].Value); return _(null); } ; }; } ;
if (!found) {
- return _(Error((("Application setting with key \"" + key) + "\" does not exist."))); } ; _(); }, true)); }, true)); }); });};
+ return _(Error((("Application setting with key \"" + key) + "\" does not exist."))); } ; _(); }, true)); }, true)); }); });
+
+
+
+ function getSettings(appSettings) {
+ var settings = appSettings;
+ if (!settings.NameValuePair) {
+ settings.NameValuePair = []; }
+ else if (settings.NameValuePair.Name) {
+ settings.NameValuePair = [settings.NameValuePair,]; } ;
+
+
+ return settings; };};
View
48 lib/cli/commands/siteconfig_.js
@@ -85,9 +85,7 @@ exports.init = function (cli) {
var siteConfigurations = site.doSiteConfigGet(context, _);
if (siteConfigurations.AppSettings.NameValuePair) {
- if (siteConfigurations.AppSettings.NameValuePair.Name) {
- siteConfigurations.AppSettings.NameValuePair = [ siteConfigurations.AppSettings.NameValuePair ];
- }
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
log.table(siteConfigurations.AppSettings.NameValuePair, function (row, item) {
row.cell('Name', item.Name);
@@ -117,11 +115,7 @@ exports.init = function (cli) {
var siteConfigurations = site.doSiteConfigGet(context, _);
if (Object.keys(settings).length > 0) {
- if (!siteConfigurations.AppSettings.NameValuePair) {
- siteConfigurations.AppSettings.NameValuePair = [ ];
- } else if (siteConfigurations.AppSettings.NameValuePair.Name) {
- siteConfigurations.AppSettings.NamevaluePair = [ siteConfigurations.AppSettings.NamevaluePair ];
- }
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
for (var setting in settings) {
if (settings.hasOwnProperty(setting)) {
@@ -161,21 +155,21 @@ exports.init = function (cli) {
var found = false;
if (siteConfigurations.AppSettings.NameValuePair) {
- var settings = siteConfigurations.AppSettings.NameValuePair;
- if (settings.Name) {
- settings = [ settings ];
- }
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
- for (var i = 0; i < settings.length; i++) {
- if (settings[i].Name === key) {
- settings.splice(i, 1);
+ for (var i = 0; i < siteConfigurations.AppSettings.NameValuePair.length; i++) {
+ if (siteConfigurations.AppSettings.NameValuePair[i].Name === key) {
+ siteConfigurations.AppSettings.NameValuePair.splice(i, 1);
found = true;
i--;
}
}
if (found) {
- siteConfigurations.AppSettings.NameValuePair = settings;
+ if (siteConfigurations.AppSettings.NameValuePair.length === 0) {
+ siteConfigurations.AppSettings = { };
+ }
+
site.doSiteConfigPUT(siteConfigurations, context, _);
}
}
@@ -203,14 +197,11 @@ exports.init = function (cli) {
var found = false;
if (siteConfigurations.AppSettings.NameValuePair) {
- var settings = siteConfigurations.AppSettings.NameValuePair;
- if (settings.Name) {
- settings = [ settings ];
- }
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
- for (var i = 0; i < settings.length; i++) {
- if (settings[i].Name === key) {
- log.data('Value: ', settings[i].Value);
+ for (var i = 0; i < siteConfigurations.AppSettings.NameValuePair.length; i++) {
+ if (siteConfigurations.AppSettings.NameValuePair[i].Name === key) {
+ log.data('Value: ', siteConfigurations.AppSettings.NameValuePair[i].Value);
return;
}
}
@@ -220,4 +211,15 @@ exports.init = function (cli) {
throw Error('Application setting with key "' + key + '" does not exist.')
}
});
+
+ function getSettings(appSettings) {
+ var settings = appSettings;
+ if (!settings.NameValuePair) {
+ settings.NameValuePair = [ ];
+ } else if (settings.NameValuePair.Name) {
+ settings.NameValuePair = [ settings.NameValuePair ];
+ }
+
+ return settings;
+ };
};
View
122 test/cli/commands/cli.siteconfig-tests.js
@@ -32,13 +32,49 @@ var should = require('should');
var cli = require('../cli');
var capture = require('../util').capture;
+var siteName1 = 'cliuttestsiteconfig1';
+var siteName2 = 'cliuttestsiteconfig2';
+
+var siteNames = [ siteName1, siteName2 ];
+
suite('cli', function(){
suite('siteconfig', function() {
- test('siteconfig list', function(done) {
- var siteName = 'cliuttestsiteconfig1';
+ setup(function (done) {
+
+ var removeSites = function (sites, cb) {
+ if (sites.length === 0) {
+ cb();
+ } else {
+ var siteName = sites.pop();
+ // Delete created site
+ var cmd = ('node cli.js site delete ' + siteName + ' --json --quiet').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ removeSites(sites, cb);
+ });
+ }
+ };
+
+ // List sites
+ var cmd = ('node cli.js site list --json').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ var siteList = JSON.parse(result.text);
+ var filteredSites = siteNames.filter(function (site) {
+ return siteList.some(function (s) {
+ return site === s.Name;
+ });
+ });
+
+ removeSites(filteredSites, done);
+ });
+ });
+ test('siteconfig list', function(done) {
// Create site
- var cmd = ('node cli.js site create ' + siteName + ' --json --location').split(' ');
+ var cmd = ('node cli.js site create ' + siteName1 + ' --json --location').split(' ');
cmd.push('East US');
capture(function() {
@@ -48,7 +84,7 @@ suite('cli', function(){
result.exitStatus.should.equal(0);
// List sites
- cmd = ('node cli.js site config list ' + siteName + ' --json ').split(' ');
+ cmd = ('node cli.js site config list ' + siteName1 + ' --json ').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
@@ -57,14 +93,14 @@ suite('cli', function(){
result.exitStatus.should.equal(0);
// add a setting
- var cmd = ('node cli.js site config add mysetting=myvalue ' + siteName + ' --json').split(' ');
+ var cmd = ('node cli.js site config add mysetting=myvalue ' + siteName1 + ' --json').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
result.text.should.equal('');
result.exitStatus.should.equal(0);
- cmd = 'node cli.js site config list --json'.split(' ');
+ cmd = ('node cli.js site config list ' + siteName1 + ' --json').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
@@ -74,15 +110,14 @@ suite('cli', function(){
settingsList.length.should.equal(1);
// add another setting
- var cmd = ('node cli.js site config add mysetting=myvalue ' + siteName + ' --json').split(' ');
+ var cmd = ('node cli.js site config add mysetting2=myvalue ' + siteName1 + ' --json').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
- console.log(result);
result.text.should.equal('');
result.exitStatus.should.equal(0);
- cmd = ('node cli.js site config list ' + siteName + ' --json').split(' ');
+ cmd = ('node cli.js site config list ' + siteName1 + ' --json').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
@@ -91,13 +126,68 @@ suite('cli', function(){
// Listing should return 2 setting now
settingsList.length.should.equal(2);
- // Delete created site
- cmd = ('node cli.js site delete ' + siteName + ' --json --quiet').split(' ');
- capture(function() {
- cli.parse(cmd);
- }, function (result) {
- done();
- });
+ done();
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+
+ test('siteconfig add get clear', function(done) {
+ var siteName = 'cliuttestsiteconfig2';
+
+ // Create site
+ var cmd = ('node cli.js site create ' + siteName2 + ' --json --location').split(' ');
+ cmd.push('East US');
+
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.text.should.equal('');
+ result.exitStatus.should.equal(0);
+
+ // List sites
+ cmd = ('node cli.js site config list ' + siteName2 + ' --json ').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ // there should be not settings yet as the site was just created
+ result.text.should.equal('');
+ result.exitStatus.should.equal(0);
+
+ // add a setting
+ var cmd = ('node cli.js site config add mysetting=myvalue ' + siteName2 + ' --json').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.text.should.equal('');
+ result.exitStatus.should.equal(0);
+
+ cmd = ('node cli.js site config get mysetting ' + siteName2 + ' --json').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.text.should.equal('"myvalue"\n');
+ result.exitStatus.should.equal(0);
+
+ // add another setting
+ var cmd = ('node cli.js site config clear mysetting ' + siteName2 + ' --json').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.text.should.equal('');
+ result.exitStatus.should.equal(0);
+
+ cmd = ('node cli.js site config list ' + siteName2 + ' --json').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.text.should.equal('');
+ result.exitStatus.should.equal(0);
+
+ done();
});
});
});

0 comments on commit bdb69ae

Please sign in to comment.
Something went wrong with that request. Please try again.