2015-07-20 00:09:47 -07:00
'use strict' ;
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
var async = require ( 'async' ) ,
config = require ( '../../config.js' ) ,
database = require ( '../../database.js' ) ,
expect = require ( 'expect.js' ) ,
nock = require ( 'nock' ) ,
2015-12-15 09:12:52 -08:00
superagent = require ( 'superagent' ) ,
2015-07-20 00:09:47 -07:00
server = require ( '../../server.js' ) ,
shell = require ( '../../shell.js' ) ;
var SERVER _URL = 'http://localhost:' + config . get ( 'port' ) ;
var USERNAME = 'admin' , PASSWORD = 'password' , EMAIL = 'silly@me.com' ;
var token = null ; // authentication token
var server ;
function setup ( done ) {
2015-08-04 16:59:35 +02:00
nock . cleanAll ( ) ;
2015-07-20 00:09:47 -07:00
config . set ( 'version' , '0.5.0' ) ;
2015-10-30 21:20:45 +01:00
config . set ( 'fqdn' , 'localhost' ) ;
2015-07-20 00:09:47 -07:00
server . start ( done ) ;
}
function cleanup ( done ) {
database . _clear ( function ( error ) {
expect ( error ) . to . not . be . ok ( ) ;
server . stop ( done ) ;
} ) ;
}
var gSudoOriginal = null ;
function injectShellMock ( ) {
gSudoOriginal = shell . sudo ;
shell . sudo = function ( tag , options , callback ) { callback ( null ) ; } ;
}
function restoreShellMock ( ) {
shell . sudo = gSudoOriginal ;
}
describe ( 'Cloudron' , function ( ) {
describe ( 'activate' , function ( ) {
before ( setup ) ;
after ( cleanup ) ;
it ( 'fails due to missing setupToken' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. send ( { username : '' , password : 'somepassword' , email : 'admin@foo.bar' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
2015-12-29 16:07:04 +01:00
it ( 'fails due to internal server error on appstore side' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 500 , { message : 'this is wrong' } ) ;
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : 'somepassword' , email : 'admin@foo.bar' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 500 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
2015-07-20 00:09:47 -07:00
it ( 'fails due to empty username' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : '' , password : 'somepassword' , email : 'admin@foo.bar' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails due to empty password' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : '' , email : 'admin@foo.bar' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails due to empty email' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : 'somepassword' , email : '' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails due to empty name' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : '' , email : 'admin@foo.bar' , name : '' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails due to invalid email' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : 'somepassword' , email : 'invalidemail' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds' , function ( done ) {
var scope1 = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
var scope2 = nock ( config . apiServerOrigin ( ) ) . post ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/done?setupToken=somesetuptoken' ) . reply ( 201 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : 'somepassword' , email : 'admin@foo.bar' , name : 'tester' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 201 ) ;
expect ( scope1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( scope2 . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails the second time' , function ( done ) {
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : 'someuser' , password : 'somepassword' , email : 'admin@foo.bar' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 409 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
describe ( 'get config' , function ( ) {
before ( function ( done ) {
async . series ( [
setup ,
function ( callback ) {
var scope1 = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
var scope2 = nock ( config . apiServerOrigin ( ) ) . post ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/done?setupToken=somesetuptoken' ) . reply ( 201 , { } ) ;
config . _reset ( ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : USERNAME , password : PASSWORD , email : EMAIL } )
. end ( function ( error , result ) {
expect ( result ) . to . be . ok ( ) ;
expect ( scope1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( scope2 . isDone ( ) ) . to . be . ok ( ) ;
// stash token for further use
token = result . body . token ;
callback ( ) ;
} ) ;
} ,
] , done ) ;
} ) ;
after ( cleanup ) ;
it ( 'cannot get without token' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . get ( SERVER _URL + '/api/v1/cloudron/config' )
2015-07-20 00:09:47 -07:00
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 401 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds without appstore' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . get ( SERVER _URL + '/api/v1/cloudron/config' )
2015-07-20 00:09:47 -07:00
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 200 ) ;
expect ( result . body . apiServerOrigin ) . to . eql ( 'http://localhost:6060' ) ;
expect ( result . body . webServerOrigin ) . to . eql ( null ) ;
2015-10-30 21:20:45 +01:00
expect ( result . body . fqdn ) . to . eql ( config . fqdn ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . isCustomDomain ) . to . eql ( false ) ;
expect ( result . body . progress ) . to . be . an ( 'object' ) ;
expect ( result . body . update ) . to . be . an ( 'object' ) ;
2015-10-30 21:20:45 +01:00
expect ( result . body . version ) . to . eql ( config . version ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . developerMode ) . to . be . a ( 'boolean' ) ;
expect ( result . body . size ) . to . eql ( null ) ;
expect ( result . body . region ) . to . eql ( null ) ;
2015-10-22 11:05:29 +02:00
expect ( result . body . memory ) . to . eql ( 0 ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . cloudronName ) . to . be . a ( 'string' ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds' , function ( done ) {
2015-10-22 11:05:29 +02:00
var scope = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/localhost?token=' + config . token ( ) ) . reply ( 200 , { box : { region : 'sfo' , size : '1gb' } } ) ;
2015-07-20 00:09:47 -07:00
2015-12-15 09:12:52 -08:00
superagent . get ( SERVER _URL + '/api/v1/cloudron/config' )
2015-07-20 00:09:47 -07:00
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 200 ) ;
expect ( result . body . apiServerOrigin ) . to . eql ( 'http://localhost:6060' ) ;
expect ( result . body . webServerOrigin ) . to . eql ( null ) ;
2015-10-30 21:20:45 +01:00
expect ( result . body . fqdn ) . to . eql ( config . fqdn ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . isCustomDomain ) . to . eql ( false ) ;
expect ( result . body . progress ) . to . be . an ( 'object' ) ;
expect ( result . body . update ) . to . be . an ( 'object' ) ;
2015-10-30 21:20:45 +01:00
expect ( result . body . version ) . to . eql ( config . version ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . developerMode ) . to . be . a ( 'boolean' ) ;
2015-10-22 11:05:29 +02:00
expect ( result . body . size ) . to . eql ( '1gb' ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . region ) . to . eql ( 'sfo' ) ;
2015-10-22 11:05:29 +02:00
expect ( result . body . memory ) . to . eql ( 1073741824 ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . cloudronName ) . to . be . a ( 'string' ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
describe ( 'migrate' , function ( ) {
before ( function ( done ) {
async . series ( [
setup ,
function ( callback ) {
var scope1 = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
var scope2 = nock ( config . apiServerOrigin ( ) ) . post ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/done?setupToken=somesetuptoken' ) . reply ( 201 , { } ) ;
config . _reset ( ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-07-20 00:09:47 -07:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : USERNAME , password : PASSWORD , email : EMAIL } )
. end ( function ( error , result ) {
expect ( result ) . to . be . ok ( ) ;
expect ( scope1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( scope2 . isDone ( ) ) . to . be . ok ( ) ;
// stash token for further use
token = result . body . token ;
callback ( ) ;
} ) ;
} ,
2015-11-09 20:34:25 -08:00
function setupBackupConfig ( callback ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/settings/backup_config' )
2015-11-09 20:34:25 -08:00
. send ( { provider : 'caas' , token : 'BACKUP_TOKEN' , bucket : 'Bucket' , prefix : 'Prefix' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 200 ) ;
callback ( ) ;
} ) ;
}
2015-07-20 00:09:47 -07:00
] , done ) ;
} ) ;
after ( cleanup ) ;
it ( 'fails without token' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , region : 'sfo' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 401 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails without password' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , region : 'sfo' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with missing size' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with wrong size type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 4 , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with missing region' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with wrong region type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , region : 4 , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails when in wrong state' , function ( done ) {
2015-08-27 11:43:26 -07:00
var scope2 = nock ( config . apiServerOrigin ( ) )
2015-11-09 20:34:25 -08:00
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/awscredentials?token=BACKUP_TOKEN' )
2015-09-08 21:01:04 -07:00
. reply ( 201 , { credentials : { AccessKeyId : 'accessKeyId' , SecretAccessKey : 'secretAccessKey' , SessionToken : 'sessionToken' } } ) ;
2015-08-27 11:43:26 -07:00
var scope3 = nock ( config . apiServerOrigin ( ) )
2015-10-22 11:05:29 +02:00
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/backupDone?token=APPSTORE_TOKEN' , function ( body ) {
2015-09-08 22:11:19 -07:00
return body . boxVersion && body . restoreKey && ! body . appId && ! body . appVersion && body . appBackupIds . length === 0 ;
} )
2015-08-27 11:43:26 -07:00
. reply ( 200 , { id : 'someid' } ) ;
var scope1 = nock ( config . apiServerOrigin ( ) )
2015-09-08 22:11:19 -07:00
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/migrate?token=APPSTORE_TOKEN' , function ( body ) {
return body . size && body . region && body . restoreKey ;
} ) . reply ( 409 , { } ) ;
2015-07-20 00:09:47 -07:00
injectShellMock ( ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 202 ) ;
function checkAppstoreServerCalled ( ) {
2015-08-27 11:43:26 -07:00
if ( scope1 . isDone ( ) && scope2 . isDone ( ) && scope3 . isDone ( ) ) {
2015-07-20 00:09:47 -07:00
restoreShellMock ( ) ;
return done ( ) ;
}
setTimeout ( checkAppstoreServerCalled , 100 ) ;
}
checkAppstoreServerCalled ( ) ;
} ) ;
} ) ;
it ( 'succeeds' , function ( done ) {
2015-09-08 22:11:19 -07:00
var scope1 = nock ( config . apiServerOrigin ( ) ) . post ( '/api/v1/boxes/' + config . fqdn ( ) + '/migrate?token=APPSTORE_TOKEN' , function ( body ) {
return body . size && body . region && body . restoreKey ;
} ) . reply ( 202 , { } ) ;
var scope2 = nock ( config . apiServerOrigin ( ) )
2015-10-22 11:05:29 +02:00
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/backupDone?token=APPSTORE_TOKEN' , function ( body ) {
2015-09-08 22:11:19 -07:00
return body . boxVersion && body . restoreKey && ! body . appId && ! body . appVersion && body . appBackupIds . length === 0 ;
} )
. reply ( 200 , { id : 'someid' } ) ;
var scope3 = nock ( config . apiServerOrigin ( ) )
2015-11-09 20:34:25 -08:00
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/awscredentials?token=BACKUP_TOKEN' )
2015-09-08 22:11:19 -07:00
. reply ( 201 , { credentials : { AccessKeyId : 'accessKeyId' , SecretAccessKey : 'secretAccessKey' , SessionToken : 'sessionToken' } } ) ;
2015-07-20 00:09:47 -07:00
injectShellMock ( ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
2015-07-20 00:09:47 -07:00
. send ( { size : 'small' , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 202 ) ;
function checkAppstoreServerCalled ( ) {
2015-09-08 22:11:19 -07:00
if ( scope1 . isDone ( ) && scope2 . isDone ( ) && scope3 . isDone ( ) ) {
2015-07-20 00:09:47 -07:00
restoreShellMock ( ) ;
return done ( ) ;
}
setTimeout ( checkAppstoreServerCalled , 100 ) ;
}
checkAppstoreServerCalled ( ) ;
} ) ;
} ) ;
} ) ;
2015-08-04 16:59:35 +02:00
describe ( 'feedback' , function ( ) {
before ( function ( done ) {
async . series ( [
setup ,
function ( callback ) {
var scope1 = nock ( config . apiServerOrigin ( ) ) . get ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/verify?setupToken=somesetuptoken' ) . reply ( 200 , { } ) ;
var scope2 = nock ( config . apiServerOrigin ( ) ) . post ( '/api/v1/boxes/' + config . fqdn ( ) + '/setup/done?setupToken=somesetuptoken' ) . reply ( 201 , { } ) ;
config . _reset ( ) ;
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2015-08-04 16:59:35 +02:00
. query ( { setupToken : 'somesetuptoken' } )
. send ( { username : USERNAME , password : PASSWORD , email : EMAIL } )
. end ( function ( error , result ) {
expect ( result ) . to . be . ok ( ) ;
expect ( scope1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( scope2 . isDone ( ) ) . to . be . ok ( ) ;
// stash token for further use
token = result . body . token ;
callback ( ) ;
} ) ;
} ,
] , done ) ;
} ) ;
after ( cleanup ) ;
it ( 'fails without token' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , subject : 'some subject' , description : 'some description' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 401 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails without type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with empty type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : '' , subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with unknown type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'foobar' , subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds with ticket type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 201 ) ;
done ( ) ;
} ) ;
} ) ;
2015-08-06 17:34:40 +02:00
it ( 'succeeds with app type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-06 17:34:40 +02:00
. send ( { type : 'app' , subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 201 ) ;
done ( ) ;
} ) ;
} ) ;
2015-08-04 16:59:35 +02:00
it ( 'fails without description' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , subject : 'some subject' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with empty subject' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , subject : '' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails with empty description' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , subject : 'some subject' , description : '' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds with feedback type' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'feedback' , subject : 'some subject' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 201 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails without subject' , function ( done ) {
2015-12-15 09:12:52 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/feedback' )
2015-08-04 16:59:35 +02:00
. send ( { type : 'ticket' , description : 'some description' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
2015-07-20 00:09:47 -07:00
} ) ;