Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup and first acceptance test for backend server
- Loading branch information
Showing
8 changed files
with
141 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
*.swp | ||
*zip |
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,18 @@ | ||
function Album(name, artist, image, link) { | ||
this.name = name; | ||
this.artist = artist; | ||
this.image = image; | ||
this.link = link; | ||
} | ||
|
||
Album.prototype.toString = function() { | ||
var ret = | ||
"Album\n" + | ||
" " + this.name + | ||
" " + this.artist + | ||
" " + this.image + | ||
" " + this.link; | ||
return ret; | ||
} | ||
|
||
module.exports = Album; |
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,34 @@ | ||
{ | ||
"name": "BandcampMultitagPlugin", | ||
"version": "1.1.0", | ||
"description": "Service to search Bandcamp using multiple tags", | ||
"main": "angular.min.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/SvDvorak/BandcampMultitagSearch.git" | ||
}, | ||
"keywords": [ | ||
"Bandcamp", | ||
"search", | ||
"tags" | ||
], | ||
"author": "Andreas Wilcox", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/SvDvorak/BandcampMultitagSearch/issues" | ||
}, | ||
"homepage": "https://github.com/SvDvorak/BandcampMultitagSearch", | ||
"dependencies": { | ||
"express": "^4.13.4", | ||
"xmlhttprequest": "^1.8.0" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.9.1", | ||
"gulp-less": "^3.1.0", | ||
"gulp-livereload": "^3.8.1", | ||
"jasmine": "^2.4.1" | ||
} | ||
} |
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,12 @@ | ||
|
||
var albums = {} | ||
|
||
module.exports = { | ||
getAlbumsByTag: function () { | ||
return albums; | ||
}, | ||
|
||
setAlbumsForTag: function (tag, newAlbums) { | ||
albums = newAlbums; | ||
} | ||
}; |
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,23 @@ | ||
|
||
module.exports = { | ||
bandcampApi : {}, | ||
|
||
start: function (bandcampApi) { | ||
var express = require("express"); | ||
var app = express(); | ||
|
||
//Lets define a port we want to listen to | ||
const PORT=8079; | ||
|
||
app.get("/", function(request, res) { | ||
var albums = bandcampApi.getAlbumsByTag(""); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.status(200); | ||
res.send(JSON.stringify(albums)); | ||
}); | ||
|
||
app.listen(PORT, function(){ | ||
console.log("Server listening on: http://localhost:%s", PORT); | ||
}); | ||
}, | ||
}; |
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 @@ | ||
require('./server').start(); |
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,39 @@ | ||
var server = require("../server/server"); | ||
var bandcampFake = require("../server/bandcamp-fake"); | ||
var Album = require("../api-types"); | ||
|
||
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | ||
|
||
describe("Server with cache", function() { | ||
beforeEach(function(done) { | ||
server.start(bandcampFake); | ||
setTimeout(function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
it("returns albums", function(done) { | ||
var album = new Album( | ||
"Album name", | ||
"Artist name", | ||
"www.imagelink.com", | ||
"www.albumlink.com"); | ||
|
||
bandcampFake.setAlbumsForTag("tag", album); | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "http://localhost:8079", true); | ||
xhr.onreadystatechange = function() { | ||
if(xhr.readyState == 4 && xhr.status == 200) { | ||
var actualAlbums = JSON.parse(xhr.responseText); | ||
expect(actualAlbums.name).toBe("Album name"); | ||
expect(actualAlbums.artist).toBe("Artist name"); | ||
expect(actualAlbums.image).toBe("www.imagelink.com"); | ||
expect(actualAlbums.link).toBe("www.albumlink.com"); | ||
done(); | ||
} | ||
} | ||
|
||
xhr.send(); | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"spec_dir": "spec", | ||
"spec_files": [ | ||
"**/*server.js" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.js" | ||
], | ||
"stopSpecOnExpectationFailure": false, | ||
"random": false | ||
} |