@@ -17,7 +17,9 @@ var should = require('should');
17
17
var assert = require ( 'assert' ) ;
18
18
var request = require ( 'supertest' ) ;
19
19
var async = require ( 'async' ) ;
20
+ var _ = require ( 'lodash' ) ;
20
21
var config = require ( 'config' ) ;
22
+ var sampleData = require ( './../sampledata' ) ;
21
23
22
24
var datasource = require ( './../../datasource' ) ;
23
25
datasource . init ( config ) ;
@@ -39,14 +41,7 @@ describe('Challenges Controller', function() {
39
41
describe ( 'Challenges API' , function ( ) {
40
42
var challengeId ;
41
43
beforeEach ( function ( done ) {
42
- reqData = {
43
- title : 'Serenity Challenge' ,
44
- status : 'SUBMISSION' ,
45
- account : 'account' ,
46
- accountId : '12ASD' ,
47
- prizes : [ 500.00 , 250.00 ] ,
48
- regStartAt : '2014-10-09'
49
- } ;
44
+ reqData = _ . clone ( sampleData . challengeData , true ) ;
50
45
done ( ) ;
51
46
} ) ;
52
47
@@ -149,6 +144,120 @@ describe('Challenges Controller', function() {
149
144
} ) ;
150
145
} ) ;
151
146
147
+ it ( 'should return fields respecting the Swagger documentation file' , function ( done ) {
148
+ var challengeId ;
149
+ var challengeFileId ;
150
+ var participantId ;
151
+ var requirementId ;
152
+ var scorecardId ;
153
+ var scorecardItemId ;
154
+ var submissionId ;
155
+ var submissionFileId ;
156
+ async . series ( [ function ( callback ) {
157
+ // create challenge
158
+ request ( url )
159
+ . post ( '/challenges' )
160
+ . send ( sampleData . challengeData )
161
+ . end ( function ( err , res ) {
162
+ // verify response
163
+ should . not . exist ( err ) ;
164
+ challengeId = res . body . id ;
165
+ callback ( ) ;
166
+ } ) ;
167
+ } , function ( callback ) {
168
+ // add file to challenge
169
+ request ( url )
170
+ . post ( '/challenges/' + challengeId + '/files' )
171
+ . send ( sampleData . challengeFileData )
172
+ . end ( function ( err , res ) {
173
+ // verify response
174
+ should . not . exist ( err ) ;
175
+ challengeFileId = res . body . id ;
176
+ callback ( ) ;
177
+ } ) ;
178
+ } , function ( callback ) {
179
+ // add participant
180
+ request ( url )
181
+ . post ( '/challenges/' + challengeId + '/participants' )
182
+ . send ( sampleData . participantData )
183
+ . end ( function ( err , res ) {
184
+ // verify response
185
+ should . not . exist ( err ) ;
186
+ participantId = res . body . id ;
187
+ callback ( ) ;
188
+ } ) ;
189
+ } , function ( callback ) {
190
+ // add requirement
191
+ request ( url )
192
+ . post ( '/challenges/' + challengeId + '/requirements' )
193
+ . send ( sampleData . requirementData )
194
+ . end ( function ( err , res ) {
195
+ // verify response
196
+ should . not . exist ( err ) ;
197
+ requirementId = res . body . id ;
198
+ callback ( ) ;
199
+ } ) ;
200
+ } , function ( callback ) {
201
+ // add scorecard
202
+ request ( url )
203
+ . post ( '/challenges/' + challengeId + '/scorecards/' )
204
+ . send ( sampleData . scorecardData )
205
+ . end ( function ( err , res ) {
206
+ // verify response
207
+ should . not . exist ( err ) ;
208
+ scorecardId = res . body . id ;
209
+ callback ( ) ;
210
+ } ) ;
211
+ } , function ( callback ) {
212
+ // add scorecard item
213
+ request ( url )
214
+ . post ( '/challenges/' + challengeId + '/scorecards/' + scorecardId + '/scorecardItems' )
215
+ . send ( sampleData . scorecardItemData )
216
+ . end ( function ( err , res ) {
217
+ // verify response
218
+ should . not . exist ( err ) ;
219
+ scorecardItemId = res . body . id ;
220
+ callback ( ) ;
221
+ } ) ;
222
+ } , function ( callback ) {
223
+ // add submission
224
+ request ( url )
225
+ . post ( '/challenges/' + challengeId + '/submissions' )
226
+ . send ( sampleData . submissionData )
227
+ . end ( function ( err , res ) {
228
+ // verify response
229
+ should . not . exist ( err ) ;
230
+ submissionId = res . body . id ;
231
+ callback ( ) ;
232
+ } ) ;
233
+ } , function ( callback ) {
234
+ // add file to submission
235
+ request ( url )
236
+ . post ( '/challenges/' + challengeId + '/submissions/' + submissionId + '/files' )
237
+ . send ( sampleData . challengeFileData )
238
+ . end ( function ( err , res ) {
239
+ // verify response
240
+ should . not . exist ( err ) ;
241
+ submissionFileId = res . body . id ;
242
+ callback ( ) ;
243
+ } ) ;
244
+ } ] , function ( ) {
245
+ var replacementMap = {
246
+ challengeId : challengeId ,
247
+ fileId : {
248
+ '/challenges/{challengeId}/files/' : challengeFileId ,
249
+ '/challenges/{challengeId}/submissions/{submissionId}/files/' : submissionFileId
250
+ } ,
251
+ participantId : participantId ,
252
+ requirementId : requirementId ,
253
+ scorecardId : scorecardId ,
254
+ scorecardItemId : scorecardItemId ,
255
+ submissionId : submissionId
256
+ } ;
257
+ require ( './../swaggerTestHelper' ) . validateGetRequests ( url , __dirname + '/../../api/swagger/swagger.yaml' , replacementMap , done ) ;
258
+ } ) ;
259
+ } ) ;
260
+
152
261
} ) ;
153
262
154
263
@@ -417,14 +526,7 @@ describe('Challenges Controller', function() {
417
526
describe ( 'Files API' , function ( ) {
418
527
var fileId ;
419
528
beforeEach ( function ( done ) {
420
- reqData = {
421
- title : 'File Title' ,
422
- filePath : '/uploads' ,
423
- size : 123 ,
424
- fileName : 'my-submission.zip' ,
425
- storageLocation : 'local' ,
426
- challengeId : 111
427
- } ;
529
+ reqData = _ . clone ( sampleData . challengeFileData , true ) ;
428
530
done ( ) ;
429
531
} ) ;
430
532
@@ -532,11 +634,7 @@ describe('Challenges Controller', function() {
532
634
describe ( 'Participants API' , function ( ) {
533
635
var participantId ;
534
636
beforeEach ( function ( done ) {
535
- reqData = {
536
- role : 'submitter' ,
537
- challengeId : 111 ,
538
- userId : 222
539
- } ;
637
+ reqData = _ . clone ( sampleData . participantData , true ) ;
540
638
done ( ) ;
541
639
} ) ;
542
640
@@ -643,10 +741,7 @@ describe('Challenges Controller', function() {
643
741
describe ( 'Submissions API' , function ( ) {
644
742
var submissionId ;
645
743
beforeEach ( function ( done ) {
646
- reqData = {
647
- challengeId : 111 ,
648
- submitterId : 222
649
- } ;
744
+ reqData = _ . clone ( sampleData . submissionData , true ) ;
650
745
done ( ) ;
651
746
} ) ;
652
747
0 commit comments