Skip to content

Commit

Permalink
Merge pull request #456 from systemapic/issue/454
Browse files Browse the repository at this point in the history
Issue/454
  • Loading branch information
knutole committed Feb 22, 2016
2 parents e2684a3 + b452b10 commit 6850b8e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 185 deletions.
181 changes: 47 additions & 134 deletions routes/routes.js

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions test/data/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ var httpStatus = require('http-status');
var format = require('util').format;
var endpoints = require('../endpoints.js');




module.exports = function () {
describe(endpoints.data.layers, function () {
this.slow(500);
Expand All @@ -24,7 +21,7 @@ module.exports = function () {

// test 1
it('should respond with status code 401 when not authenticated', function (done) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({})
.expect(httpStatus.UNAUTHORIZED)
.end(done);
Expand All @@ -35,7 +32,7 @@ module.exports = function () {
// test 2
it('should respond with status code 400 and error if type is not postgis or raster', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'not postgis or raster',
access_token: access_token
Expand All @@ -55,7 +52,7 @@ module.exports = function () {
// test 3
it('should respond with status code 400 and error if data.file_id doesn\'t exist in request body', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'raster',
access_token: access_token
Expand All @@ -70,7 +67,7 @@ module.exports = function () {
// test 4
it('should respond with status code 200 and empty array of layers if layers with specific file doesn\'t exist', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'raster',
data: {file_id: 'some file id'},
Expand All @@ -92,7 +89,7 @@ module.exports = function () {
// test 5
it('should respond with status code 200 and array of layers if type is raster and all parameters are correct', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'raster',
data: {file_id: helpers.test_layer.file},
Expand All @@ -119,7 +116,7 @@ module.exports = function () {
// test 6
it('should respond with status code 400 and error if table_name doesn\'t exist in request parameters', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'postgis',
data: {database_name: 'some database_name'},
Expand All @@ -135,7 +132,7 @@ module.exports = function () {
// test 7
it('should respond with status code 400 and error if database_name doesn\'t exist in request parameters', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'postgis',
data: {table_name: 'some table_name'},
Expand All @@ -151,7 +148,7 @@ module.exports = function () {
// test 8
it('should respond with status code 200 and empty array of layers if layers with specific table_name doesn\'t exist', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'postgis',
data: {table_name: 'some table_name', database_name: 'some database_name'},
Expand All @@ -173,7 +170,7 @@ module.exports = function () {
// test 9
it('should respond with status code 200 and array of specific layers if and all parameters are correctly', function (done) {
token(function (err, access_token) {
api.post(endpoints.data.layers)
api.get(endpoints.data.layers)
.send({
type: 'postgis',
data: {
Expand Down
8 changes: 4 additions & 4 deletions test/hashes/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ module.exports = function () {
});

it("should respond with status code 401 when not authenticated", function (done) {
api.post(endpoints.hashes.get)
api.get(endpoints.hashes.get)
.send()
.expect(httpStatus.UNAUTHORIZED)
.end(done);
});

it('should respond with status code 400 and specific error message if id and project_id don\'t exist in request body', function (done) {
token(function (err, access_token) {
api.post(endpoints.hashes.get)
api.get(endpoints.hashes.get)
.send({
access_token: access_token
})
Expand All @@ -71,7 +71,7 @@ module.exports = function () {

it('should respond with status code 400 and specific error message if id and project_id don\'t exist in request body', function (done) {
token(function (err, access_token) {
api.post(endpoints.hashes.get)
api.get(endpoints.hashes.get)
.send({
access_token: access_token,
project_id: 'some_project_id',
Expand All @@ -93,7 +93,7 @@ module.exports = function () {

it('should respond with status code 200', function (done) {
token(function (err, access_token) {
api.post(endpoints.hashes.get)
api.get(endpoints.hashes.get)
.send({
access_token: access_token,
project_id: tmpHash.project,
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = util = {
},

get_access_token : function (done) {
api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username : util.test_user.email,
password : util.test_user.password
Expand All @@ -98,7 +98,7 @@ module.exports = util = {
},

get_users_access_token : function (_user, callback) {
api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
grant_type : 'password',
username : _user.email,
Expand Down
8 changes: 3 additions & 5 deletions test/projects/getPrivate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ var endpoints = require('../endpoints.js');
module.exports = function () {
describe(endpoints.projects.private, function () {


// test 1
it("should respond with status code 401 when not authenticated", function (done) {
api.post(endpoints.projects.private)
api.get(endpoints.projects.private)
.send()
.expect(httpStatus.UNAUTHORIZED)
.end(done);
});


// test 2
it('should respond with status code 400 and specific error message if project_id or user_access_token don\'t exist in request body', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.private)
api.get(endpoints.projects.private)
.send({ access_token: access_token })
.expect(httpStatus.BAD_REQUEST)
.end(function (err, res) {
Expand All @@ -46,7 +44,7 @@ module.exports = function () {
// test 3
it('should respond with status code 200', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.private)
api.get(endpoints.projects.private)
.send({
access_token: access_token,
project_id: 'some project_id',
Expand Down
16 changes: 6 additions & 10 deletions test/projects/getPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ var endpoints = require('../endpoints.js');
module.exports = function () {
describe(endpoints.projects.public, function () {


// test 1
it("should respond with status code 401 when not authenticated", function (done) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send()
.expect(httpStatus.UNAUTHORIZED)
.end(done);
});


// test 2
it('should respond with status code 400 and specific error message if username or project_slug don\'t exist in request body', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send({ access_token: access_token })
.expect(httpStatus.BAD_REQUEST)
.end(function (err, res) {
Expand All @@ -41,13 +39,11 @@ module.exports = function () {
});
});
});



// test 3
it('should respond with status code 404 and specific error message if user doesn\'t exist', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send({
access_token: access_token,
username: 'some username',
Expand All @@ -70,7 +66,7 @@ module.exports = function () {
// test 4
it('should respond with status code 404 and specific error message', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send({
access_token: access_token,
username: helpers.test_user.username,
Expand Down Expand Up @@ -136,7 +132,7 @@ module.exports = function () {
// test 5
it('should respond with status code 400 and specific error message if project is not public', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send({
access_token: access_token,
username: helpers.test_user.username,
Expand All @@ -157,7 +153,7 @@ module.exports = function () {
// test 6
it('should respond with status code 200 and specific project', function (done) {
token(function (err, access_token) {
api.post(endpoints.projects.public)
api.get(endpoints.projects.public)
.send({
access_token: access_token,
username: helpers.test_user.username,
Expand Down
14 changes: 7 additions & 7 deletions test/token/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function () {
describe(endpoints.users.token.token, function () {
it('should respond with status code 400 and error if username and email don\'t exist in request body', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({})
.expect(httpStatus.BAD_REQUEST)
.end(function (err, res) {
Expand All @@ -32,7 +32,7 @@ module.exports = function () {

it('should respond with status code 400 and error if password doesn\'t exist in request body', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username: 'some user'
})
Expand All @@ -53,7 +53,7 @@ module.exports = function () {

it('should respond with status code 404 and error if user with specific username doesn\'t exist', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username: 'some user',
password: 'some password'
Expand All @@ -73,7 +73,7 @@ module.exports = function () {

it('should respond with status code 404 and error if user with specific email doesn\'t exist', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
email: 'some user',
password: 'some password'
Expand Down Expand Up @@ -105,7 +105,7 @@ module.exports = function () {

it('should respond with status code 400 and error if user with specific username exists but password is wrong', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username: helpers.test_user.username,
password: 'some password'
Expand All @@ -125,7 +125,7 @@ module.exports = function () {

it('should get access token with email and password', function (done) {

api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username : helpers.test_user.email,
password : helpers.test_user.password
Expand All @@ -146,7 +146,7 @@ module.exports = function () {
});

it('should get access token with username and password', function (done) {
api.post(endpoints.users.token.token)
api.get(endpoints.users.token.token)
.send({
username : helpers.test_user.username,
password : helpers.test_user.password
Expand Down
2 changes: 1 addition & 1 deletion test/user_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('User', function () {
it('should get portal store with access token', function (done) {
this.slow(700);
token(function (err, access_token) {
api.post(endpoints.portal)
api.get(endpoints.portal)
.send({access_token : access_token})
.expect(200)
.end(function (err, res) {
Expand Down
6 changes: 3 additions & 3 deletions test/users/getInviteLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function () {
describe(endpoints.users.invite.link, function () {

it('should respond with status code 401 when not authenticated', function (done) {
api.post(endpoints.users.invite.link)
api.get(endpoints.users.invite.link)
.send({})
.expect(httpStatus.UNAUTHORIZED)
.end(done);
Expand All @@ -25,7 +25,7 @@ module.exports = function () {
return done(err);
}

api.post(endpoints.users.invite.link)
api.get(endpoints.users.invite.link)
.send({
access_token: access_token
})
Expand All @@ -52,7 +52,7 @@ module.exports = function () {
return done(err);
}

api.post(endpoints.users.invite.link)
api.get(endpoints.users.invite.link)
.send({
access_token: access_token,
access: "test_access"
Expand Down
Loading

0 comments on commit 6850b8e

Please sign in to comment.