2015-07-20 00:09:47 -07:00
'use strict' ;
/* 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' ) ,
2016-06-27 22:24:30 -05:00
locker = require ( '../../locker.js' ) ,
2015-07-20 00:09:47 -07:00
nock = require ( 'nock' ) ,
2015-12-31 11:55:01 +01:00
os = require ( 'os' ) ,
2015-12-15 09:12:52 -08:00
superagent = require ( 'superagent' ) ,
2015-07-20 00:09:47 -07:00
server = require ( '../../server.js' ) ,
2016-10-13 14:55:14 -07:00
settings = require ( '../../settings.js' ) ,
2015-07-20 00:09:47 -07:00
shell = require ( '../../shell.js' ) ;
var SERVER _URL = 'http://localhost:' + config . get ( 'port' ) ;
2016-04-13 16:50:20 -07:00
var USERNAME = 'superadmin' , PASSWORD = 'Foobar?1337' , EMAIL = 'silly@me.com' ;
2015-07-20 00:09:47 -07:00
var token = null ; // authentication token
var server ;
function setup ( done ) {
2015-08-04 16:59:35 +02:00
nock . cleanAll ( ) ;
2016-01-29 14:17:31 +01:00
config . _reset ( ) ;
2015-07-20 00:09:47 -07:00
config . set ( 'version' , '0.5.0' ) ;
2016-06-27 22:24:30 -05:00
config . set ( 'fqdn' , 'localhost' ) ;
2016-10-13 14:55:14 -07:00
server . start ( function ( error ) {
if ( error ) return done ( error ) ;
2016-10-13 15:28:05 -07:00
settings . setBackupConfig ( { provider : 'caas' , token : 'BACKUP_TOKEN' , bucket : 'Bucket' , prefix : 'Prefix' } , done ) ;
2016-10-13 14:55:14 -07:00
} ) ;
2015-07-20 00:09:47 -07:00
}
function cleanup ( done ) {
database . _clear ( function ( error ) {
expect ( error ) . to . not . be . ok ( ) ;
2016-01-29 14:17:31 +01:00
config . _reset ( ) ;
2015-07-20 00:09:47 -07:00
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' } )
2016-01-20 16:06:51 +01:00
. send ( { username : 'someuser' , password : 'strong#A3asdf' , email : 'admin@foo.bar' } )
2015-12-29 16:07:04 +01:00
. 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' } )
2016-01-20 16:06:51 +01:00
. send ( { username : '' , password : 'ADSFsdf$%436' , email : 'admin@foo.bar' } )
2015-07-20 00:09:47 -07:00
. 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' } )
2016-01-20 16:06:51 +01:00
. send ( { username : 'someuser' , password : 'ADSF#asd546' , email : '' } )
2015-07-20 00:09:47 -07:00
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
2016-01-20 16:14:44 +01:00
it ( 'fails due to wrong displayName type' , function ( done ) {
2015-07-20 00:09:47 -07:00
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' } )
2016-01-20 16:14:44 +01:00
. send ( { username : 'someuser' , password : 'ADSF?#asd546' , email : 'admin@foo.bar' , displayName : 1234 } )
2015-07-20 00:09:47 -07:00
. 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' } )
2016-01-20 16:06:51 +01:00
. send ( { username : 'someuser' , password : 'ADSF#asd546' , email : 'invalidemail' } )
2015-07-20 00:09:47 -07:00
. 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' } )
2016-01-20 16:14:44 +01:00
. send ( { username : 'someuser' , password : 'ADSF#asd546' , email : 'admin@foo.bar' , displayName : 'tester' } )
2015-07-20 00:09:47 -07:00
. 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' } )
2016-01-20 16:06:51 +01:00
. send ( { username : 'someuser' , password : 'ADSF#asd546' , email : 'admin@foo.bar' } )
2015-07-20 00:09:47 -07:00
. 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 ( ) ) ;
2017-02-06 23:27:04 -08:00
expect ( result . body . isCustomDomain ) . to . eql ( true ) ;
2015-07-20 00:09:47 -07:00
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-12-31 11:55:01 +01:00
expect ( result . body . memory ) . to . eql ( os . totalmem ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . cloudronName ) . to . be . a ( 'string' ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'succeeds' , function ( done ) {
2016-04-10 17:15:19 -07:00
var scope = nock ( config . apiServerOrigin ( ) )
. get ( '/api/v1/boxes/localhost?token=' + config . token ( ) )
. reply ( 200 , { box : { region : 'sfo' , size : '1gb' } , user : { } } ) ;
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 ( ) ) ;
2017-02-06 23:27:04 -08:00
expect ( result . body . isCustomDomain ) . to . eql ( true ) ;
2015-07-20 00:09:47 -07:00
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-12-31 11:55:01 +01:00
expect ( result . body . memory ) . to . eql ( os . totalmem ( ) ) ;
2015-07-20 00:09:47 -07:00
expect ( result . body . cloudronName ) . to . be . a ( 'string' ) ;
expect ( scope . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
2016-06-27 22:24:30 -05:00
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 , { } ) ;
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
. 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 ( function ( done ) {
locker . unlock ( locker . _operation ) ; // migrate never unlocks
cleanup ( done ) ;
} ) ;
it ( 'fails without token' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 'small' , region : 'sfo' } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 401 ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'fails without password' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 'small' , region : 'sfo' } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
2016-07-14 16:17:09 +02:00
it ( 'succeeds without size' , function ( done ) {
2016-06-27 22:24:30 -05:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
2016-07-14 16:17:09 +02:00
expect ( result . statusCode ) . to . equal ( 202 ) ;
2016-06-27 22:24:30 -05:00
done ( ) ;
} ) ;
} ) ;
it ( 'fails with wrong size type' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 4 , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
2016-07-14 16:17:09 +02:00
it ( 'succeeds without region' , function ( done ) {
2016-06-27 22:24:30 -05:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 'small' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
2016-07-14 16:17:09 +02:00
expect ( result . statusCode ) . to . equal ( 202 ) ;
2016-06-27 22:24:30 -05:00
done ( ) ;
} ) ;
} ) ;
it ( 'fails with wrong region type' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. 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 ) {
var scope2 = nock ( config . apiServerOrigin ( ) )
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/awscredentials?token=BACKUP_TOKEN' )
. reply ( 201 , { credentials : { AccessKeyId : 'accessKeyId' , SecretAccessKey : 'secretAccessKey' , SessionToken : 'sessionToken' } } ) ;
var scope3 = nock ( config . apiServerOrigin ( ) )
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/backupDone?token=APPSTORE_TOKEN' , function ( body ) {
return body . boxVersion && body . restoreKey && ! body . appId && ! body . appVersion && body . appBackupIds . length === 0 ;
} )
. reply ( 200 , { id : 'someid' } ) ;
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 ( 409 , { } ) ;
injectShellMock ( ) ;
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 'small' , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 202 ) ;
function checkAppstoreServerCalled ( ) {
if ( scope1 . isDone ( ) && scope2 . isDone ( ) && scope3 . isDone ( ) ) {
restoreShellMock ( ) ;
return done ( ) ;
}
setTimeout ( checkAppstoreServerCalled , 100 ) ;
}
checkAppstoreServerCalled ( ) ;
} ) ;
} ) ;
it ( 'succeeds' , function ( done ) {
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 ( ) )
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/backupDone?token=APPSTORE_TOKEN' , function ( body ) {
return body . boxVersion && body . restoreKey && ! body . appId && ! body . appVersion && body . appBackupIds . length === 0 ;
} )
. reply ( 200 , { id : 'someid' } ) ;
var scope3 = nock ( config . apiServerOrigin ( ) )
. post ( '/api/v1/boxes/' + config . fqdn ( ) + '/awscredentials?token=BACKUP_TOKEN' )
. reply ( 201 , { credentials : { AccessKeyId : 'accessKeyId' , SecretAccessKey : 'secretAccessKey' , SessionToken : 'sessionToken' } } ) ;
injectShellMock ( ) ;
superagent . post ( SERVER _URL + '/api/v1/cloudron/migrate' )
. send ( { size : 'small' , region : 'sfo' , password : PASSWORD } )
. query ( { access _token : token } )
. end ( function ( error , result ) {
expect ( result . statusCode ) . to . equal ( 202 ) ;
function checkAppstoreServerCalled ( ) {
if ( scope1 . isDone ( ) && scope2 . isDone ( ) && scope3 . isDone ( ) ) {
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' )
2016-03-04 22:27:18 +01:00
. send ( { type : 'app_missing' , subject : 'some subject' , description : 'some description' } )
2015-08-06 17:34:40 +02:00
. 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
} ) ;