Skip to content

Commit a153fca

Browse files
committed
Merge pull request #263 from foundersandcoders/angulartokentactics
Angulartokentactics
2 parents 004c521 + b46f8c0 commit a153fca

File tree

10 files changed

+207
-9
lines changed

10 files changed

+207
-9
lines changed

makefile

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,39 @@ s:
22
node server/server.js
33

44
t:
5-
./node_modules/tape/bin/tape test/frontend/unit/*.js | ./node_modules/.bin/tap-spec
6-
7-
ts:
8-
./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape test/api/*.test.js | ./node_modules/.bin/tap-spec
5+
./node_modules/tape/bin/tape \
6+
test/frontend/unit/*.js \
7+
| ./node_modules/.bin/tap-spec
98

109
tc:
11-
./node_modules/.bin/istanbul cover test/frontend/unit/*.js | ./node_modules/.bin/tap-spec
10+
./node_modules/.bin/istanbul \
11+
cover \
12+
test/frontend/unit/*.js \
13+
| ./node_modules/.bin/tap-spec
14+
15+
c:
16+
./node_modules/node-sass/bin/node-sass \
17+
server/public/css/main.scss \
18+
server/public/css/main.css
19+
20+
cw:
21+
./node_modules/node-sass/bin/node-sass \
22+
--watch \
23+
server/public/css/main.scss \
24+
server/public/css/main.css
1225

1326
dep:
1427
npm install
1528

29+
b:
30+
./node_modules/.bin/browserify \
31+
server/angular/app.js \
32+
-o server/public/js/1.0.0.camdenmaps.min.js
33+
34+
bw:
35+
./node_modules/.bin/watchify \
36+
server/angular/app.js \
37+
-o server/public/js/1.0.0.camdenmaps.min.js \
38+
-v
39+
1640
.PHONY: s t dep

server/angular/services/fetch-token-service.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
"$http",
1111
function ($http) {
1212

13+
this.tokenIssued = false;
14+
1315
this.getToken = function getToken () {
14-
15-
return $http({method:"GET", url:"http://camdenmaps.herokuapp.com/auth_token"});
16+
if(!this.tokenIssued) {
17+
this.tokenIssued = true;
18+
return $http({method:"GET", url:"http://camdenmaps.herokuapp.com/auth_token"});
19+
} else {
20+
21+
return {
22+
success: function(cb) {
23+
cb();
24+
}
25+
}
26+
}
1627

1728
}
1829
}

server/lib/capitalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//capitalize first letter of word (norm
55
module.exports = function cap(word) {
6-
if(typeof word !== "undefined") {
6+
if(typeof word === "string") {
77
return word[0].toUpperCase() + word.substring(1, word.length).toLowerCase();
88
} else {
99
return word;

server/lib/cleanobj.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var strip = require("./striphtml.js");
55

66
//creates an includes function to search strings
7-
if (!('contains' in String.prototype)) {
7+
if (!String.prototype.hasOwnProperty("contains")) {
88
String.prototype.contains = function(str, startIndex) {
99
return ''.indexOf.call(this, str, startIndex) !== -1;
1010
};

server/logs/server_log.txt

Whitespace-only changes.

test/api/cacheprotocol.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var test = require("tape");
2+
var cacheprotocol = require("../../server/lib/cacheprotocol.js");
3+
4+
test("cacheprotocol should contain a function", function(t) {
5+
6+
t.equals(typeof cacheprotocol, "function", "cacheprotocol is a function");
7+
t.end();
8+
9+
});

test/api/capitalize.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var test = require("tape");
2+
var capitalize = require("../../server/lib/capitalize.js");
3+
4+
var ins = ["hello", "euhaoeusnht", "William"];
5+
var outs = ["Hello", "Euhaoeusnht", "William"];
6+
7+
8+
test("capitalize should be a function", function(t) {
9+
10+
t.equals(typeof capitalize, "function", "capitalize is a function");
11+
t.end();
12+
13+
});
14+
15+
16+
test("capitalize should return input if not a string", function(t) {
17+
18+
t.equals(typeof capitalize(), "undefined", "capitalize() returns undefined");
19+
t.equals(typeof capitalize(function(){}), "function", "capitalize(function({}) returns function");
20+
t.equals(typeof capitalize({test: "hello"}), "object", "capitalize({}) returns object");
21+
t.equals(typeof capitalize(3), "number", "capitalize(3) returns number");
22+
t.end();
23+
24+
});
25+
26+
27+
ins.map(function(w, i) {
28+
29+
test("capitalize should return word with capitalized first lettef if input is a string", function(t) {
30+
31+
t.equals(capitalize(w), outs[i], ins[i] + " returns " + outs[i]);
32+
t.end();
33+
34+
});
35+
36+
});

test/api/cleanobj.test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var test = require("tape");
2+
var clean = require("../../server/lib/cleanobj.js");
3+
4+
test("cleanobj.js should contain a function", function(t) {
5+
6+
t.equals(typeof clean, "function", "cleanobj.js is a function");
7+
t.end();
8+
9+
});
10+
11+
test("String.prototype should have method 'contains'", function(t) {
12+
13+
t.ok(String.prototype.hasOwnProperty("contains"), "String.prototype.contains exists");
14+
t.equals(typeof String.prototype.contains, "function", "String.prototype.contains is a function");
15+
t.end();
16+
17+
});
18+
19+
20+
test("String.prototype.contains should return true if string contains input", function(t) {
21+
22+
t.equals("HELLO".contains("O"), true, "'HELLO'.contains('O') is true");
23+
t.equals("eeee".contains(9), false, "'eeee'.contains(9) is false");
24+
t.end();
25+
26+
});
27+
28+
29+
test("cleanobj should only change properties that are strings and don't contain http://", function(t) {
30+
31+
var obj = {
32+
hello: ["heueu", 334],
33+
dog: true,
34+
url: "http://euaoeuaou",
35+
cat: 93939
36+
};
37+
38+
Object.keys(obj).map(function(k) {
39+
t.equals(clean(obj)[k], obj[k], "obj." + k + " is unchanged");
40+
});
41+
42+
t.end();
43+
44+
});
45+
46+
47+
test("cleanobj should change all / to 'and' in string properties", function(t) {
48+
49+
var obj = {
50+
yes: "eaosuh/aouea",
51+
no: "eaosuh/aouea/euaoeu",
52+
maybe: "aueoths/"
53+
};
54+
var objProcessed = {
55+
yes: "eaosuh and aouea",
56+
no: "eaosuh and aouea and euaoeu",
57+
maybe: "aueoths and "
58+
};
59+
60+
Object.keys(obj).map(function(k) {
61+
t.equals(clean(obj)[k], objProcessed[k], "obj." + k + " has been changed");
62+
});
63+
64+
t.end();
65+
66+
67+
});
68+
69+
70+
test("String.prototype.contains should not be overwritten if it exists", function(t) {
71+
72+
String.prototype.contains = function() {
73+
return true;
74+
};
75+
clean = require("../../server/lib/cleanobj.js");
76+
t.equals("".contains(), true, "String.prototype.contains has not been overwritten");
77+
t.end();
78+
79+
});

test/api/mapUri.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var test = require("tape");
2+
var mapUri = require("../../server/lib/mapUri.js");
3+
4+
test("mapUri should contain an object", function(t) {
5+
6+
t.equals(typeof mapUri, "object", "mapUri contains a function");
7+
t.ok(mapUri.hasOwnProperty("mapUri"), "mapUri.mapUri exists");
8+
t.ok(mapUri.hasOwnProperty("mapQuery"), "mapUri.mapQuery exists");
9+
t.ok(mapUri.hasOwnProperty("mapStreetworks"), "mapUri.mapStreetworks exists");
10+
t.ok(mapUri.hasOwnProperty("mapLocalInformation"), "mapUri.mapLocalInformation exists");
11+
12+
t.end();
13+
14+
});

test/api/server.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var test = require("tape");
2+
var server = require("../../server/server.js");
3+
var request = require("request");
4+
5+
var apiUrl = "http://0.0.0.0:8080";
6+
7+
server.start(function(){
8+
console.log("server started and tests running ...");
9+
10+
});
11+
12+
13+
test("server should contain an object");
14+
15+
16+
test("server should contain an object");
17+
test("server should contain an object");
18+
test("server should contain an object");
19+
test("server should contain an object");
20+
test("server should contain an object");
21+
test("server should contain an object");
22+
test("server should contain an object");
23+
test("server should contain an object");
24+
test("server should contain an object");
25+
test("server should contain an object");

0 commit comments

Comments
 (0)