Skip to content

Commit

Permalink
Merge pull request #263 from foundersandcoders/angulartokentactics
Browse files Browse the repository at this point in the history
Angulartokentactics
  • Loading branch information
FilWisher committed Feb 26, 2015
2 parents 004c521 + b46f8c0 commit a153fca
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 9 deletions.
34 changes: 29 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@ s:
node server/server.js

t:
./node_modules/tape/bin/tape test/frontend/unit/*.js | ./node_modules/.bin/tap-spec

ts:
./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape test/api/*.test.js | ./node_modules/.bin/tap-spec
./node_modules/tape/bin/tape \
test/frontend/unit/*.js \
| ./node_modules/.bin/tap-spec

tc:
./node_modules/.bin/istanbul cover test/frontend/unit/*.js | ./node_modules/.bin/tap-spec
./node_modules/.bin/istanbul \
cover \
test/frontend/unit/*.js \
| ./node_modules/.bin/tap-spec

c:
./node_modules/node-sass/bin/node-sass \
server/public/css/main.scss \
server/public/css/main.css

cw:
./node_modules/node-sass/bin/node-sass \
--watch \
server/public/css/main.scss \
server/public/css/main.css

dep:
npm install

b:
./node_modules/.bin/browserify \
server/angular/app.js \
-o server/public/js/1.0.0.camdenmaps.min.js

bw:
./node_modules/.bin/watchify \
server/angular/app.js \
-o server/public/js/1.0.0.camdenmaps.min.js \
-v

.PHONY: s t dep
15 changes: 13 additions & 2 deletions server/angular/services/fetch-token-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@
"$http",
function ($http) {

this.tokenIssued = false;

this.getToken = function getToken () {

return $http({method:"GET", url:"http://camdenmaps.herokuapp.com/auth_token"});
if(!this.tokenIssued) {
this.tokenIssued = true;
return $http({method:"GET", url:"http://camdenmaps.herokuapp.com/auth_token"});
} else {

return {
success: function(cb) {
cb();
}
}
}

}
}
Expand Down
2 changes: 1 addition & 1 deletion server/lib/capitalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//capitalize first letter of word (norm
module.exports = function cap(word) {
if(typeof word !== "undefined") {
if(typeof word === "string") {
return word[0].toUpperCase() + word.substring(1, word.length).toLowerCase();
} else {
return word;
Expand Down
2 changes: 1 addition & 1 deletion server/lib/cleanobj.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var strip = require("./striphtml.js");

//creates an includes function to search strings
if (!('contains' in String.prototype)) {
if (!String.prototype.hasOwnProperty("contains")) {
String.prototype.contains = function(str, startIndex) {
return ''.indexOf.call(this, str, startIndex) !== -1;
};
Expand Down
Empty file added server/logs/server_log.txt
Empty file.
9 changes: 9 additions & 0 deletions test/api/cacheprotocol.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var test = require("tape");
var cacheprotocol = require("../../server/lib/cacheprotocol.js");

test("cacheprotocol should contain a function", function(t) {

t.equals(typeof cacheprotocol, "function", "cacheprotocol is a function");
t.end();

});
36 changes: 36 additions & 0 deletions test/api/capitalize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var test = require("tape");
var capitalize = require("../../server/lib/capitalize.js");

var ins = ["hello", "euhaoeusnht", "William"];
var outs = ["Hello", "Euhaoeusnht", "William"];


test("capitalize should be a function", function(t) {

t.equals(typeof capitalize, "function", "capitalize is a function");
t.end();

});


test("capitalize should return input if not a string", function(t) {

t.equals(typeof capitalize(), "undefined", "capitalize() returns undefined");
t.equals(typeof capitalize(function(){}), "function", "capitalize(function({}) returns function");
t.equals(typeof capitalize({test: "hello"}), "object", "capitalize({}) returns object");
t.equals(typeof capitalize(3), "number", "capitalize(3) returns number");
t.end();

});


ins.map(function(w, i) {

test("capitalize should return word with capitalized first lettef if input is a string", function(t) {

t.equals(capitalize(w), outs[i], ins[i] + " returns " + outs[i]);
t.end();

});

});
79 changes: 79 additions & 0 deletions test/api/cleanobj.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var test = require("tape");
var clean = require("../../server/lib/cleanobj.js");

test("cleanobj.js should contain a function", function(t) {

t.equals(typeof clean, "function", "cleanobj.js is a function");
t.end();

});

test("String.prototype should have method 'contains'", function(t) {

t.ok(String.prototype.hasOwnProperty("contains"), "String.prototype.contains exists");
t.equals(typeof String.prototype.contains, "function", "String.prototype.contains is a function");
t.end();

});


test("String.prototype.contains should return true if string contains input", function(t) {

t.equals("HELLO".contains("O"), true, "'HELLO'.contains('O') is true");
t.equals("eeee".contains(9), false, "'eeee'.contains(9) is false");
t.end();

});


test("cleanobj should only change properties that are strings and don't contain http://", function(t) {

var obj = {
hello: ["heueu", 334],
dog: true,
url: "http://euaoeuaou",
cat: 93939
};

Object.keys(obj).map(function(k) {
t.equals(clean(obj)[k], obj[k], "obj." + k + " is unchanged");
});

t.end();

});


test("cleanobj should change all / to 'and' in string properties", function(t) {

var obj = {
yes: "eaosuh/aouea",
no: "eaosuh/aouea/euaoeu",
maybe: "aueoths/"
};
var objProcessed = {
yes: "eaosuh and aouea",
no: "eaosuh and aouea and euaoeu",
maybe: "aueoths and "
};

Object.keys(obj).map(function(k) {
t.equals(clean(obj)[k], objProcessed[k], "obj." + k + " has been changed");
});

t.end();


});


test("String.prototype.contains should not be overwritten if it exists", function(t) {

String.prototype.contains = function() {
return true;
};
clean = require("../../server/lib/cleanobj.js");
t.equals("".contains(), true, "String.prototype.contains has not been overwritten");
t.end();

});
14 changes: 14 additions & 0 deletions test/api/mapUri.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var test = require("tape");
var mapUri = require("../../server/lib/mapUri.js");

test("mapUri should contain an object", function(t) {

t.equals(typeof mapUri, "object", "mapUri contains a function");
t.ok(mapUri.hasOwnProperty("mapUri"), "mapUri.mapUri exists");
t.ok(mapUri.hasOwnProperty("mapQuery"), "mapUri.mapQuery exists");
t.ok(mapUri.hasOwnProperty("mapStreetworks"), "mapUri.mapStreetworks exists");
t.ok(mapUri.hasOwnProperty("mapLocalInformation"), "mapUri.mapLocalInformation exists");

t.end();

});
25 changes: 25 additions & 0 deletions test/api/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var test = require("tape");
var server = require("../../server/server.js");
var request = require("request");

var apiUrl = "http://0.0.0.0:8080";

server.start(function(){
console.log("server started and tests running ...");

});


test("server should contain an object");


test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");
test("server should contain an object");

0 comments on commit a153fca

Please sign in to comment.