From e60992fc1c3ce4ed4db6688f1b4bc5eca193fec6 Mon Sep 17 00:00:00 2001 From: bugbuka Date: Tue, 8 Apr 2014 11:33:16 +0800 Subject: [PATCH] Module Assembly - TopCoder NodeJS Unregister Challenge API --- actions/challengeRegistration.js | 51 +--- actions/challengeUnregistration.js | 246 +++++++++++++++ apiary.apib | 128 ++++++++ initializers/challengeHelper.js | 57 +++- package.json | 2 +- queries/challenge_unregistration_validations | 19 ++ .../challenge_unregistration_validations.json | 5 + queries/delete_challenge_resources | 3 + queries/delete_challenge_resources.json | 5 + queries/delete_challenge_result | 2 + queries/delete_challenge_result.json | 5 + queries/get_challenge_forum | 8 + queries/get_challenge_forum.json | 5 + queries/get_user_challenge_resource | 13 + queries/get_user_challenge_resource.json | 5 + routes.js | 7 +- .../common_oltp__clean | 11 + .../common_oltp__clean.json | 5 + .../common_oltp__clean.sql | 11 + .../common_oltp__create_sequence.sql | 3 + .../common_oltp__insert_test_data | 59 ++++ .../common_oltp__insert_test_data.json | 5 + .../common_oltp__insert_test_data.sql | 49 +++ .../informixoltp__clean | 1 + .../informixoltp__insert_test_data | 2 + test/sqls/challengeUnregistration/jive__clean | 4 + .../challengeUnregistration/jive__clean.json | 5 + .../challengeUnregistration/jive__clean.sql | 4 + .../jive__insert_test_data | 15 + .../jive__insert_test_data.json | 5 + .../jive__insert_test_data.sql | 4 + .../jive__select_jiveuserperm | 1 + .../jive__select_jiveuserperm.json | 5 + .../tcs_catalog__clean | 21 ++ .../tcs_catalog__clean.json | 5 + .../tcs_catalog__clean.sql | 21 ++ .../tcs_catalog__insert_test_data | 84 +++++ .../tcs_catalog__insert_test_data.json | 5 + .../tcs_catalog__insert_test_data.sql | 40 +++ .../tcs_catalog__select_component_inquiry | 1 + ...tcs_catalog__select_component_inquiry.json | 5 + .../tcs_catalog__select_project_result | 1 + .../tcs_catalog__select_project_result.json | 5 + ...elect_software_challenge_component_inquiry | 1 + ..._software_challenge_component_inquiry.json | 5 + ...atalog__select_software_challenge_resource | 1 + ...g__select_software_challenge_resource.json | 5 + ...g__select_software_challenge_resource_info | 3 + ...lect_software_challenge_resource_info.json | 5 + ..._catalog__select_studio_challenge_resource | 1 + ...log__select_studio_challenge_resource.json | 5 + ...log__select_studio_challenge_resource_info | 4 + ...select_studio_challenge_resource_info.json | 5 + test/test.challengeUnregistration.js | 287 ++++++++++++++++++ 54 files changed, 1211 insertions(+), 49 deletions(-) create mode 100755 actions/challengeUnregistration.js create mode 100755 queries/challenge_unregistration_validations create mode 100755 queries/challenge_unregistration_validations.json create mode 100755 queries/delete_challenge_resources create mode 100755 queries/delete_challenge_resources.json create mode 100755 queries/delete_challenge_result create mode 100755 queries/delete_challenge_result.json create mode 100755 queries/get_challenge_forum create mode 100755 queries/get_challenge_forum.json create mode 100755 queries/get_user_challenge_resource create mode 100755 queries/get_user_challenge_resource.json create mode 100755 test/sqls/challengeUnregistration/common_oltp__clean create mode 100755 test/sqls/challengeUnregistration/common_oltp__clean.json create mode 100755 test/sqls/challengeUnregistration/common_oltp__clean.sql create mode 100755 test/sqls/challengeUnregistration/common_oltp__create_sequence.sql create mode 100755 test/sqls/challengeUnregistration/common_oltp__insert_test_data create mode 100755 test/sqls/challengeUnregistration/common_oltp__insert_test_data.json create mode 100755 test/sqls/challengeUnregistration/common_oltp__insert_test_data.sql create mode 100755 test/sqls/challengeUnregistration/informixoltp__clean create mode 100755 test/sqls/challengeUnregistration/informixoltp__insert_test_data create mode 100755 test/sqls/challengeUnregistration/jive__clean create mode 100755 test/sqls/challengeUnregistration/jive__clean.json create mode 100755 test/sqls/challengeUnregistration/jive__clean.sql create mode 100755 test/sqls/challengeUnregistration/jive__insert_test_data create mode 100755 test/sqls/challengeUnregistration/jive__insert_test_data.json create mode 100755 test/sqls/challengeUnregistration/jive__insert_test_data.sql create mode 100755 test/sqls/challengeUnregistration/jive__select_jiveuserperm create mode 100755 test/sqls/challengeUnregistration/jive__select_jiveuserperm.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__clean create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__clean.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__clean.sql create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__insert_test_data create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.sql create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_project_result create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_project_result.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource.json create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info create mode 100755 test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info.json create mode 100755 test/test.challengeUnregistration.js diff --git a/actions/challengeRegistration.js b/actions/challengeRegistration.js index 9b4027dec..f708ab4f0 100644 --- a/actions/challengeRegistration.js +++ b/actions/challengeRegistration.js @@ -3,14 +3,17 @@ * * The APIs to register a challenge (studio category or software category) for the current logged-in user. * - * @version 1.2 - * @author ecnu_haozi, xjtufreeman, TCSASSEMBLER + * @version 1.3 + * @author ecnu_haozi, xjtufreeman, bugbuka * * changes in 1.1: * Combine Challenge Registration API(BUGR-11058) * * changes in 1.2: * Integrate the forums operation(Module Assembly - Integrating Forums Wrapper with Challenge Registration API) + * + * changes in 1.3: + * move common function getForumWrapper, aduitResourceAddition to challengeHelper.js */ "use strict"; @@ -26,25 +29,6 @@ var ForbiddenError = require('../errors/ForbiddenError'); */ var forumWrapper = null; -/** - * Get forum wrapper. It is initialized only once. - * @param {Object} api The api object that is used to access the infrastructure. - * @param {Function} callback the callback function - */ -var getForumWrapper = function (api, callback) { - if (forumWrapper) { - callback(null, forumWrapper); - } else { - try { - forumWrapper = new ForumWrapper(api.config.general.devForumJNDI); - callback(null, forumWrapper); - } catch (ex) { - api.log('Failed to connect to forum: ' + ex + " " + (ex.stack || ''), 'error'); - callback(new Error('Failed to connect to forum')); - } - } -}; - //constants var DESIGN_PROJECT_TYPE = 1, DEVELOPMENT_PROJECT_TYPE = 2, @@ -162,27 +146,6 @@ var persistResource = function (api, resourceId, userId, challengeId, dbConnecti }); }; -/** - * Audit the challenge registration on table 'tcs_catalog.project_user_audit'. - * - * @param {Object} api The api object that is used to access the infrastructure. - * @param {Number} userId The current logged-in user's id. - * @param {Number} challengeId The id of the challenge to register. - * @param {Object} dbConnectionMap The database connection map for the current request. - * @param {Function} next The callback to be called after this function is done. - */ -var aduitResourceAddition = function (api, userId, challengeId, dbConnectionMap, next) { - api.dataAccess.executeQuery("audit_challenge_registration", { - projectId: challengeId, - resourceUserId: userId, - resourceRoleId: SUBMITTER_RESOURCE_ROLE_ID, - auditActionTypeId: PROJECT_USER_AUDIT_CREATE_TYPE, - actionUserId: userId - }, - dbConnectionMap, - next); -}; - /** * Check if the rating suit for software category contests. * The code logic is duplicated from server-side java code. @@ -282,7 +245,7 @@ var projectTrack = function (api, userId, challengeId, componentInfo, dbConnecti function (resourceId, callback) { async.parallel([ function (cb) { - aduitResourceAddition(api, userId, challengeId, dbConnectionMap, cb); + api.challengeHelper.aduitResourceAddition(api, userId, challengeId, SUBMITTER_RESOURCE_ROLE_ID, PROJECT_USER_AUDIT_CREATE_TYPE, dbConnectionMap, cb); }, function (cb) { prepareProjectResult( @@ -487,7 +450,7 @@ var grantForumAccess = function (api, userId, activeForumCategoryId, next) { api.log('start to grant user ' + userId + ' forum category ' + activeForumCategoryId + ' access.'); async.waterfall([ function (cb) { - getForumWrapper(api, cb); + api.challengeHelper.getForumWrapper(api, cb); }, function (forumWrapper, cb) { forumWrapper.assignRole(userId, "Software_Users_" + activeForumCategoryId, function (err) { if (err) { diff --git a/actions/challengeUnregistration.js b/actions/challengeUnregistration.js new file mode 100755 index 000000000..5c9320b05 --- /dev/null +++ b/actions/challengeUnregistration.js @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2014 TopCoder Inc., All Rights Reserved. + * + * The APIs to un-register a challenge (studio category or software category) for the current logged-in user. + * + * @version 1.0 + * @author bugbuka + */ +"use strict"; + +var async = require('async'); +var _ = require('underscore'); +var moment = require('moment'); +var ForumWrapper = require("forum-connector").ForumWrapper; +var UnauthorizedError = require('../errors/UnauthorizedError'); +var NotFoundError = require('../errors/NotFoundError'); +var ForbiddenError = require('../errors/ForbiddenError'); + +//constants +var SUBMITTER_RESOURCE_ROLE_ID = 1, + PROJECT_USER_AUDIT_DELETE_TYPE = 2; + +/** + * Checks if specified challenge category ID implies the presence of records in project_result and component_inquiry + * tables for challenge registrants. + * + * @param {Number} categoryId - ID for challenge category. + * @returns {boolean} true if above records are required; false otherwise. + * @since 1.3 + */ +function isProjectResultCategory(categoryId) { + return (categoryId === 1 // Component Design + || categoryId === 2 // Component Development + || categoryId === 5 // Component Testing + || categoryId === 6 // Application Specification + || categoryId === 7 // Application Architecture + || categoryId === 9 // Bug Hunt + || categoryId === 13 // Test Scenarios + || categoryId === 26 // Test Suites + || categoryId === 14 // Application Assembly + || categoryId === 23 // Application Conceptualization + || categoryId === 19 // UI Prototype + || categoryId === 24 // RIA Build + || categoryId === 25 // RIA Component + || categoryId === 29 // Copilot Posting + || categoryId === 35 // Content Creation + || categoryId === 36 // Reporting + || categoryId === 38 // First2Finish + || categoryId === 39 // Code + ); +} + +/** + * Remove forum permissions. It is initialized only once. + * + * @param {Object} api The api object that is used to access the infrastructure. + * @param {Number} userId The current logged-in user's id. + * @param {Number} forumCategoryId The sql params. + * @param {Function} next The callback to be called after this function is done. + */ +var removeForumPermissions = function (api, userId, forumCategoryId, next) { + + if (api.config.general.grantForumAccess !== true || forumCategoryId === 0) { + next(); + return; + } + + if (forumCategoryId === null) { + api.log('Could not find forum category ' + forumCategoryId, 'error'); + next(new Error('Could not find forum category ' + forumCategoryId)); + return; + } + + api.log('start to remove user ' + userId + ' from forum category ' + forumCategoryId + '.'); + async.waterfall([ + function (cb) { + api.challengeHelper.getForumWrapper(api, cb); + }, function (forumWrapper, cb) { + forumWrapper.removeRole(userId, "Software_Users_" + forumCategoryId, cb); + }, function (forumWrapper, cb) { + forumWrapper.removeRole(userId, "Software_Moderators_" + forumCategoryId, cb); + }, function (forumWrapper, cb) { + forumWrapper.removeUserPermission(userId, forumCategoryId, cb); + }, function (forumWrapper, cb) { + forumWrapper.deleteCategoryWatch(userId, forumCategoryId, cb); + } + ], function (err) { + if (err) { + next(err); + return; + } + next(); + }); +}; + +/** + * Unregister a development (software) challenge for the current logged-in user. + * + * @param {Object} api The api object that is used to access the infrastructure. + * @param {Number} userId The current logged-in user's id. + * @param {Object} sqlParams The sql params. + * @param {Object} unregisterInfo The data used to do unregistration. + * @param {Object} dbConnectionMap The database connection map for the current request. + * @param {Function} next The callback to be called after this function is done. + */ +var unregisterChallenge = function (api, userId, sqlParams, unregisterInfo, dbConnectionMap, next) { + async.series([ + function (cb) { + if (sqlParams.isStudio || isProjectResultCategory(sqlParams.categoryId)) { + api.dataAccess.executeQuery("delete_challenge_result", sqlParams, dbConnectionMap, cb); + } else { + cb(); + } + + }, function (cb) { + + if (_.size(unregisterInfo.userChallengeResources) < 1) { + api.log("Could not find user challenge resource", 'error'); + cb(new Error('Could not find user challenge resource')); + return; + } + var submitterRoleResourceId = _.filter(unregisterInfo.userChallengeResources, function (resource) { + return resource.resource_role_id === SUBMITTER_RESOURCE_ROLE_ID; + })[0].resource_id; + + api.dataAccess.executeQuery("delete_challenge_resources", {resourceId : submitterRoleResourceId}, dbConnectionMap, cb); + }, function (cb) { + + api.challengeHelper.aduitResourceAddition(api, userId, sqlParams.challengeId, SUBMITTER_RESOURCE_ROLE_ID, PROJECT_USER_AUDIT_DELETE_TYPE, dbConnectionMap, cb); + }, function (cb) { + + if (_.size(unregisterInfo.userChallengeResources) === 1 && unregisterInfo.userChallengeResources[0].resource_role_id === SUBMITTER_RESOURCE_ROLE_ID) { // Only remove forum permissions if the user has no other roles left. + if (unregisterInfo.challengeForum.length === 0) { + api.log("Could not find user challenge forum", 'error'); + cb(new Error('Could not find user challenge forum')); + return; + } + var forumCategoryId = parseInt(unregisterInfo.challengeForum[0].forum_category_id, 10); + removeForumPermissions(api, userId, forumCategoryId, cb); + } + cb(); + } + ], next); +}; + +/** + * The action to unregister a challenge for the current logged-in user. + * + * @param {Object} api The api object that is used to access the infrastructure. + * @param {Object} connection The connection for the current request. + * @param {Function} next The callback to be called after this function is done. + */ +var unregisterChallengeAction = function (api, connection, next) { + + var helper = api.helper, + sqlParams = {}, + userId = connection.caller.userId, + challengeId = Number(connection.params.challengeId), + + execQuery = function (name) { + return function (cbx) { + api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx); + }; + }; + + async.waterfall([ + function (cb) { + + //Simple validations of the incoming parameters + var error = helper.checkPositiveInteger(challengeId, 'challengeId') || + helper.checkMaxInt(challengeId, 'challengeId') || + helper.checkMember(connection, 'You don\'t have the authority to access this. Please login.'); + + if (error) { + cb(error); + return; + } + + //Check if the user passes validations for joining the challenge + sqlParams.userId = userId; + sqlParams.challengeId = challengeId; + + api.dataAccess.executeQuery("challenge_unregistration_validations", sqlParams, connection.dbConnectionMap, cb); + }, function (rows, cb) { + if (rows.length === 0) { + + cb(new NotFoundError('No such challenge exists.')); + } else if (!rows[0].reg_open) { + + cb(new ForbiddenError('You cannot unregister since registration phase is closed.')); + } else if (!rows[0].user_has_submitter_resource_role) { + + cb(new ForbiddenError('You are not registered for this challenge.')); + } + + sqlParams.categoryId = rows[0].category_id; + sqlParams.isStudio = rows[0].is_studio; + + async.series({ + userChallengeResources: execQuery('get_user_challenge_resource'), + challengeForum: execQuery('get_challenge_forum') + }, cb); + + }, + function (result, cb) { + unregisterChallenge(api, userId, sqlParams, result, connection.dbConnectionMap, cb); + } + ], function (err) { + if (err) { + api.helper.handleError(api, connection, err); + } else { + api.log("unregister the challenge succeeded.", 'debug'); + connection.response = {message : "ok"}; + } + next(connection, true); + }); + +}; + +/** + * The API to unregister a challenge for the current logged-in user. + */ +exports.unregisterChallenge = { + name: "unregisterChallenge", + description: "unregisterChallenge", + inputs: { + required: ["challengeId"], + optional: [] + }, + blockedConnectionTypes: [], + outputExample: {}, + version: 'v2', + cacheEnabled : false, + transaction: 'write', + databases: ["tcs_catalog"], + run: function (api, connection, next) { + if (connection.dbConnectionMap) { + api.log("Execute unregisterChallenge#run", 'debug'); + unregisterChallengeAction(api, connection, next); + } else { + api.helper.handleNoConnection(api, connection, next); + } + } +}; + + diff --git a/apiary.apib b/apiary.apib index 59647c445..04d1f52f0 100644 --- a/apiary.apib +++ b/apiary.apib @@ -5647,6 +5647,134 @@ Register a new user. "description":"Servers are up but overloaded. Try again later." } +## Unregister for a software/studio challenge [/challenges/{challengeId}/unregister] +### Unregister for a software/studio challenge [POST] + ++ Parameters + + challengeId (required, number, `1234567`) ... The challenge for which to Unregister + ++ Request + + + Headers + + Authorization : Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZHwxMzI0NTYiLCJleHAiOjEzOTM3MDM1NzEsImF1ZCI6InRvcGNvZGVyIiwiaWF0IjoxMzkzNjQzNTcxfQ.F2iohKp2nwjQeGqrBD1wn42GJUD0r28aGjhDle7KujA + ++ Response 200 (application/json) + + { + "message":"ok" + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be less or equal to 2147483647." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be number." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be positive." + } + ++ Response 401 (application/json) + + { + "name":"Unauthorized", + "value":"401", + "description":"You don\'t have the authority to access this. Please login." + } + ++ Response 403 (application/json) + + { + "name":"Forbidden", + "value":"403", + "description":"You cannot unregister since registration phase is closed." + } + ++ Response 403 (application/json) + + { + "name":"Forbidden", + "value":"403", + "description":"You are not registered for this challenge." + } + ++ Response 404 (application/json) + + { + "name":"Not Found", + "value":"404", + "description":"No such challenge exists." + } + ++ Response 500 (application/json) + + { + "name":"Internal Server Error", + "value":"500", + "description":"Unknown server error. Please contact support." + } + ++ Response 500 (application/json) + + { + "name": "Internal Server Error", + "value": 500, + "description": "Something is broken. Please contact support.", + "details": "Failed to connect to forum" + } + ++ Response 500 (application/json) + + { + "name": "Internal Server Error", + "value": 500, + "description": "Something is broken. Please contact support.", + "details": "Could not find user challenge resource" + } + + ++ Response 500 (application/json) + + { + "name": "Internal Server Error", + "value": 500, + "description": "Something is broken. Please contact support.", + "details": "Could not find user challenge forum" + } + + ++ Response 500 (application/json) + + { + "name": "Internal Server Error", + "value": 500, + "description": "Something is broken. Please contact support.", + "details": "Could not find forum category 3" + } + ++ Response 503 (application/json) + + { + "name":"Service Unavailable", + "value":"503", + "description":"Servers are up but overloaded. Try again later." + } + # Group Terms Of Use API ## View terms of use [/terms/detail/{termsOfUseId}] ### View terms of use by id [GET] diff --git a/initializers/challengeHelper.js b/initializers/challengeHelper.js index 95d2767d3..8545cb5d9 100644 --- a/initializers/challengeHelper.js +++ b/initializers/challengeHelper.js @@ -1,9 +1,12 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.0 - * @author ecnu_haozi + * @version 1.1 + * @author ecnu_haozi, bugbuka * Refactor common code out from challenge.js. + * + * changes in 1.1: + * add common function getForumWrapper, aduitResourceAddition */ "use strict"; @@ -14,12 +17,18 @@ var BadRequestError = require('../errors/BadRequestError'); var UnauthorizedError = require('../errors/UnauthorizedError'); var NotFoundError = require('../errors/NotFoundError'); var ForbiddenError = require('../errors/ForbiddenError'); +var ForumWrapper = require("forum-connector").ForumWrapper; /** * This copilot posting project type id */ var COPILOT_POSTING_PROJECT_TYPE = 29; +/** + * The forum wrapper instance + */ +var forumWrapper = null; + /** * Expose the "idGenerator" utility. * @@ -29,6 +38,50 @@ var COPILOT_POSTING_PROJECT_TYPE = 29; exports.challengeHelper = function (api, next) { api.challengeHelper = { + /** + * Get forum wrapper. It is initialized only once. + * @param {Object} api The api object that is used to access the infrastructure. + * @param {Function} callback the callback function + * @since 1.1 + */ + getForumWrapper : function (api, callback) { + if (forumWrapper) { + callback(null, forumWrapper); + } else { + try { + forumWrapper = new ForumWrapper(api.config.general.devForumJNDI); + callback(null, forumWrapper); + } catch (ex) { + api.log('Failed to connect to forum: ' + ex + " " + (ex.stack || ''), 'error'); + callback(new Error('Failed to connect to forum')); + } + } + }, + + /** + * Audit the challenge registration on table 'tcs_catalog.project_user_audit'. + * + * @param {Object} api The api object that is used to access the infrastructure. + * @param {Number} userId The current logged-in user's id. + * @param {Number} challengeId The id of the challenge to register. + * @param {Number} submitterResourceRoleId The id of the submitter resource role. + * @param {Number} auditActionTypeId The id of the audit action type. + * @param {Object} dbConnectionMap The database connection map for the current request. + * @param {Function} next The callback to be called after this function is done. + * @since 1.1 + */ + aduitResourceAddition : function (api, userId, challengeId, submitterResourceRoleId, auditActionTypeId, dbConnectionMap, next) { + api.dataAccess.executeQuery("audit_challenge_registration", { + projectId: challengeId, + resourceUserId: userId, + resourceRoleId: submitterResourceRoleId, + auditActionTypeId: auditActionTypeId, + actionUserId: userId + }, + dbConnectionMap, + next); + }, + /** * Gets the challenge terms for the current user given the challenge id and an optional role. * diff --git a/package.json b/package.json index b69616314..d84896042 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "bignum": "0.6.2", "java": "0.2.9", "informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#ae513d6c27d14acaef52092165831dcf23fc83dd", - "forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#9066f062e4e2a97b3de89e047a3b022443e7dd83", + "forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#98d0db07348a0950924b9ec967bf83769346b700", "asn1": "*", "crypto": ">= 0.0.3", "jsonwebtoken": "*", diff --git a/queries/challenge_unregistration_validations b/queries/challenge_unregistration_validations new file mode 100755 index 000000000..c0e29841d --- /dev/null +++ b/queries/challenge_unregistration_validations @@ -0,0 +1,19 @@ +select distinct + p.project_id, + p.project_category_id as category_id, + (pp_reg_open.project_id IS NOT NULL) as reg_open, + (resource_role_id IS NOT NULL) as user_has_Submitter_resource_role, + CASE WHEN (p.project_studio_spec_id is NULL) THEN 0 ELSE 1 END as is_studio +from project p +-- Check if project's registration is open +left join + project_phase pp_reg_open + on p.project_id = pp_reg_open.project_id + and pp_reg_open.phase_type_id = 1 + and pp_reg_open.phase_status_id = 2 +-- Check if user has Submitter resource role +left join resource rs + on rs.project_id = p.project_id + and rs.resource_role_id = 1 +where p.project_id = @challengeId@; + diff --git a/queries/challenge_unregistration_validations.json b/queries/challenge_unregistration_validations.json new file mode 100755 index 000000000..26e53f27b --- /dev/null +++ b/queries/challenge_unregistration_validations.json @@ -0,0 +1,5 @@ +{ + "name" : "challenge_unregistration_validations", + "db" : "tcs_catalog", + "sqlfile" : "challenge_unregistration_validations" +} diff --git a/queries/delete_challenge_resources b/queries/delete_challenge_resources new file mode 100755 index 000000000..1a24a1fe8 --- /dev/null +++ b/queries/delete_challenge_resources @@ -0,0 +1,3 @@ +DELETE FROM resource_info WHERE resource_id = @resourceId@; +DELETE FROM resource_submission WHERE resource_id = @resourceId@; +DELETE FROM resource WHERE resource_id = @resourceId@; \ No newline at end of file diff --git a/queries/delete_challenge_resources.json b/queries/delete_challenge_resources.json new file mode 100755 index 000000000..feb0dc72a --- /dev/null +++ b/queries/delete_challenge_resources.json @@ -0,0 +1,5 @@ +{ + "name" : "delete_challenge_resources", + "db" : "tcs_catalog", + "sqlfile" : "delete_challenge_resources" +} \ No newline at end of file diff --git a/queries/delete_challenge_result b/queries/delete_challenge_result new file mode 100755 index 000000000..05cadc78a --- /dev/null +++ b/queries/delete_challenge_result @@ -0,0 +1,2 @@ +delete from project_result where project_id = @challengeId@ and user_id = @userId@; +delete from component_inquiry where project_id = @challengeId@ and user_id = @userId@; \ No newline at end of file diff --git a/queries/delete_challenge_result.json b/queries/delete_challenge_result.json new file mode 100755 index 000000000..dab2e2a02 --- /dev/null +++ b/queries/delete_challenge_result.json @@ -0,0 +1,5 @@ +{ + "name" : "delete_challenge_result", + "db" : "tcs_catalog", + "sqlfile" : "delete_challenge_result" +} \ No newline at end of file diff --git a/queries/get_challenge_forum b/queries/get_challenge_forum new file mode 100755 index 000000000..3eb0febdc --- /dev/null +++ b/queries/get_challenge_forum @@ -0,0 +1,8 @@ +SELECT info.project_id, + info_type.name, + info.value as forum_category_id +FROM project_info AS info + JOIN project_info_type_lu AS info_type + ON info.project_info_type_id = info_type.project_info_type_id +WHERE info.project_id IN ( @challengeId@ ) +and name = 'Developer Forum ID' \ No newline at end of file diff --git a/queries/get_challenge_forum.json b/queries/get_challenge_forum.json new file mode 100755 index 000000000..5bc8ff225 --- /dev/null +++ b/queries/get_challenge_forum.json @@ -0,0 +1,5 @@ +{ + "name" : "get_challenge_forum", + "db" : "tcs_catalog", + "sqlfile" : "get_challenge_forum" +} \ No newline at end of file diff --git a/queries/get_user_challenge_resource b/queries/get_user_challenge_resource new file mode 100755 index 000000000..2c009b357 --- /dev/null +++ b/queries/get_user_challenge_resource @@ -0,0 +1,13 @@ +SELECT DISTINCT + resource_info_type_lu.resource_info_type_id, + resource_info.value as user_id, + resource.resource_id AS resource_id, + resource_role_id + FROM resource, + resource_info, + resource_info_type_lu +WHERE resource.resource_id = resource_info.resource_id + AND resource_info.resource_info_type_id = resource_info_type_lu.resource_info_type_id + AND project_id = @challengeId@ + AND resource_info_type_lu.resource_info_type_id = 1 -- External Reference ID + AND resource_info.value = '@userId@' \ No newline at end of file diff --git a/queries/get_user_challenge_resource.json b/queries/get_user_challenge_resource.json new file mode 100755 index 000000000..9db744c64 --- /dev/null +++ b/queries/get_user_challenge_resource.json @@ -0,0 +1,5 @@ +{ +"name" : "get_user_challenge_resource", +"db" : "tcs_catalog", +"sqlfile" : "get_user_challenge_resource" +} \ No newline at end of file diff --git a/routes.js b/routes.js index c84b42907..7282d668c 100755 --- a/routes.js +++ b/routes.js @@ -1,8 +1,8 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.31 - * @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, TCSASSEMBLER + * @version 1.32 + * @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, bugbuka * Changes in 1.1: * - add routes for search challenges * Changes in 1.2: @@ -74,6 +74,8 @@ * - added route for getting marathon match challenge register info api * Changes in 1.31: * - add route for challenge rss output api. + * changes in 1.32: + * - added route for Challenge Unregistration API */ /* --------------------- @@ -231,6 +233,7 @@ exports.routes = { { path: "/:apiVersion/develop/challenges/:challengeId/submit", action: "submitForDevelopChallenge" }, { path: "/:apiVersion/design/challenges/:challengeId/submit", action: "submitForDesignChallenge" }, { path: "/:apiVersion/challenges/:challengeId/register", action: "registerChallenge" }, + { path: "/:apiVersion/challenges/:challengeId/unregister", action: "unregisterChallenge" }, { path: "/:apiVersion/auth", action: "generateJwt" }, { path: "/:apiVersion/reauth", action: "refreshJwt" }, { path: "/:apiVersion/platform/billing", action: "createBilling" }, diff --git a/test/sqls/challengeUnregistration/common_oltp__clean b/test/sqls/challengeUnregistration/common_oltp__clean new file mode 100755 index 000000000..1e0ed8835 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__clean @@ -0,0 +1,11 @@ +delete from user_social_login where user_id > 400010 and user_id < 400020; +delete from user_address_xref where address_id > 40000000 and address_id < 40000010; +delete from address where address_id > 40000000 and address_id < 40000010; +delete from project_role_terms_of_use_xref where project_id > 40000000 and project_id < 40000020; +delete from user_terms_of_use_xref where user_id > 400010 and user_id < 400020; +delete from user_status where user_id > 400010 and user_id < 400020; +delete from security_user where login_id > 400010 and login_id < 400020; +delete from email where email_id > 400010 and email_id < 400020; +delete from corona_event where user_id > 400010 and user_id < 400020; +delete from user where user_id > 400010 and user_id < 400020; + diff --git a/test/sqls/challengeUnregistration/common_oltp__clean.json b/test/sqls/challengeUnregistration/common_oltp__clean.json new file mode 100755 index 000000000..b9356c845 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__clean.json @@ -0,0 +1,5 @@ +{ + "name" : "common_oltp__clean", + "db" : "common_oltp", + "sqlfile" : "common_oltp__clean" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/common_oltp__clean.sql b/test/sqls/challengeUnregistration/common_oltp__clean.sql new file mode 100755 index 000000000..1e0ed8835 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__clean.sql @@ -0,0 +1,11 @@ +delete from user_social_login where user_id > 400010 and user_id < 400020; +delete from user_address_xref where address_id > 40000000 and address_id < 40000010; +delete from address where address_id > 40000000 and address_id < 40000010; +delete from project_role_terms_of_use_xref where project_id > 40000000 and project_id < 40000020; +delete from user_terms_of_use_xref where user_id > 400010 and user_id < 400020; +delete from user_status where user_id > 400010 and user_id < 400020; +delete from security_user where login_id > 400010 and login_id < 400020; +delete from email where email_id > 400010 and email_id < 400020; +delete from corona_event where user_id > 400010 and user_id < 400020; +delete from user where user_id > 400010 and user_id < 400020; + diff --git a/test/sqls/challengeUnregistration/common_oltp__create_sequence.sql b/test/sqls/challengeUnregistration/common_oltp__create_sequence.sql new file mode 100755 index 000000000..dfaff8892 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__create_sequence.sql @@ -0,0 +1,3 @@ +CREATE SEQUENCE SEQUENCE_COMPONNENT_INQUIRY_SEQ INCREMENT BY 1 START WITH 4000000; + +CREATE SEQUENCE SEQUENCE_RESOURCE_ID_SEQ INCREMENT BY 1 START WITH 4000000; diff --git a/test/sqls/challengeUnregistration/common_oltp__insert_test_data b/test/sqls/challengeUnregistration/common_oltp__insert_test_data new file mode 100755 index 000000000..c74b9cd22 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__insert_test_data @@ -0,0 +1,59 @@ +INSERT into user (user_id, handle, status, timezone_id) values (400011, 'normal_user_11', 'A', 143); +INSERT into user (user_id, handle, status, timezone_id) values (400012, 'normal_user_12', 'A', 143); +INSERT into user (user_id, handle, status, timezone_id) values (400013, 'normal_user_13', 'A', 143); + +INSERT INTO email(user_id,email_id,email_type_id,address,create_date,modify_date,primary_ind,status_id) VALUES (400011, 400011, 1, 'facebook.topcoder@gmail.com', CURRENT, CURRENT, 1, 1); + +INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('fb400011', 400011, 1, 'user11'); +INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('fb400012', 400012, 1, 'user12'); +INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('fb400013', 400013, 1, 'user13'); + +INSERT INTO 'informix'.address(address_id,address_type_id,address1,address2,city,state_code,zip,country_code,create_date,modify_date,address3,province) +VALUES (40000001, 2, 'address1', NULL, 'city', 'ME', '04043', '840', '2008-08-01 16:37:48.000', '2008-08-01 16:37:48.000', NULL, NULL); +INSERT INTO 'informix'.address(address_id,address_type_id,address1,address2,city,state_code,zip,country_code,create_date,modify_date,address3,province) +VALUES (40000002, 2, 'address1', NULL, 'city', 'ME', '04043', '192', '2008-08-01 16:37:48.000', '2008-08-01 16:37:48.000', NULL, NULL); + +INSERT INTO 'informix'.user_address_xref(user_id,address_id) VALUES (400012, 40000001); +INSERT INTO 'informix'.user_address_xref(user_id,address_id) VALUES (400013, 40000002); + +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 1, 20543, 1, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 1, 20493, 2, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 4, 20623, 3, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 4, 20713, 4, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 15, 20963, 5, 1); + +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 1, 20543, 1, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 1, 20493, 2, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 4, 20623, 3, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 4, 20713, 4, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 15, 20963, 5, 1); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20543); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20493); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20623); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20713); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20963); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400012, 20543); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400013, 20543); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400013, 20493); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400013, 20623); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400013, 20713); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400013, 20963); + +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20543.txt' WHERE terms_of_use_id = 20543; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20493.txt' WHERE terms_of_use_id = 20493; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20623.txt' WHERE terms_of_use_id = 20623; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20713.txt' WHERE terms_of_use_id = 20713; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20963.txt' WHERE terms_of_use_id = 20963; diff --git a/test/sqls/challengeUnregistration/common_oltp__insert_test_data.json b/test/sqls/challengeUnregistration/common_oltp__insert_test_data.json new file mode 100755 index 000000000..77f0e4d97 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__insert_test_data.json @@ -0,0 +1,5 @@ +{ + "name" : "common_oltp__insert_test_data", + "db" : "common_oltp", + "sqlfile" : "common_oltp__insert_test_data" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/common_oltp__insert_test_data.sql b/test/sqls/challengeUnregistration/common_oltp__insert_test_data.sql new file mode 100755 index 000000000..c81c695d6 --- /dev/null +++ b/test/sqls/challengeUnregistration/common_oltp__insert_test_data.sql @@ -0,0 +1,49 @@ +INSERT into user (user_id, handle, status, timezone_id) values (400011, 'normal_user_11', 'A', 143); +INSERT into user (user_id, handle, status, timezone_id) values (400012, 'normal_user_12', 'A', 143); + +INSERT INTO email(user_id,email_id,email_type_id,address,create_date,modify_date,primary_ind,status_id) VALUES (400011, 400011, 1, 'facebook.topcoder@gmail.com', CURRENT, CURRENT, 1, 1); + +INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('fb400011', 400011, 1, 'user11'); +INSERT INTO user_social_login(social_user_id, user_id, social_login_provider_id, social_user_name) VALUES ('fb400012', 400012, 1, 'user12'); + +INSERT INTO 'informix'.address(address_id,address_type_id,address1,address2,city,state_code,zip,country_code,create_date,modify_date,address3,province) +VALUES (40000001, 2, 'address1', NULL, 'city', 'ME', '04043', '840', '2008-08-01 16:37:48.000', '2008-08-01 16:37:48.000', NULL, NULL); + +INSERT INTO 'informix'.user_address_xref(user_id,address_id) VALUES (400011, 40000001); +INSERT INTO 'informix'.user_address_xref(user_id,address_id) VALUES (400012, 40000001); + +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 1, 20543, 1, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 1, 20493, 2, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 4, 20623, 3, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 4, 20713, 4, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000001, 15, 20963, 5, 1); + +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 1, 20543, 1, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 1, 20493, 2, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 4, 20623, 3, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 4, 20713, 4, 1); +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, sort_order, group_ind) +VALUES (40000002, 15, 20963, 5, 1); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20543); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20493); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20623); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20713); +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400011, 20963); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id) VALUES (400012, 20543); + +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20543.txt' WHERE terms_of_use_id = 20543; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20493.txt' WHERE terms_of_use_id = 20493; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20623.txt' WHERE terms_of_use_id = 20623; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20713.txt' WHERE terms_of_use_id = 20713; +UPDATE terms_of_use SET url = 'http://topcoder.com/terms/20963.txt' WHERE terms_of_use_id = 20963; diff --git a/test/sqls/challengeUnregistration/informixoltp__clean b/test/sqls/challengeUnregistration/informixoltp__clean new file mode 100755 index 000000000..0fbeadc36 --- /dev/null +++ b/test/sqls/challengeUnregistration/informixoltp__clean @@ -0,0 +1 @@ +DELETE FROM coder WHERE coder_id = 400013; diff --git a/test/sqls/challengeUnregistration/informixoltp__insert_test_data b/test/sqls/challengeUnregistration/informixoltp__insert_test_data new file mode 100755 index 000000000..21adb5061 --- /dev/null +++ b/test/sqls/challengeUnregistration/informixoltp__insert_test_data @@ -0,0 +1,2 @@ +INSERT INTO 'informixoltp':coder(coder_id, quote, coder_type_id, comp_country_code, display_quote, quote_location, quote_color, display_banner, banner_style) +VALUES(400013, '', 2, '192', 1, 'md', '#000000', 1, 'bannerStyle1'); \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__clean b/test/sqls/challengeUnregistration/jive__clean new file mode 100755 index 000000000..4824e26ac --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__clean @@ -0,0 +1,4 @@ +delete from jiveuserperm where userid = 400011; +delete from jivegroupuser where userid > 400010 and userid < 400020; +delete from jivegroup where groupid >= 101 and groupid <= 104; +delete from jivecategory where categoryid >= 1001 and categoryid <= 1004; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__clean.json b/test/sqls/challengeUnregistration/jive__clean.json new file mode 100755 index 000000000..a70d93c50 --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__clean.json @@ -0,0 +1,5 @@ +{ + "name" : "jive__clean", + "db" : "jive", + "sqlfile" : "jive__clean" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__clean.sql b/test/sqls/challengeUnregistration/jive__clean.sql new file mode 100755 index 000000000..4824e26ac --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__clean.sql @@ -0,0 +1,4 @@ +delete from jiveuserperm where userid = 400011; +delete from jivegroupuser where userid > 400010 and userid < 400020; +delete from jivegroup where groupid >= 101 and groupid <= 104; +delete from jivecategory where categoryid >= 1001 and categoryid <= 1004; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__insert_test_data b/test/sqls/challengeUnregistration/jive__insert_test_data new file mode 100755 index 000000000..0f110cbd7 --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__insert_test_data @@ -0,0 +1,15 @@ +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (101, 'Software_Users_1001', 'contest for autotest 1', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (102, 'Software_Moderators_1001', 'contest for autotest 1', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (103, 'Software_Users_1002', 'contest for autotest 2', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (104, 'Software_Moderators_1002', 'contest for autotest 2', 1395226951776, 1395226951776); + +INSERT INTO jivegroupuser (groupid, userid, administrator) VALUES (1001,400011, 0); + +INSERT INTO jivecategory (categoryid, name, description, creationdate, modificationdate, lft, rgt) VALUES (1001, 'test_1001', 'test_1001', 1396014756004, 1396014756004, 1001, 1003); + +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 0); +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 2); +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 1); +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 6); +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 4); +INSERT INTO jiveuserperm (objecttype, objectid, userid, permissiontype, permission) VALUES (14, 1001, 400011, 1, 10); diff --git a/test/sqls/challengeUnregistration/jive__insert_test_data.json b/test/sqls/challengeUnregistration/jive__insert_test_data.json new file mode 100755 index 000000000..ed8c2f9ba --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__insert_test_data.json @@ -0,0 +1,5 @@ +{ + "name" : "jive__insert_test_data", + "db" : "jive", + "sqlfile" : "jive__insert_test_data" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__insert_test_data.sql b/test/sqls/challengeUnregistration/jive__insert_test_data.sql new file mode 100755 index 000000000..89049c2d7 --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__insert_test_data.sql @@ -0,0 +1,4 @@ +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (101, 'Software_Users_1001', 'contest for autotest 1', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (102, 'Software_Moderators_1001', 'contest for autotest 1', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (103, 'Software_Users_1002', 'contest for autotest 2', 1395226951776, 1395226951776); +INSERT INTO jivegroup(groupid, name, description, creationdate, modificationdate) VALUES (104, 'Software_Moderators_1002', 'contest for autotest 2', 1395226951776, 1395226951776); diff --git a/test/sqls/challengeUnregistration/jive__select_jiveuserperm b/test/sqls/challengeUnregistration/jive__select_jiveuserperm new file mode 100755 index 000000000..68027c47f --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__select_jiveuserperm @@ -0,0 +1 @@ +* from jiveuserperm where userid = 400011; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/jive__select_jiveuserperm.json b/test/sqls/challengeUnregistration/jive__select_jiveuserperm.json new file mode 100755 index 000000000..d03eccdf0 --- /dev/null +++ b/test/sqls/challengeUnregistration/jive__select_jiveuserperm.json @@ -0,0 +1,5 @@ +{ + "name" : "jive__select_jiveuserperm", + "db" : "jive", + "sqlfile" : "jive__select_jiveuserperm" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__clean b/test/sqls/challengeUnregistration/tcs_catalog__clean new file mode 100755 index 000000000..ea45daf34 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__clean @@ -0,0 +1,21 @@ +delete from resource_info where resource_id in (select resource_id from resource where project_id > 40000000 and project_id < 40000020); +delete from component_inquiry where component_inquiry_id > 80000001 and component_inquiry_id < 80000020; +delete from project_result where user_id = 400011; +delete from resource where project_id > 40000000 and project_id < 40000020; +delete from project_result where project_id > 40000000 and project_id < 40000020; +delete from project_user_audit where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; + +delete from project_info where project_id > 40000000 and project_id < 40000020; +delete from project_phase where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; +delete from project where project_id > 40000000 and project_id < 40000020; +delete from comp_version_dates_history where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_jive_category_xref where jive_category_id >= 1001 and jive_category_id <= 1003; +delete from comp_versions where component_id > 40000000 and component_id < 40000020; +delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_catalog where component_id > 40000000 and component_id < 40000020; +delete from user_rating where user_id = 400011; +delete from user_reliability where user_id = 400011; +delete from project_studio_specification where project_studio_spec_id = 1001; +delete from copilot_profile where copilot_profile_id = 400011; diff --git a/test/sqls/challengeUnregistration/tcs_catalog__clean.json b/test/sqls/challengeUnregistration/tcs_catalog__clean.json new file mode 100755 index 000000000..fc515d318 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__clean.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__clean", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__clean" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__clean.sql b/test/sqls/challengeUnregistration/tcs_catalog__clean.sql new file mode 100755 index 000000000..ea45daf34 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__clean.sql @@ -0,0 +1,21 @@ +delete from resource_info where resource_id in (select resource_id from resource where project_id > 40000000 and project_id < 40000020); +delete from component_inquiry where component_inquiry_id > 80000001 and component_inquiry_id < 80000020; +delete from project_result where user_id = 400011; +delete from resource where project_id > 40000000 and project_id < 40000020; +delete from project_result where project_id > 40000000 and project_id < 40000020; +delete from project_user_audit where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; + +delete from project_info where project_id > 40000000 and project_id < 40000020; +delete from project_phase where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; +delete from project where project_id > 40000000 and project_id < 40000020; +delete from comp_version_dates_history where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_jive_category_xref where jive_category_id >= 1001 and jive_category_id <= 1003; +delete from comp_versions where component_id > 40000000 and component_id < 40000020; +delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_catalog where component_id > 40000000 and component_id < 40000020; +delete from user_rating where user_id = 400011; +delete from user_reliability where user_id = 400011; +delete from project_studio_specification where project_studio_spec_id = 1001; +delete from copilot_profile where copilot_profile_id = 400011; diff --git a/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data new file mode 100755 index 000000000..95c6252c2 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data @@ -0,0 +1,84 @@ +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 4, '1001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_jive_category_xref (comp_vers_id, jive_category_id) VALUES ('40000001', 1001); + +INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT); + +INSERT INTO resource (resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES (40000001, 1, 40000001, 400011, current, 400011, current); + +INSERT INTO resource_info (resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 1, 400011, 400011, current, 400011, current); + +INSERT INTO tcs_catalog:component_inquiry (component_inquiry_id, component_id, user_id, comment, agreed_to_terms, rating, phase, tc_user_id, version, create_time, project_id) VALUES (80000001, 40000001, 400011, 'Cool', 1, 0, 113, 400011, 1, current, 40000001); + +INSERT INTO tcs_catalog:project_result (user_id, project_id, old_rating, new_rating, raw_score, final_score, payment, placed, rating_ind, valid_submission_ind, create_date, modify_date, passed_review_ind, point_adjustment, rating_order) VALUES (400011, 40000001, 0, 1, 80, 90, 1, 0, 0, 0, current, current, 1, 1, 1); + +INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1001,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1001); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 4, '1001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_jive_category_xref (comp_vers_id, jive_category_id) VALUES ('40000002', 1002); + +INSERT INTO resource (resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES (40000002, 1, 40000002, 400011, current, 400011, current); + +INSERT INTO resource_info (resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 1, 400011, 400011, current, 400011, current); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131); + +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000003, 1, 29, 132456, CURRENT, 132456, CURRENT, 40000011, null); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 2, '40000003', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 4, '1001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000003', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000003', '40000003', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO resource (resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES (40000003, 1, 40000003, 400011, current, 400011, current); + +INSERT INTO resource_info (resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 1, 400011, 400011, current, 400011, current); + +INSERT INTO component_inquiry (component_inquiry_id, component_id, user_id, comment, agreed_to_terms, rating, phase, tc_user_id, version, create_time, project_id) VALUES (80000003, 40000003, 400011, 'Cool3', 1, 0, 113, 400011, 1, current, 40000003); + +INSERT INTO project_result (user_id, project_id, old_rating, new_rating, raw_score, final_score, payment, placed, rating_ind, valid_submission_ind, create_date, modify_date, passed_review_ind, point_adjustment, rating_order) VALUES (400011, 40000003, 0, 1, 80, 90, 1, 0, 0, 0, current, current, 1, 1, 1); + +INSERT INTO comp_jive_category_xref (comp_vers_id, jive_category_id) VALUES ('40000003', 1003); + +INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000003, 40000003, 113, CURRENT); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000003, 40000003, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO copilot_profile(copilot_profile_id, user_id, copilot_profile_status_id, suspension_count, reliability, create_user, create_date, update_user, update_date) +VALUES(400011, 400011, 1, 1, 50, 132456, CURRENT, 132456, CURRENT); diff --git a/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.json b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.json new file mode 100755 index 000000000..b47388df7 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__insert_test_data", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__insert_test_data" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.sql b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.sql new file mode 100755 index 000000000..74d5c4d62 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__insert_test_data.sql @@ -0,0 +1,40 @@ +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_jive_category_xref (comp_vers_id, jive_category_id) VALUES ('40000001', 1001); + +INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT); + +INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT); + + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_jive_category_xref (comp_vers_id, jive_category_id) VALUES ('40000002', 1002); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131); \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry b/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry new file mode 100755 index 000000000..3793443f6 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry @@ -0,0 +1 @@ +* FROM component_inquiry WHERE component_id = 40000001; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry.json b/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry.json new file mode 100755 index 000000000..ae723df78 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_component_inquiry.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_component_inquiry", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_component_inquiry" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_project_result b/test/sqls/challengeUnregistration/tcs_catalog__select_project_result new file mode 100755 index 000000000..2a8336566 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_project_result @@ -0,0 +1 @@ +* FROM project_result WHERE project_id = 40000001; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_project_result.json b/test/sqls/challengeUnregistration/tcs_catalog__select_project_result.json new file mode 100755 index 000000000..e708f40a1 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_project_result.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_project_result", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_project_result" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry new file mode 100755 index 000000000..75b960cb7 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry @@ -0,0 +1 @@ +* FROM component_inquiry WHERE project_id = 40000001; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry.json b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry.json new file mode 100755 index 000000000..ba02d2d5e --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_component_inquiry.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_software_challenge_component_inquiry", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_software_challenge_component_inquiry" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource new file mode 100755 index 000000000..e538ec1ee --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource @@ -0,0 +1 @@ +* FROM resource WHERE project_id = 40000001; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource.json b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource.json new file mode 100755 index 000000000..816144594 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_software_challenge_resource", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_software_challenge_resource" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info new file mode 100755 index 000000000..c6a7175b2 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info @@ -0,0 +1,3 @@ +(SELECT i.value FROM resource_info i WHERE r.resource_id = i.resource_id AND i.resource_info_type_id = 1 ) AS user_id, +(SELECT i.value FROM resource_info i WHERE r.resource_id = i.resource_id AND i.resource_info_type_id = 2 ) AS handle +FROM resource r WHERE project_id = 40000001; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info.json b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info.json new file mode 100755 index 000000000..5e5123c56 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_software_challenge_resource_info.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_software_challenge_resource_info", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_software_challenge_resource_info" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource new file mode 100755 index 000000000..b0d456f35 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource @@ -0,0 +1 @@ +* FROM resource WHERE project_id = 40000002; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource.json b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource.json new file mode 100755 index 000000000..e0ce21a71 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_studio_challenge_resource", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_studio_challenge_resource" +} \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info new file mode 100755 index 000000000..b50384897 --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info @@ -0,0 +1,4 @@ +(SELECT i.value FROM resource_info i WHERE r.resource_id = i.resource_id AND i.resource_info_type_id = 1 ) AS user_id, +(SELECT i.value FROM resource_info i WHERE r.resource_id = i.resource_id AND i.resource_info_type_id = 2 ) AS handle, +(SELECT i.value FROM resource_info i WHERE r.resource_id = i.resource_id AND i.resource_info_type_id = 8 ) AS payments +FROM resource r WHERE project_id = 40000002; \ No newline at end of file diff --git a/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info.json b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info.json new file mode 100755 index 000000000..fbe5a466f --- /dev/null +++ b/test/sqls/challengeUnregistration/tcs_catalog__select_studio_challenge_resource_info.json @@ -0,0 +1,5 @@ +{ + "name" : "tcs_catalog__select_studio_challenge_resource_info", + "db" : "tcs_catalog", + "sqlfile" : "tcs_catalog__select_studio_challenge_resource_info" +} \ No newline at end of file diff --git a/test/test.challengeUnregistration.js b/test/test.challengeUnregistration.js new file mode 100755 index 000000000..85f776350 --- /dev/null +++ b/test/test.challengeUnregistration.js @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. + * + * @version 1.0 + * @author bugbuka + */ +"use strict"; +/*global describe, it, before, beforeEach, after, afterEach */ +/*jslint node: true, stupid: true, unparam: true */ + +/** + * Module dependencies. + */ +var fs = require('fs'); +var supertest = require('supertest'); +var assert = require('chai').assert; +var async = require('async'); +var _ = require('underscore'); +var testHelper = require('./helpers/testHelper'); +var SQL_DIR = __dirname + "/sqls/challengeUnregistration/"; +var SQL_DIR2 = "sqls/challengeUnregistration/"; +var TEST_FILE_DIR = "test/test_files/"; + +var API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:8080'; + +var grantForumAccess = require('../config').config.general.grantForumAccess; +/** + * Objects and values required for generating the OAuth token + */ +var CLIENT_ID = require('../config').config.general.oauthClientId; +var SECRET = require('../config').config.general.oauthClientSecret; +var jwt = require('jsonwebtoken'); + +describe('Challenge Unregistration API', function () { + this.timeout(120000); // The api with testing remote db could be quit slow + + /** + * Users that we have setup. + */ + var user11 = 'facebook|fb400011', + user12 = 'facebook|fb400012'; + + /** + * Return the authentication header to be used for the given user. + * @param {Object} user the user to authenticate + */ + function getAuthHeader(user) { + var authHeader = "Bearer " + jwt.sign({sub: user}, SECRET, {expiresInMinutes: 1000, audience: CLIENT_ID}); + return authHeader; + } + + /** + * Clear database + * @param {Function} done the callback + */ + function clearDb(done) { + async.series([ + function (cb) { + if (grantForumAccess !== true) { + cb(); + return; + } + testHelper.runSqlFile(SQL_DIR + "jive__clean", "jive", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "tcs_catalog__clean", "tcs_catalog", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "common_oltp__clean", "common_oltp", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "informixoltp__clean", "informixoltp", cb); + } + ], done); + } + + /** + * This function is run before all tests. + * Generate tests data. + * @param {Function} done the callback + */ + before(function (done) { + async.series([ + clearDb, + function (cb) { + if (grantForumAccess !== true) { + cb(); + return; + } + testHelper.runSqlFile(SQL_DIR + "jive__insert_test_data", "jive", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "common_oltp__insert_test_data", "common_oltp", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "tcs_catalog__insert_test_data", "tcs_catalog", cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + "informixoltp__insert_test_data", "informixoltp", cb); + } + ], done); + }); + /** + * This function is run after all tests. + * Clean up all data. + * @param {Function} done the callback + */ + after(function (done) { + clearDb(done); + }); + + //validate against a table + function validateTable(sqlfile, done) { + console.log("Now validate based on sqlfile: " + sqlfile); + async.waterfall([ + function (callback) { + testHelper.runSqlFromJSON(sqlfile, true, callback); + }, + function (result, callback) { + console.log('The query result:' + JSON.stringify(result)); + assert.ok(result.length === 0, 'result is empty'); + console.log('matched'); + callback(null, null); + } + ], done); + } + + //validateDatabase for test successInput + function validateDatabaseForDevelop(done) { + async.series([ + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_component_inquiry.json", + callback + ); + }, + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_project_result.json", + callback + ); + }, + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_software_challenge_resource.json", + callback + ); + }, + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_software_challenge_resource_info.json", + callback + ); + }, + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_software_challenge_component_inquiry.json", + callback + ); + }, + function (callback) { + if (grantForumAccess !== true) { + callback(); + return; + } + + validateTable( + SQL_DIR2 + "jive__select_jiveuserperm.json", + callback + ); + } + ], done); + } + + //validateDatabase for test successInput + function validateDatabaseForDesign(done) { + async.series([ + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_studio_challenge_resource.json", + callback + ); + }, + function (callback) { + validateTable( + SQL_DIR2 + "tcs_catalog__select_studio_challenge_resource_info.json", + callback + ); + } + ], done); + } + + // Check if the data are in expected structure and data + it('Unregister software challenge should success', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/40000001/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user11)) + .expect('Content-Type', /json/) + .expect(200) + .end(function (err, result) { + if (err) { + done(err); + return; + } + console.log('Registration completed. Now verify the database is the same as predicted data'); + validateDatabaseForDevelop(done); + }); + }); + + // Unreigster again the same user, the same challenge as above, should fail. + it('Unregister again should fail', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/40000001/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user11)) + .expect('Content-Type', /json/) + .expect(403, done); + }); + + + /// Check if the data are in expected structure and data + it('Unregister studio challenge should success', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/40000002/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user11)) + .expect('Content-Type', /json/) + .expect(200) + .end(function (err, result) { + if (err) { + done(err); + return; + } + validateDatabaseForDesign(done); + }); + }); + + // Check if the data are in expected structure and data + // It's a copilot posting challenge. + it('User unregister a copilot posting challenge', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/40000003/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user11)) + .expect('Content-Type', /json/) + .expect(200) + .end(function (err, result) { + if (err) { + done(err); + return; + } + console.log('Registration completed. Now verify the database is the same as predicted data'); + validateDatabaseForDevelop(done); + }); + }); + + // negative challengeId number. + it('negative challenge number', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/-40000002/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user12)) + .expect('Content-Type', /json/) + .expect(400, done); + }); + + // the challengeId param is not a number. + it('Challenge is NOT a number', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/NAN/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user12)) + .expect('Content-Type', /json/) + .expect(400, done); + }); + + // the challengeId param exceed MAX_INT. + it('Challenge number exceed MAX_INT', function (done) { + supertest(API_ENDPOINT) + .post("/v2/challenges/214748364700/unregister") + .set('Accept', 'application/json') + .set('Authorization', getAuthHeader(user12)) + .expect('Content-Type', /json/) + .expect(400, done); + }); +}); \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy