@@ -79,6 +79,25 @@ function createPostRequest(queryString, user) {
7979 return req ;
8080}
8181
82+ /**
83+ * Create delete request and return it.
84+ *
85+ * @param queryString - the query string
86+ * @param user - the user handle
87+ * @returns {* } request
88+ */
89+ function createDeleteRequest ( queryString , user ) {
90+ var req = request ( API_ENDPOINT )
91+ . del ( queryString )
92+ . set ( "Accept" , "application/json" )
93+ . expect ( "Content-Type" , / j s o n / ) ;
94+ if ( user ) {
95+ req . set ( 'Authorization' , generateAuthHeader ( user ) ) ;
96+ }
97+
98+ return req ;
99+ }
100+
82101/**
83102 * Assert error request.
84103 *
@@ -127,6 +146,30 @@ function assertPostError(queryString, user, obj, statusCode, errorDetail, done)
127146 } ) ;
128147}
129148
149+ /**
150+ * Assert delete response detail.
151+ *
152+ * @param queryString - the query string
153+ * @param user - the user handle
154+ * @param statusCode - the expected status code
155+ * @param errorDetail - the error detail.
156+ * @param done the callback function
157+ */
158+ function assertDeleteError ( queryString , user , statusCode , errorDetail , done ) {
159+ createDeleteRequest ( queryString , user ) . expect ( statusCode ) . end ( function ( err , res ) {
160+ if ( err ) {
161+ done ( err ) ;
162+ return ;
163+ }
164+ if ( statusCode === 200 ) {
165+ assert . equal ( res . body . error , errorDetail , "Invalid error detail" ) ;
166+ } else {
167+ assert . equal ( res . body . error . details , errorDetail , "Invalid error detail" ) ;
168+ }
169+ done ( ) ;
170+ } ) ;
171+ }
172+
130173/**
131174 * Create a long text.
132175 *
@@ -635,6 +678,34 @@ describe('SRM Round Questions APIs', function () {
635678 } ) ;
636679 } ) ;
637680
681+ describe ( 'Delete Round Question API invalid test' , function ( ) {
682+
683+ it ( "No anonymous access." , function ( done ) {
684+ assertDeleteError ( "/v2/data/srm/rounds/306/question" , null , 401 , "Authorized information needed." , done ) ;
685+ } ) ;
686+
687+ it ( "Admin access only." , function ( done ) {
688+ assertDeleteError ( "/v2/data/srm/rounds/306/question" , 'user' , 403 , "Admin access only." , done ) ;
689+ } ) ;
690+
691+ it ( "questionId should be number." , function ( done ) {
692+ assertDeleteError ( "/v2/data/srm/rounds/aaa/question" , 'heffan' , 400 , "questionId should be number." , done ) ;
693+ } ) ;
694+
695+ it ( "questionId should be Integer." , function ( done ) {
696+ assertDeleteError ( "/v2/data/srm/rounds/30.6/question" , 'heffan' , 400 , "questionId should be Integer." , done ) ;
697+ } ) ;
698+
699+ it ( "questionId should be positive." , function ( done ) {
700+ assertDeleteError ( "/v2/data/srm/rounds/-306/question" , 'heffan' , 400 , "questionId should be positive." , done ) ;
701+ } ) ;
702+
703+ it ( "questionId should be less or equal to 2147483647." , function ( done ) {
704+ assertDeleteError ( "/v2/data/srm/rounds/111111111111111111111111111/question" , 'heffan' , 400 ,
705+ "questionId should be less or equal to 2147483647." , done ) ;
706+ } ) ;
707+ } ) ;
708+
638709 describe ( 'Valid test' , function ( ) {
639710
640711 it ( "Valid set survey." , function ( done ) {
@@ -754,6 +825,65 @@ describe('SRM Round Questions APIs', function () {
754825 ] , done ) ;
755826 } ) ;
756827
828+ it ( "Valid test for delete question." , function ( done ) {
829+
830+ var validRequest = { "contest_id" : 123 , "text" : "text2" , "styleId" : 1 , "typeId" : 1 , "statusId" : 1 , "keyword" : "keyword1" , "isRequired" : true } ;
831+
832+ async . waterfall ( [
833+ function ( cb ) {
834+ var req = request ( API_ENDPOINT )
835+ . post ( "/v2/data/srm/rounds/13673/questions" )
836+ . set ( "Accept" , "application/json" )
837+ . expect ( "Content-Type" , / j s o n / ) ;
838+ req . set ( 'Authorization' , generateAuthHeader ( 'heffan' ) ) ;
839+ req . expect ( 200 ) . send ( validRequest ) . end ( function ( err , res ) {
840+ if ( err ) {
841+ cb ( err ) ;
842+ return ;
843+ }
844+ assert . equal ( res . body . success , true , "Invalid response detail" ) ;
845+ cb ( ) ;
846+ } ) ;
847+ } , function ( cb ) {
848+ var sql = "question_id from survey_question where survey_id = 13673" ;
849+ testHelper . runSqlSelectQuery ( sql , "informixoltp" , function ( err , result ) {
850+ if ( err ) {
851+ cb ( err ) ;
852+ return ;
853+ }
854+ assert . ok ( result . length >= 1 ) ;
855+ cb ( null , result [ 0 ] . question_id ) ;
856+ } ) ;
857+ } , function ( questionId , cb ) {
858+ createDeleteRequest ( "/v2/data/srm/rounds/" + questionId + "/question" , 'heffan' ) . expect ( 200 ) . end ( function ( err , res ) {
859+ if ( err ) {
860+ cb ( err ) ;
861+ return ;
862+ }
863+ assert . equal ( res . body . success , true , "Invalid response detail" ) ;
864+ cb ( null , questionId ) ;
865+ } ) ;
866+ } , function ( questionId , cb ) {
867+ var sqlQueries = [
868+ "question_id from survey_question where question_id = " + questionId ,
869+ "question_id from round_question where question_id = " + questionId ,
870+ "question_id from answer where question_id = " + questionId ,
871+ "question_id from question where question_id = " + questionId
872+ ] ;
873+ async . forEach ( sqlQueries , function ( sqlQuery , callback ) {
874+ testHelper . runSqlSelectQuery ( sqlQuery , "informixoltp" , function ( err , result ) {
875+ if ( err ) {
876+ callback ( err ) ;
877+ return ;
878+ }
879+ assert ( ! result || ( Array . isArray ( result ) && ! result . length ) , "Found question that was supposed to be deleted" ) ;
880+ callback ( ) ;
881+ } ) ;
882+ } , cb ) ;
883+ }
884+ ] , done ) ;
885+ } ) ;
886+
757887 it ( "Valid test for add question answer and list question answer." , function ( done ) {
758888 var validRequest = { "text" : "text2" , "styleId" : 1 , "typeId" : 1 , "statusId" : 1 , "keyword" : "keyword1" , "isRequired" : true } ,
759889 questionId ;
0 commit comments