feat: Enhance hackathon submission process with additional fields and validation checks
This commit is contained in:
@@ -9,7 +9,7 @@ use super::hackathon_service::{HackathonService, HackathonServiceTrait};
|
|||||||
use super::hackathon_schema::SubmissionStatus;
|
use super::hackathon_schema::SubmissionStatus;
|
||||||
use crate::v1::hackathon::HackathonRepository;
|
use crate::v1::hackathon::HackathonRepository;
|
||||||
use crate::{AppState, ResponseSuccessDto, ErrorDto};
|
use crate::{AppState, ResponseSuccessDto, ErrorDto};
|
||||||
use imphnen_entities::PermissionsEnum;
|
use imphnen_entities::{PermissionsEnum, UsersDetailQueryDto};
|
||||||
use imphnen_libs::{MetaRequestDto, ResponseListSuccessDto};
|
use imphnen_libs::{MetaRequestDto, ResponseListSuccessDto};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Extension, Path, Query},
|
extract::{Extension, Path, Query},
|
||||||
@@ -569,9 +569,11 @@ pub async fn update_hackathon_submission(
|
|||||||
)]
|
)]
|
||||||
pub async fn submit_hackathon_submission(
|
pub async fn submit_hackathon_submission(
|
||||||
Extension(state): Extension<AppState>,
|
Extension(state): Extension<AppState>,
|
||||||
|
Extension(user): Extension<UsersDetailQueryDto>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
match HackathonService::submit_hackathon_submission(id, &state).await {
|
let user_id = user.id.id.to_raw();
|
||||||
|
match HackathonService::submit_hackathon_submission(id, user_id, &state).await {
|
||||||
Ok(response) => (axum::http::StatusCode::OK, Json(response)).into_response(),
|
Ok(response) => (axum::http::StatusCode::OK, Json(response)).into_response(),
|
||||||
Err(error) => (StatusCode::from_u16(error.status).unwrap(), Json(error)).into_response(),
|
Err(error) => (StatusCode::from_u16(error.status).unwrap(), Json(error)).into_response(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,9 +315,18 @@ pub struct HackathonSubmissionCreateRequestDto {
|
|||||||
#[validate(length(min = 1, message = "Description cannot be empty"))]
|
#[validate(length(min = 1, message = "Description cannot be empty"))]
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub repository_url: Option<String>,
|
pub repository_url: Option<String>,
|
||||||
|
pub upload_file_url: Option<String>, // URL to uploaded zip/pdf file
|
||||||
pub demo_url: Option<String>,
|
pub demo_url: Option<String>,
|
||||||
pub slides_url: Option<String>,
|
pub slides_url: Option<String>,
|
||||||
pub technologies: Vec<String>,
|
pub technologies: Vec<String>,
|
||||||
|
// Social media contacts for demo (at least one required)
|
||||||
|
pub contact_instagram: Option<String>,
|
||||||
|
pub contact_twitter: Option<String>,
|
||||||
|
pub contact_linkedin: Option<String>,
|
||||||
|
pub contact_facebook: Option<String>,
|
||||||
|
pub contact_youtube: Option<String>,
|
||||||
|
pub contact_tiktok: Option<String>,
|
||||||
|
pub contact_other: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||||
@@ -331,11 +340,27 @@ pub struct HackathonSubmissionUpdateRequestDto {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub repository_url: Option<String>,
|
pub repository_url: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub upload_file_url: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub demo_url: Option<String>,
|
pub demo_url: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub slides_url: Option<String>,
|
pub slides_url: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub technologies: Option<Vec<String>>,
|
pub technologies: Option<Vec<String>>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_instagram: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_twitter: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_linkedin: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_facebook: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_youtube: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_tiktok: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contact_other: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||||
@@ -346,9 +371,17 @@ pub struct HackathonSubmissionDto {
|
|||||||
pub project_name: String,
|
pub project_name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub repository_url: Option<String>,
|
pub repository_url: Option<String>,
|
||||||
|
pub upload_file_url: Option<String>,
|
||||||
pub demo_url: Option<String>,
|
pub demo_url: Option<String>,
|
||||||
pub slides_url: Option<String>,
|
pub slides_url: Option<String>,
|
||||||
pub technologies: Vec<String>,
|
pub technologies: Vec<String>,
|
||||||
|
pub contact_instagram: Option<String>,
|
||||||
|
pub contact_twitter: Option<String>,
|
||||||
|
pub contact_linkedin: Option<String>,
|
||||||
|
pub contact_facebook: Option<String>,
|
||||||
|
pub contact_youtube: Option<String>,
|
||||||
|
pub contact_tiktok: Option<String>,
|
||||||
|
pub contact_other: Option<String>,
|
||||||
#[serde(rename = "status")]
|
#[serde(rename = "status")]
|
||||||
pub submission_status: SubmissionStatus,
|
pub submission_status: SubmissionStatus,
|
||||||
pub judge_feedback: Option<String>,
|
pub judge_feedback: Option<String>,
|
||||||
@@ -498,9 +531,17 @@ impl From<HackathonSubmissionsSchema> for HackathonSubmissionDto {
|
|||||||
project_name: schema.project_name.unwrap_or_default(),
|
project_name: schema.project_name.unwrap_or_default(),
|
||||||
description: schema.description.unwrap_or_default(),
|
description: schema.description.unwrap_or_default(),
|
||||||
repository_url: schema.repository_url,
|
repository_url: schema.repository_url,
|
||||||
|
upload_file_url: schema.upload_file_url,
|
||||||
demo_url: schema.demo_url,
|
demo_url: schema.demo_url,
|
||||||
slides_url: schema.slides_url,
|
slides_url: schema.slides_url,
|
||||||
technologies: schema.technologies.unwrap_or_default(),
|
technologies: schema.technologies.unwrap_or_default(),
|
||||||
|
contact_instagram: schema.contact_instagram,
|
||||||
|
contact_twitter: schema.contact_twitter,
|
||||||
|
contact_linkedin: schema.contact_linkedin,
|
||||||
|
contact_facebook: schema.contact_facebook,
|
||||||
|
contact_youtube: schema.contact_youtube,
|
||||||
|
contact_tiktok: schema.contact_tiktok,
|
||||||
|
contact_other: schema.contact_other,
|
||||||
submission_status: schema.submission_status.unwrap_or(super::hackathon_schema::SubmissionStatus::Draft),
|
submission_status: schema.submission_status.unwrap_or(super::hackathon_schema::SubmissionStatus::Draft),
|
||||||
judge_feedback: schema.judge_feedback,
|
judge_feedback: schema.judge_feedback,
|
||||||
submitted_at: schema.submitted_at.unwrap_or(chrono::Utc::now()),
|
submitted_at: schema.submitted_at.unwrap_or(chrono::Utc::now()),
|
||||||
|
|||||||
@@ -529,9 +529,17 @@ impl<'a> HackathonRepository<'a> {
|
|||||||
project_name: Some(submission.project_name),
|
project_name: Some(submission.project_name),
|
||||||
description: Some(submission.description),
|
description: Some(submission.description),
|
||||||
repository_url: submission.repository_url,
|
repository_url: submission.repository_url,
|
||||||
|
upload_file_url: submission.upload_file_url,
|
||||||
demo_url: submission.demo_url,
|
demo_url: submission.demo_url,
|
||||||
slides_url: submission.slides_url,
|
slides_url: submission.slides_url,
|
||||||
technologies: Some(submission.technologies),
|
technologies: Some(submission.technologies),
|
||||||
|
contact_instagram: submission.contact_instagram,
|
||||||
|
contact_twitter: submission.contact_twitter,
|
||||||
|
contact_linkedin: submission.contact_linkedin,
|
||||||
|
contact_facebook: submission.contact_facebook,
|
||||||
|
contact_youtube: submission.contact_youtube,
|
||||||
|
contact_tiktok: submission.contact_tiktok,
|
||||||
|
contact_other: submission.contact_other,
|
||||||
submission_status: Some(super::hackathon_schema::SubmissionStatus::Draft),
|
submission_status: Some(super::hackathon_schema::SubmissionStatus::Draft),
|
||||||
judge_feedback: None,
|
judge_feedback: None,
|
||||||
submitted_at: Some(chrono::Utc::now()),
|
submitted_at: Some(chrono::Utc::now()),
|
||||||
@@ -648,6 +656,9 @@ impl<'a> HackathonRepository<'a> {
|
|||||||
if let Some(repository_url) = updates.repository_url {
|
if let Some(repository_url) = updates.repository_url {
|
||||||
existing.repository_url = Some(repository_url);
|
existing.repository_url = Some(repository_url);
|
||||||
}
|
}
|
||||||
|
if let Some(upload_file_url) = updates.upload_file_url {
|
||||||
|
existing.upload_file_url = Some(upload_file_url);
|
||||||
|
}
|
||||||
if let Some(demo_url) = updates.demo_url {
|
if let Some(demo_url) = updates.demo_url {
|
||||||
existing.demo_url = Some(demo_url);
|
existing.demo_url = Some(demo_url);
|
||||||
}
|
}
|
||||||
@@ -657,6 +668,27 @@ impl<'a> HackathonRepository<'a> {
|
|||||||
if let Some(technologies) = updates.technologies {
|
if let Some(technologies) = updates.technologies {
|
||||||
existing.technologies = Some(technologies);
|
existing.technologies = Some(technologies);
|
||||||
}
|
}
|
||||||
|
if let Some(contact_instagram) = updates.contact_instagram {
|
||||||
|
existing.contact_instagram = Some(contact_instagram);
|
||||||
|
}
|
||||||
|
if let Some(contact_twitter) = updates.contact_twitter {
|
||||||
|
existing.contact_twitter = Some(contact_twitter);
|
||||||
|
}
|
||||||
|
if let Some(contact_linkedin) = updates.contact_linkedin {
|
||||||
|
existing.contact_linkedin = Some(contact_linkedin);
|
||||||
|
}
|
||||||
|
if let Some(contact_facebook) = updates.contact_facebook {
|
||||||
|
existing.contact_facebook = Some(contact_facebook);
|
||||||
|
}
|
||||||
|
if let Some(contact_youtube) = updates.contact_youtube {
|
||||||
|
existing.contact_youtube = Some(contact_youtube);
|
||||||
|
}
|
||||||
|
if let Some(contact_tiktok) = updates.contact_tiktok {
|
||||||
|
existing.contact_tiktok = Some(contact_tiktok);
|
||||||
|
}
|
||||||
|
if let Some(contact_other) = updates.contact_other {
|
||||||
|
existing.contact_other = Some(contact_other);
|
||||||
|
}
|
||||||
|
|
||||||
existing.updated_at = Some(get_iso_date());
|
existing.updated_at = Some(get_iso_date());
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,17 @@ pub struct HackathonSubmissionsSchema {
|
|||||||
pub project_name: Option<String>,
|
pub project_name: Option<String>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub repository_url: Option<String>,
|
pub repository_url: Option<String>,
|
||||||
|
pub upload_file_url: Option<String>,
|
||||||
pub demo_url: Option<String>,
|
pub demo_url: Option<String>,
|
||||||
pub slides_url: Option<String>,
|
pub slides_url: Option<String>,
|
||||||
pub technologies: Option<Vec<String>>,
|
pub technologies: Option<Vec<String>>,
|
||||||
|
pub contact_instagram: Option<String>,
|
||||||
|
pub contact_twitter: Option<String>,
|
||||||
|
pub contact_linkedin: Option<String>,
|
||||||
|
pub contact_facebook: Option<String>,
|
||||||
|
pub contact_youtube: Option<String>,
|
||||||
|
pub contact_tiktok: Option<String>,
|
||||||
|
pub contact_other: Option<String>,
|
||||||
pub submission_status: Option<SubmissionStatus>,
|
pub submission_status: Option<SubmissionStatus>,
|
||||||
pub judge_feedback: Option<String>,
|
pub judge_feedback: Option<String>,
|
||||||
pub submitted_at: Option<DateTime<Utc>>,
|
pub submitted_at: Option<DateTime<Utc>>,
|
||||||
@@ -310,9 +318,17 @@ impl Default for HackathonSubmissionsSchema {
|
|||||||
project_name: Some(String::new()),
|
project_name: Some(String::new()),
|
||||||
description: Some(String::new()),
|
description: Some(String::new()),
|
||||||
repository_url: None,
|
repository_url: None,
|
||||||
|
upload_file_url: None,
|
||||||
demo_url: None,
|
demo_url: None,
|
||||||
slides_url: None,
|
slides_url: None,
|
||||||
technologies: Some(vec![]),
|
technologies: Some(vec![]),
|
||||||
|
contact_instagram: None,
|
||||||
|
contact_twitter: None,
|
||||||
|
contact_linkedin: None,
|
||||||
|
contact_facebook: None,
|
||||||
|
contact_youtube: None,
|
||||||
|
contact_tiktok: None,
|
||||||
|
contact_other: None,
|
||||||
submission_status: Some(SubmissionStatus::Draft),
|
submission_status: Some(SubmissionStatus::Draft),
|
||||||
judge_feedback: None,
|
judge_feedback: None,
|
||||||
submitted_at: Some(Utc::now()),
|
submitted_at: Some(Utc::now()),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use serde::Deserialize;
|
||||||
// Type alias to shorten complex future return types used across the service trait
|
// Type alias to shorten complex future return types used across the service trait
|
||||||
type ListServiceFut<T> = Pin<Box<dyn Future<Output = Result<imphnen_libs::ResponseListSuccessDto<Vec<T>>, ErrorDto>> + Send>>;
|
type ListServiceFut<T> = Pin<Box<dyn Future<Output = Result<imphnen_libs::ResponseListSuccessDto<Vec<T>>, ErrorDto>> + Send>>;
|
||||||
use super::hackathon_dto::{
|
use super::hackathon_dto::{
|
||||||
@@ -111,6 +112,7 @@ pub trait HackathonServiceTrait: Send + Sync + 'static {
|
|||||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
||||||
fn submit_hackathon_submission(
|
fn submit_hackathon_submission(
|
||||||
id: String,
|
id: String,
|
||||||
|
user_id: String,
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
||||||
fn update_submission_status(
|
fn update_submission_status(
|
||||||
@@ -881,13 +883,14 @@ impl HackathonServiceTrait for HackathonService {
|
|||||||
|
|
||||||
fn submit_hackathon_submission(
|
fn submit_hackathon_submission(
|
||||||
id: String,
|
id: String,
|
||||||
|
user_id: String,
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>> {
|
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>> {
|
||||||
let state = state.to_owned();
|
let state = state.to_owned();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let repo = HackathonRepository::new(&state);
|
let repo = HackathonRepository::new(&state);
|
||||||
|
|
||||||
// Get submission to extract hackathon_id for timeline validation
|
// Get submission to extract hackathon_id for timeline validation and team_id for leader check
|
||||||
let submission = match repo.get_hackathon_submission_by_id(id.clone()).await {
|
let submission = match repo.get_hackathon_submission_by_id(id.clone()).await {
|
||||||
Ok(sub) => sub,
|
Ok(sub) => sub,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -909,6 +912,97 @@ impl HackathonServiceTrait for HackathonService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// VALIDATION 1: Check if user is the team leader
|
||||||
|
if let Some(team_id_thing) = &submission.team_id {
|
||||||
|
let team_id = team_id_thing.id.to_raw();
|
||||||
|
// Get team information to check leader
|
||||||
|
let team_query = format!(
|
||||||
|
"SELECT leader_id FROM app_teams WHERE id = type::thing('app_teams', '{}')",
|
||||||
|
team_id
|
||||||
|
);
|
||||||
|
|
||||||
|
match state.surrealdb_ws.query(&team_query).await {
|
||||||
|
Ok(mut result) => {
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct TeamLeader {
|
||||||
|
leader_id: surrealdb::sql::Thing,
|
||||||
|
}
|
||||||
|
|
||||||
|
let team: Option<TeamLeader> = result.take(0).ok().flatten();
|
||||||
|
if let Some(team) = team {
|
||||||
|
let leader_id = team.leader_id.id.to_raw();
|
||||||
|
if leader_id != user_id {
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::FORBIDDEN.as_u16(),
|
||||||
|
message: "Only team leader can submit the project".to_string(),
|
||||||
|
details: Some(serde_json::json!({
|
||||||
|
"team_leader_id": leader_id,
|
||||||
|
"your_user_id": user_id
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::NOT_FOUND.as_u16(),
|
||||||
|
message: "Team not found".to_string(),
|
||||||
|
details: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to get team information: {}", e);
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||||
|
message: "Failed to verify team leader".to_string(),
|
||||||
|
details: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||||
|
message: "Submission has no associated team".to_string(),
|
||||||
|
details: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// VALIDATION 2: Must have repository_url OR upload_file_url
|
||||||
|
let has_repo = submission.repository_url.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false);
|
||||||
|
let has_upload = submission.upload_file_url.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false);
|
||||||
|
|
||||||
|
if !has_repo && !has_upload {
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||||
|
message: "Submission must include either repository URL or uploaded file (zip/pdf)".to_string(),
|
||||||
|
details: Some(serde_json::json!({
|
||||||
|
"required": "repository_url OR upload_file_url"
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// VALIDATION 3: Must have at least one social media contact
|
||||||
|
let has_contact = [
|
||||||
|
&submission.contact_instagram,
|
||||||
|
&submission.contact_twitter,
|
||||||
|
&submission.contact_linkedin,
|
||||||
|
&submission.contact_facebook,
|
||||||
|
&submission.contact_youtube,
|
||||||
|
&submission.contact_tiktok,
|
||||||
|
&submission.contact_other,
|
||||||
|
].iter().any(|contact| {
|
||||||
|
contact.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
if !has_contact {
|
||||||
|
return Err(ErrorDto {
|
||||||
|
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||||
|
message: "Submission must include at least one social media contact for demo".to_string(),
|
||||||
|
details: Some(serde_json::json!({
|
||||||
|
"required": "At least one of: contact_instagram, contact_twitter, contact_linkedin, contact_facebook, contact_youtube, contact_tiktok, contact_other"
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Check submission timeline phase
|
// Check submission timeline phase
|
||||||
match repo.get_submission_timeline_phase(submission.hackathon_id.id.to_raw()).await {
|
match repo.get_submission_timeline_phase(submission.hackathon_id.id.to_raw()).await {
|
||||||
Ok(Some(timeline_phase)) => {
|
Ok(Some(timeline_phase)) => {
|
||||||
|
|||||||
@@ -98,16 +98,175 @@ test_hackathon_endpoints() {
|
|||||||
test_api_endpoint "DELETE Timeline" "DELETE" "/v1/hackathons/timeline/$created_timeline_id" 200 "" true
|
test_api_endpoint "DELETE Timeline" "DELETE" "/v1/hackathons/timeline/$created_timeline_id" 200 "" true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# === Hackathon Participants ===
|
||||||
|
printf "\n${CYAN}Testing Hackathon Participants...${NC}\n"
|
||||||
|
|
||||||
|
# Register participant for hackathon
|
||||||
|
local register_participant_data=$(jq -n --arg hackathon_id "$created_hackathon_id" --arg user_id "$AUTH_USER_ID" '{
|
||||||
|
hackathon_id: $hackathon_id,
|
||||||
|
user_id: $user_id,
|
||||||
|
role: "participant"
|
||||||
|
}')
|
||||||
|
test_api_endpoint "POST Register Participant" "POST" "/v1/hackathons/$created_hackathon_id/participants" 200 "$register_participant_data" true
|
||||||
|
|
||||||
|
# List participants
|
||||||
|
test_api_endpoint "GET List Participants" "GET" "/v1/hackathons/$created_hackathon_id/participants" 200 "" true
|
||||||
|
test_api_endpoint "GET List Participants (Paginated)" "GET" "/v1/hackathons/$created_hackathon_id/participants?page=1&limit=10" 200 "" true
|
||||||
|
|
||||||
# === Hackathon Submissions ===
|
# === Hackathon Submissions ===
|
||||||
# Note: Submissions require team participation
|
printf "\n${CYAN}Testing Hackathon Submissions...${NC}\n"
|
||||||
# test_api_endpoint "GET Hackathon Submissions" "GET" "/v1/hackathons/$created_hackathon_id/submissions" 200 "" true
|
|
||||||
# test_api_endpoint "GET My Submissions" "GET" "/v1/hackathons/submissions/me" 200 "" true
|
# Get or create a team for submissions
|
||||||
|
local teams_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/teams?page=1&limit=1")
|
||||||
|
local team_id=$(echo "$teams_response" | jq -r '.data[0].id // empty')
|
||||||
|
|
||||||
|
if [ -z "$team_id" ]; then
|
||||||
|
# Create a team for submission testing
|
||||||
|
local create_team_data=$(jq -n '{
|
||||||
|
name: "Hackathon Test Team '$(date +%s)'",
|
||||||
|
description: "Team for hackathon submission testing",
|
||||||
|
max_members: 5
|
||||||
|
}')
|
||||||
|
local team_response=$(curl -s -X POST -H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" -d "$create_team_data" \
|
||||||
|
"$BASE_URL/v1/teams/create")
|
||||||
|
team_id=$(echo "$team_response" | jq -r '.data.id // empty')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$team_id" ]; then
|
||||||
|
# Create submission with all required fields
|
||||||
|
local create_submission_data=$(jq -n --arg hackathon_id "$created_hackathon_id" --arg team_id "$team_id" '{
|
||||||
|
project_name: "Test Submission '$(date +%s)'",
|
||||||
|
description: "Automated test submission for hackathon",
|
||||||
|
repository_url: "https://github.com/test/repo",
|
||||||
|
upload_file_url: "https://storage.example.com/submissions/test-project.zip",
|
||||||
|
demo_url: "https://demo.example.com",
|
||||||
|
slides_url: "https://slides.example.com/test",
|
||||||
|
technologies: ["Rust", "Axum", "SurrealDB"],
|
||||||
|
contact_instagram: "@team_instagram",
|
||||||
|
contact_twitter: "@team_twitter",
|
||||||
|
contact_linkedin: "linkedin.com/in/team"
|
||||||
|
}')
|
||||||
|
local create_submission_response=$(test_api_endpoint "POST Create Submission" "POST" "/v1/hackathons/$created_hackathon_id/teams/$team_id/submissions" 201 "$create_submission_data" true)
|
||||||
|
local submission_id=$(echo "$create_submission_response" | jq -r '.data.id // empty')
|
||||||
|
|
||||||
|
if [ -n "$submission_id" ]; then
|
||||||
|
# Get submission by ID
|
||||||
|
test_api_endpoint "GET Submission By ID" "GET" "/v1/hackathons/submissions/$submission_id" 200 "" true
|
||||||
|
|
||||||
|
# List all submissions for hackathon
|
||||||
|
test_api_endpoint "GET Hackathon Submissions" "GET" "/v1/hackathons/$created_hackathon_id/submissions" 200 "" true
|
||||||
|
test_api_endpoint "GET Hackathon Submissions (Paginated)" "GET" "/v1/hackathons/$created_hackathon_id/submissions?page=1&limit=10" 200 "" true
|
||||||
|
|
||||||
|
# Update submission
|
||||||
|
local update_submission_data=$(jq -n '{
|
||||||
|
project_name: "Updated Test Submission",
|
||||||
|
description: "Updated description for testing",
|
||||||
|
repository_url: "https://github.com/test/updated-repo",
|
||||||
|
upload_file_url: "https://storage.example.com/submissions/updated-project.zip",
|
||||||
|
technologies: ["Rust", "Axum", "PostgreSQL"],
|
||||||
|
contact_youtube: "youtube.com/@teamchannel",
|
||||||
|
contact_facebook: "facebook.com/teampage"
|
||||||
|
}')
|
||||||
|
test_api_endpoint "PUT Update Submission" "PUT" "/v1/hackathons/submissions/$submission_id" 200 "$update_submission_data" true
|
||||||
|
|
||||||
|
# === Test Validation Errors ===
|
||||||
|
printf "\n${CYAN}Testing Submission Validation Errors...${NC}\n"
|
||||||
|
|
||||||
|
# Create a submission without repo/upload to test validation
|
||||||
|
local invalid_submission_no_repo=$(jq -n '{
|
||||||
|
project_name: "Invalid Submission No Repo",
|
||||||
|
description: "Testing validation - missing both repo and upload",
|
||||||
|
technologies: ["Test"],
|
||||||
|
contact_instagram: "@testaccount"
|
||||||
|
}')
|
||||||
|
local invalid_sub_response=$(curl -s -X POST -H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" -d "$invalid_submission_no_repo" \
|
||||||
|
"$BASE_URL/v1/hackathons/$created_hackathon_id/teams/$team_id/submissions")
|
||||||
|
local invalid_sub_id=$(echo "$invalid_sub_response" | jq -r '.data.id // empty')
|
||||||
|
|
||||||
|
if [ -n "$invalid_sub_id" ]; then
|
||||||
|
# Try to submit without repo/upload - should fail with 400
|
||||||
|
printf "${YELLOW}Testing: Submit without repo/upload (should fail)${NC}\n"
|
||||||
|
local submit_response=$(curl -s -w "\n%{http_code}" -X POST \
|
||||||
|
-H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
"$BASE_URL/v1/hackathons/submissions/$invalid_sub_id/submit")
|
||||||
|
local submit_status=$(echo "$submit_response" | tail -n1)
|
||||||
|
if [ "$submit_status" == "400" ]; then
|
||||||
|
printf "${GREEN}✓ Validation works: Rejected submission without repo/upload${NC}\n"
|
||||||
|
else
|
||||||
|
printf "${RED}✗ Validation failed: Should reject submission without repo/upload (got $submit_status)${NC}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup invalid submission
|
||||||
|
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
"$BASE_URL/v1/hackathons/submissions/$invalid_sub_id" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create a submission without contact to test validation
|
||||||
|
local invalid_submission_no_contact=$(jq -n '{
|
||||||
|
project_name: "Invalid Submission No Contact",
|
||||||
|
description: "Testing validation - missing contact",
|
||||||
|
repository_url: "https://github.com/test/repo",
|
||||||
|
technologies: ["Test"]
|
||||||
|
}')
|
||||||
|
invalid_sub_response=$(curl -s -X POST -H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" -d "$invalid_submission_no_contact" \
|
||||||
|
"$BASE_URL/v1/hackathons/$created_hackathon_id/teams/$team_id/submissions")
|
||||||
|
invalid_sub_id=$(echo "$invalid_sub_response" | jq -r '.data.id // empty')
|
||||||
|
|
||||||
|
if [ -n "$invalid_sub_id" ]; then
|
||||||
|
# Try to submit without contact - should fail with 400
|
||||||
|
printf "${YELLOW}Testing: Submit without social media contact (should fail)${NC}\n"
|
||||||
|
submit_response=$(curl -s -w "\n%{http_code}" -X POST \
|
||||||
|
-H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
"$BASE_URL/v1/hackathons/submissions/$invalid_sub_id/submit")
|
||||||
|
submit_status=$(echo "$submit_response" | tail -n1)
|
||||||
|
if [ "$submit_status" == "400" ]; then
|
||||||
|
printf "${GREEN}✓ Validation works: Rejected submission without social media contact${NC}\n"
|
||||||
|
else
|
||||||
|
printf "${RED}✗ Validation failed: Should reject submission without contact (got $submit_status)${NC}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup invalid submission
|
||||||
|
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
"$BASE_URL/v1/hackathons/submissions/$invalid_sub_id" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# === Submit Valid Submission ===
|
||||||
|
printf "\n${CYAN}Testing Valid Submission...${NC}\n"
|
||||||
|
# Submit final submission (no body required) - should succeed as all validations pass
|
||||||
|
test_api_endpoint "POST Submit Final Submission" "POST" "/v1/hackathons/submissions/$submission_id/submit" 200 "" true
|
||||||
|
|
||||||
|
# Update submission status (admin only)
|
||||||
|
local update_status_data=$(jq -n '{
|
||||||
|
status: "under_review",
|
||||||
|
feedback: "Great project, under review by our panel"
|
||||||
|
}')
|
||||||
|
test_api_endpoint "PUT Update Submission Status" "PUT" "/v1/hackathons/submissions/$submission_id/status" 200 "$update_status_data" true
|
||||||
|
|
||||||
|
# Get user submissions
|
||||||
|
test_api_endpoint "GET User Submissions" "GET" "/v1/users/$AUTH_USER_ID/hackathon-submissions" 200 "" true
|
||||||
|
|
||||||
|
# Delete submission
|
||||||
|
test_api_endpoint "DELETE Submission" "DELETE" "/v1/hackathons/submissions/$submission_id" 200 "" true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# === Hackathon Results ===
|
# === Hackathon Results ===
|
||||||
# test_api_endpoint "GET Admin Results" "GET" "/v1/hackathons/$created_hackathon_id/results" 200 "" true
|
printf "\n${CYAN}Testing Hackathon Results...${NC}\n"
|
||||||
# test_api_endpoint "GET Public Results" "GET" "/v1/hackathons/$created_hackathon_id/results/public" 200 "" false
|
test_api_endpoint "GET Public Results" "GET" "/v1/hackathons/$created_hackathon_id/results" 200 "" false
|
||||||
|
test_api_endpoint "GET Admin Results" "GET" "/v1/hackathons/$created_hackathon_id/admin/results" 200 "" true
|
||||||
|
|
||||||
# Delete hackathon
|
# === Search Hackathons ===
|
||||||
|
local search_data=$(jq -n '{
|
||||||
|
query: "test",
|
||||||
|
page: 1,
|
||||||
|
limit: 10
|
||||||
|
}')
|
||||||
|
test_api_endpoint "POST Search Hackathons" "POST" "/v1/hackathons/search" 200 "$search_data" false
|
||||||
|
|
||||||
|
# Delete hackathon (cleanup)
|
||||||
test_api_endpoint "DELETE Hackathon" "DELETE" "/v1/hackathons/$created_hackathon_id" 200 "" true
|
test_api_endpoint "DELETE Hackathon" "DELETE" "/v1/hackathons/$created_hackathon_id" 200 "" true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-21
@@ -9,19 +9,15 @@ source "$(dirname "$0")/../common/test-common.sh"
|
|||||||
test_team_endpoints() {
|
test_team_endpoints() {
|
||||||
printf "\n${CYAN}=== Testing Team Endpoints ===${NC}\n"
|
printf "\n${CYAN}=== Testing Team Endpoints ===${NC}\n"
|
||||||
|
|
||||||
# Public endpoints (skip - may require auth)
|
# === Public Team Endpoints (Authenticated) ===
|
||||||
# test_api_endpoint "GET Public Teams" "GET" "/v1/teams" 200 "" false
|
test_api_endpoint "GET Public Teams List" "GET" "/v1/teams" 200 "" true
|
||||||
# test_api_endpoint "GET Public Teams (Search)" "GET" "/v1/teams?search=dev" 200 "" false
|
test_api_endpoint "GET Public Teams (Paginated)" "GET" "/v1/teams?page=1&limit=10" 200 "" true
|
||||||
# test_api_endpoint "GET Teams Search" "GET" "/v1/teams/search?query=development" 200 "" false
|
test_api_endpoint "GET Teams Search" "GET" "/v1/teams/search?query=test" 200 "" true
|
||||||
|
|
||||||
# Admin endpoints
|
# === Admin Endpoints ===
|
||||||
test_api_endpoint "GET Admin Teams" "GET" "/v1/teams/admin" 200 "" true
|
test_api_endpoint "GET Admin Teams" "GET" "/v1/teams/admin" 200 "" true
|
||||||
test_api_endpoint "GET Admin Teams (Paginated)" "GET" "/v1/teams/admin?page=1&limit=10" 200 "" true
|
test_api_endpoint "GET Admin Teams (Paginated)" "GET" "/v1/teams/admin?page=1&limit=10" 200 "" true
|
||||||
|
|
||||||
# Get team by ID (skip - test team may not exist)
|
|
||||||
# local test_team_id="team-001"
|
|
||||||
# test_api_endpoint "GET Team By ID" "GET" "/v1/teams/admin/$test_team_id" 200 "" true
|
|
||||||
|
|
||||||
# Test with dynamic team from list
|
# Test with dynamic team from list
|
||||||
local teams_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/teams/admin")
|
local teams_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/teams/admin")
|
||||||
local test_team_id=$(echo "$teams_response" | jq -r '.data[0].id // empty')
|
local test_team_id=$(echo "$teams_response" | jq -r '.data[0].id // empty')
|
||||||
@@ -29,38 +25,67 @@ test_team_endpoints() {
|
|||||||
if [ -n "$test_team_id" ]; then
|
if [ -n "$test_team_id" ]; then
|
||||||
test_api_endpoint "GET Team By ID" "GET" "/v1/teams/admin/$test_team_id" 200 "" true
|
test_api_endpoint "GET Team By ID" "GET" "/v1/teams/admin/$test_team_id" 200 "" true
|
||||||
test_api_endpoint "GET Team Members" "GET" "/v1/teams/admin/$test_team_id/members" 200 "" true
|
test_api_endpoint "GET Team Members" "GET" "/v1/teams/admin/$test_team_id/members" 200 "" true
|
||||||
|
test_api_endpoint "GET Team By ID (Public)" "GET" "/v1/teams/$test_team_id" 200 "" true
|
||||||
|
test_api_endpoint "GET Team Members (Public)" "GET" "/v1/teams/$test_team_id/members" 200 "" true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create team
|
# === Create Team and Test Full Flow ===
|
||||||
local create_team_data=$(jq -n '{
|
local create_team_data=$(jq -n '{
|
||||||
name: "Test Team '$(date +%s)'",
|
name: "Test Team '$(date +%s)'",
|
||||||
description: "Auto-generated test team",
|
description: "Auto-generated test team for comprehensive testing",
|
||||||
is_open: true,
|
is_open: true,
|
||||||
max_members: 5,
|
max_members: 5,
|
||||||
skills_required: ["Rust", "Testing"],
|
skills_required: ["Rust", "Testing", "API"],
|
||||||
location: "Remote"
|
location: "Remote"
|
||||||
}')
|
}')
|
||||||
local create_team_response=$(test_api_endpoint "POST Create Team" "POST" "/v1/teams/admin" 201 "$create_team_data" true)
|
local create_team_response=$(test_api_endpoint "POST Create Team" "POST" "/v1/teams/create" 201 "$create_team_data" true)
|
||||||
local created_team_id=$(echo "$create_team_response" | jq -r '.data.id // empty')
|
local created_team_id=$(echo "$create_team_response" | jq -r '.data.id // empty')
|
||||||
|
|
||||||
if [ -n "$created_team_id" ]; then
|
if [ -n "$created_team_id" ]; then
|
||||||
# Update team
|
# Update team
|
||||||
local update_team_data=$(jq -n '{
|
local update_team_data=$(jq -n '{
|
||||||
name: "Updated Test Team",
|
name: "Updated Test Team",
|
||||||
description: "Updated description",
|
description: "Updated description for testing",
|
||||||
is_open: false,
|
is_open: false,
|
||||||
max_members: 10
|
max_members: 10
|
||||||
}')
|
}')
|
||||||
test_api_endpoint "PUT Update Team" "PUT" "/v1/teams/admin/$created_team_id" 200 "$update_team_data" true
|
test_api_endpoint "PUT Update Team" "PUT" "/v1/teams/update/$created_team_id" 200 "$update_team_data" true
|
||||||
|
|
||||||
# Invite members
|
# === Team Member Management ===
|
||||||
local invite_data=$(jq -n '{
|
# Get a test user ID for member operations
|
||||||
user_ids: ["c3b1d6a8-8d4f-4b36-b789-2e532ec7a7b2"]
|
local users_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/users?page=1&limit=1")
|
||||||
|
local test_user_id=$(echo "$users_response" | jq -r '.data[0].id // empty')
|
||||||
|
|
||||||
|
if [ -n "$test_user_id" ] && [ "$test_user_id" != "$AUTH_USER_ID" ]; then
|
||||||
|
# Add team member
|
||||||
|
local add_member_data=$(jq -n --arg user_id "$test_user_id" '{
|
||||||
|
user_id: $user_id,
|
||||||
|
role: "member"
|
||||||
|
}')
|
||||||
|
test_api_endpoint "POST Add Team Member" "POST" "/v1/teams/$created_team_id/members" 200 "$add_member_data" true
|
||||||
|
|
||||||
|
# Remove team member
|
||||||
|
test_api_endpoint "DELETE Remove Team Member" "DELETE" "/v1/teams/$created_team_id/members/$test_user_id" 200 "" true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# === Team Invitation Flow ===
|
||||||
|
local invite_emails_data=$(jq -n '{
|
||||||
|
emails: ["test-invite@example.com"],
|
||||||
|
message: "Join our test team!"
|
||||||
}')
|
}')
|
||||||
test_api_endpoint "POST Invite Members" "POST" "/v1/teams/admin/$created_team_id/invite" 200 "$invite_data" true
|
local invite_response=$(test_api_endpoint "POST Invite Team Members" "POST" "/v1/teams/$created_team_id/invite" 200 "$invite_emails_data" true)
|
||||||
|
|
||||||
# Delete team
|
# Note: Accept invitation requires valid token from email
|
||||||
test_api_endpoint "DELETE Team" "DELETE" "/v1/teams/admin/$created_team_id" 200 "" true
|
# This would be tested in integration tests with email service
|
||||||
|
# test_api_endpoint "POST Accept Invitation" "POST" "/v1/teams/accept/{token}" 200 "" true
|
||||||
|
|
||||||
|
# === Leave Team ===
|
||||||
|
# Test leave team endpoint (will fail if user is owner, which is expected)
|
||||||
|
# test_api_endpoint "POST Leave Team" "POST" "/v1/teams/$created_team_id/leave" 200 "" true
|
||||||
|
# test_api_endpoint "POST Leave Current Team" "POST" "/v1/teams/leave-me" 200 "" true
|
||||||
|
|
||||||
|
# Delete team (cleanup)
|
||||||
|
test_api_endpoint "DELETE Team" "DELETE" "/v1/teams/delete/$created_team_id" 200 "" true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user