Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix unit tests
  • Loading branch information
bryanhiggins committed Nov 11, 2013
1 parent 0c959f0 commit fb6a59c1b077998d6ef0c58960af0b3cde4681a2
Showing 5 changed files with 49 additions and 26 deletions.
@@ -91,8 +91,13 @@ describe("create tests", function () {
});

it("Empty dir error", function () {
executeScript(CREATE_COMMAND, ["./"], true);
wrench.mkdirSyncRecursive(tempFolder);
executeScript(CREATE_COMMAND, [tempFolder], true);
expect(_output).toContain("The project path must be an empty directory");
this.after(function () {
wrench.rmdirSyncRecursive(tempFolder);
});

});

it("Invalid appId error", function () {
@@ -21,6 +21,7 @@ describe("logger", function () {
describe("when the log level is verbose", function () {
beforeEach(function () {
spyOn(console, "log");
spyOn(console, "error");
logger.level('verbose');
});

@@ -31,7 +32,7 @@ describe("logger", function () {

it("logs error messages", function () {
logger.error("PC LOAD LETTER");
expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
expect(console.error).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
});

it("logs warning messages", function () {
@@ -48,6 +49,7 @@ describe("logger", function () {
describe("when the log level is warn", function () {
beforeEach(function () {
spyOn(console, "log");
spyOn(console, "error");
logger.level('warn');
});

@@ -58,7 +60,7 @@ describe("logger", function () {

it("logs error messages", function () {
logger.error("PC LOAD LETTER");
expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
expect(console.error).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
});

it("logs warning messages", function () {
@@ -75,6 +77,7 @@ describe("logger", function () {
describe("when the log level is error", function () {
beforeEach(function () {
spyOn(console, "log");
spyOn(console, "error");
logger.level('error');
});

@@ -85,7 +88,7 @@ describe("logger", function () {

it("logs error messages", function () {
logger.error("PC LOAD LETTER");
expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
expect(console.error).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
});

it("doesn't log warning messages", function () {
@@ -25,6 +25,7 @@ var srcPath = __dirname + "/../../../../../templates/project/cordova/lib/",
localize = require(srcPath + "localize"),
logger = require(srcPath + "logger"),
packagerValidator = require(srcPath + "packager-validator"),
signingUtils = require(srcPath + "signing-utils"),
fs = require("fs"),
cmd,
extManager = {
@@ -64,40 +65,55 @@ describe("Packager Validator", function () {
}).toThrow(localize.translate("EXCEPTION_MISSING_SIGNING_KEY_FILE", "author.p12"));
});

it("throws an exception when -g set and barsigner.csk was not found", function () {
it("throws an exception when -g set and bbidtoken.csk or barsigner.csk was not found", function () {
var session = testUtilities.cloneObj(testData.session),
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = undefined;
session.storepass = "myPassword";

expect(function () {
packagerValidator.validateSession(session, configObj);
}).toThrow(localize.translate("EXCEPTION_MISSING_SIGNING_KEY_FILE", "barsigner.csk"));
}).toThrow(localize.translate("EXCEPTION_MISSING_SIGNING_KEY_FILE", "bbidtoken.csk"));
});

it("throws an exception when --buildId set and barsigner.csk was not found", function () {
it("does not throw an exception when -g set and barsigner.csk was found", function () {
var session = testUtilities.cloneObj(testData.session),
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = "barsigner.csk";
session.keystoreDb = "barsigner.db";
session.storepass = "myPassword";

expect(function () {
packagerValidator.validateSession(session, configObj);
}).not.toThrow();
});

it("throws an exception when --buildId set and bbbidtoken.csk was not found", function () {
var session = testUtilities.cloneObj(testData.session),
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = undefined;
session.buildId = "100";

expect(function () {
packagerValidator.validateSession(session, configObj);
}).toThrow(localize.translate("EXCEPTION_MISSING_SIGNING_KEY_FILE", "barsigner.csk"));
}).toThrow(localize.translate("EXCEPTION_MISSING_SIGNING_KEY_FILE", "bbidtoken.csk"));
});

it("throws an exception when -g set and barsigner.db was not found", function () {
var session = testUtilities.cloneObj(testData.session),
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = "c:/barsigner.csk";
session.keystoreDb = undefined;
session.storepass = "myPassword";
@@ -112,7 +128,7 @@ describe("Packager Validator", function () {
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = "c:/barsigner.csk";
session.keystoreDb = undefined;
session.buildId = "100";
@@ -138,21 +154,21 @@ describe("Packager Validator", function () {
expect(logger.warn).toHaveBeenCalledWith(localize.translate("WARNING_MISSING_SIGNING_KEY_FILE", "author.p12"));
});

it("generated a warning when Build ID is set in config and barsigner.csk was not found", function () {
it("generated a warning when Build ID is set in config and bbidtoken.csk was not found", function () {
var session = testUtilities.cloneObj(testData.session),
configObj = testUtilities.cloneObj(testData.config);

//Mock the logger
spyOn(logger, "warn");

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = undefined;
session.buildId = undefined;
configObj.buildId = "100";

packagerValidator.validateSession(session, configObj);
expect(logger.warn).toHaveBeenCalledWith(localize.translate("WARNING_MISSING_SIGNING_KEY_FILE", "barsigner.csk"));
expect(logger.warn).toHaveBeenCalledWith(localize.translate("WARNING_MISSING_SIGNING_KEY_FILE", "bbidtoken.csk"));
});

it("generated a warning when Build ID is set in config and barsigner.db was not found", function () {
@@ -163,7 +179,7 @@ describe("Packager Validator", function () {
spyOn(logger, "warn");

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = "c:/barsigner.csk";
session.keystoreDb = undefined;
session.buildId = undefined;
@@ -192,7 +208,7 @@ describe("Packager Validator", function () {
configObj = testUtilities.cloneObj(testData.config);

//setup signing parameters
session.keystore = "c:/author.p12";
session.keystore = signingUtils.getDefaultPath("author.p12");
session.keystoreCsk = "c:/barsigner.csk";
session.keystoreDb = "c:/barsigner.db";
session.storepass = undefined;
@@ -22,6 +22,7 @@
var session = require(__dirname + "/../../../../../templates/project/cordova/lib/session"),
localize = require(__dirname + "/../../../../../templates/project/cordova/lib/localize"),
testUtils = require("./test-utilities"),
utils = require(__dirname + "/../../../../../templates/project/cordova/lib/utils"),
path = require("path"),
fs = require("fs"),
wrench = require("wrench"),
@@ -31,6 +32,7 @@ describe("Session", function () {
beforeEach(function () {
//Do not create the source folder
spyOn(wrench, "mkdirSyncRecursive");
spyOn(utils, "getProperties").andReturn({});
});

it("sets the source directory correctly when specified [-s C:/sampleApp/mySource]", function () {
@@ -169,16 +171,14 @@ describe("Session", function () {
it("get params from non-existent file should throw error", function () {
var data = {
args: [ 'C:/sampleApp/sample.zip' ],
params: "blah.json"
},
result;
params: "blah.json",
keystorepass: "test"
};

spyOn(fs, "existsSync").andReturn(false);

result = session.initialize(data);

expect(function () {
result.getParams("blackberry-signer");
session.initialize(data);
}).toThrow(localize.translate("EXCEPTION_PARAMS_FILE_NOT_FOUND", path.resolve("blah.json")));
});

@@ -192,10 +192,8 @@ describe("Session", function () {
spyOn(path, "resolve").andReturn("test/params-bad.json");
spyOn(fs, "existsSync").andReturn(true);

result = session.initialize(data);

expect(function () {
result.getParams("blackberry-signer");
session.initialize(data);
}).toThrow(localize.translate("EXCEPTION_PARAMS_FILE_ERROR", path.resolve("blah.json")));
});
});
@@ -25,6 +25,7 @@ module.exports = function (done, custom) {
"bin/test/cordova/unit"
];
utils.copyFile('bin/lib/utils.js', 'bin/templates/project/cordova/lib/', '../');
utils.copyFile('bin/lib/signing-utils.js', 'bin/templates/project/cordova/lib/', '../');
jasmine.executeSpecsInFolder({
'specFolders': specs,
'onComplete': function (runner) {

0 comments on commit fb6a59c

Please sign in to comment.