-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Financial-Times/tests
Adding Tests
- Loading branch information
Showing
15 changed files
with
393 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea/ | ||
node_modules/ | ||
bower_components/ | ||
test/app/public/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "0.12.2" | ||
before_install: | ||
- npm install -g karma-cli | ||
- npm install -g origami-build-tools | ||
install: | ||
- make install | ||
script: | ||
- make verify test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
.PHONY: test | ||
|
||
clean: | ||
git clean -xfd | ||
|
||
install: | ||
origami-build-tools install | ||
|
||
verify: | ||
nbt verify | ||
nbt verify --skip-layout-checks | ||
|
||
test: | ||
./node_modules/karma/bin/karma start | ||
karma start | ||
|
||
test-app: | ||
rm -rf test/app/public/ | ||
mkdir test/app/public/ | ||
browserify test/app/main.js --debug --transform debowerify > test/app/public/bundle.js | ||
node test/app/server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
'use strict'; | ||
var request = require('./src/request'); | ||
var cache = require('./src/cache'); | ||
|
||
function makeRequest(url){ | ||
return request(url).then(function(response){ | ||
return response.ok ? response.json() : Promise.resolve(false); | ||
}).catch(function(e){ | ||
setTimeout(function(){ | ||
throw e; | ||
}, 0); | ||
}) | ||
|
||
function details(){ | ||
// if it has products then it must've been a full call | ||
if(cache('products')){ | ||
return Promise.resolve(cache()); | ||
} | ||
|
||
return request('/').then(function(sessionDetails){ | ||
cache(sessionDetails); | ||
return sessionDetails; | ||
}); | ||
} | ||
|
||
function uuid(){ | ||
if(cache('uuid')){ | ||
return Promise.resolve({uuid:cache('uuid')}); | ||
} | ||
|
||
return request('/uuid').then(function(response){ | ||
cache('uuid', response.uuid); | ||
return response; | ||
}); | ||
} | ||
|
||
function session(){ | ||
return makeRequest('/'); | ||
function validate(){ | ||
return request('/validate'); | ||
} | ||
|
||
session.validate = function(){ | ||
return makeRequest('/validate'); | ||
module.exports = { | ||
details : details, | ||
uuid : uuid, | ||
validate : validate, | ||
cache : cache | ||
}; | ||
|
||
module.exports = session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var detailsCache = {}; | ||
|
||
|
||
function cache(name, value) { | ||
if(typeof name === 'object'){ | ||
detailsCache = name; | ||
return; | ||
} | ||
|
||
if(typeof name === 'string' && typeof value === 'string') { | ||
detailsCache[name] = value; | ||
return; | ||
} | ||
|
||
if(typeof name === 'string' && typeof value === 'undefined') { | ||
return detailsCache[name] || null; | ||
} | ||
|
||
if(typeof name === 'undefined' && typeof value === 'undefined') { | ||
return detailsCache; | ||
} | ||
|
||
throw new Error('Invalid arguments'); | ||
} | ||
|
||
cache.clear = function(){ | ||
detailsCache = {}; | ||
}; | ||
|
||
module.exports = cache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>APP TEST</title> | ||
<link rel="stylesheet" href="//build.origami.ft.com/bundles/css?modules=o-buttons@^2.0.3" /> | ||
|
||
</head> | ||
<body> | ||
|
||
<div class="buttons"> | ||
<button id="details" data-method="details" class="o-buttons o-buttons--big">Session Details</button> | ||
<button id="uuid" data-method="uuid" class="o-buttons o-buttons--big">Get UUID</button> | ||
<button id="validate" data-method="validate" class="o-buttons o-buttons--big">Validate Session</button> | ||
</div> | ||
|
||
<div class="results"> | ||
|
||
</div> | ||
<script src="bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
var session = require('../../main'); | ||
|
||
function handleClick(e){ | ||
var target = e.target; | ||
var method = target.getAttribute('data-method'); | ||
console.log('Call method ' + method); | ||
session[method]().then(function(response){ | ||
console.log(response); | ||
}); | ||
} | ||
|
||
function addClick(el){ | ||
console.log('add click to', el); | ||
el.addEventListener('click', handleClick); | ||
} | ||
|
||
[].slice.call(document.querySelectorAll('.buttons button'), 0).forEach(addClick); |
Oops, something went wrong.