Skip to content

Commit

Permalink
Setup and first acceptance test for backend server
Browse files Browse the repository at this point in the history
  • Loading branch information
SvDvorak committed Jun 3, 2016
1 parent f9a987f commit 9817172
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules/
*.swp
*zip
18 changes: 18 additions & 0 deletions api-types.js
@@ -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;
34 changes: 34 additions & 0 deletions package.json
@@ -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"
}
}
12 changes: 12 additions & 0 deletions server/bandcamp-fake.js
@@ -0,0 +1,12 @@

var albums = {}

module.exports = {
getAlbumsByTag: function () {
return albums;
},

setAlbumsForTag: function (tag, newAlbums) {
albums = newAlbums;
}
};
23 changes: 23 additions & 0 deletions server/server.js
@@ -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);
});
},
};
1 change: 1 addition & 0 deletions server/start_server.js
@@ -0,0 +1 @@
require('./server').start();
39 changes: 39 additions & 0 deletions spec/server.js
@@ -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();
});
});
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*server.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}

0 comments on commit 9817172

Please sign in to comment.