Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit ed81d85

Browse files
author
fireice.topcoder
committed
fix empty components paramter case
1 parent 29f032c commit ed81d85

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

actions/srmRoundComponentsAndTerms.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function checkDefinedNonNegativeInteger(value, name, error, helper) {
5959
* @param callback the callback method
6060
*/
6161
function checkComponents(api, dbConnectionMap, components, callback) {
62-
var helper = api.helper, error = helper.checkArray(components, "components", false), existingComponentDivisionIds = [];
62+
var helper = api.helper, error = helper.checkArray(components, "components", true), existingComponentDivisionIds = [];
6363
if (error) {
6464
callback(error);
6565
return;
@@ -202,7 +202,7 @@ var setRoundComponents = function (api, connection, dbConnectionMap, next) {
202202
var helper = api.helper,
203203
sqlParams = {},
204204
roundId = Number(connection.params.roundId),
205-
components = connection.params.components;
205+
components = connection.params.components || [];
206206

207207
async.waterfall([
208208
function (cb) {
@@ -348,8 +348,8 @@ exports.setRoundComponents = {
348348
name: "setRoundComponents",
349349
description: "Set Round Components",
350350
inputs: {
351-
required: ['roundId', 'components'],
352-
optional: []
351+
required: ['roundId'],
352+
optional: ['components']
353353
},
354354
blockedConnectionTypes: [],
355355
outputExample: {},

test/test.srmRoundComponentsAndTerms.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ describe('SRM Round Components And Terms APIs', function () {
345345
});
346346

347347
describe('Valid test', function () {
348+
it("Valid set components.", function(done) {
349+
var validRequest = {};
350+
createPostRequest("/v2/data/srm/rounds/13673/components", 'heffan').expect(200).send(validRequest).end(function (err, res) {
351+
if (err) {
352+
done(err);
353+
return;
354+
}
355+
assert.equal(res.body.success, true, "Invalid response detail");
356+
var sql = "* from round_component where round_id = 13673 order by component_id";
357+
testHelper.runSqlSelectQuery(sql, "informixoltp", function (err, result) {
358+
if (err) {
359+
done(err);
360+
return;
361+
}
362+
assert.equal(result.length, 0, "All components should be removed!");
363+
});
364+
done();
365+
});
366+
});
367+
348368
it("Valid set components.", function (done) {
349369
var validRequest = {"components": [{"componentId": 2020, "points": 250, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
350370
{"componentId": 2021, "points": 500, "divisionId": 2, "difficultyId": 2, "openOrder": 1, "submitOrder": 1}]};

0 commit comments

Comments
 (0)