Skip to content

Commit 998f97a

Browse files
committed
feat(enrollment): enhance participant enrollment with dynamic field retrieval and improved logging
1 parent 994b3fd commit 998f97a

2 files changed

Lines changed: 63 additions & 370 deletions

File tree

test-scripts/enroll-participants.sh

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,70 @@ CURRENT_TIME=$(date +%s)
2323
PARTICIPANT_1_PHONE="${PARTICIPANT_1_PHONE:-+1555${CURRENT_TIME}001}"
2424
PARTICIPANT_2_PHONE="${PARTICIPANT_2_PHONE:-+1555${CURRENT_TIME}002}"
2525
PARTICIPANT_3_PHONE="${PARTICIPANT_3_PHONE:-+1555${CURRENT_TIME}003}"
26+
DEFAULT_TIMEZONE="${PARTICIPANT_TIMEZONE:-America/Toronto}"
27+
28+
# Helper to get participant-specific fields from .env with defaults
29+
get_participant_field() {
30+
local participant_num="$1"
31+
local field="$2"
32+
local default_value="$3"
33+
local var_name="PARTICIPANT_${participant_num}_${field}"
34+
local value="${!var_name}"
35+
36+
if [ -z "$value" ]; then
37+
value="$default_value"
38+
fi
39+
40+
echo "$value"
41+
}
2642

2743
# Function to enroll a participant
2844
enroll_participant() {
2945
local phone="$1"
30-
local name="$2"
31-
local participant_num="$3"
32-
33-
log "Enrolling participant $participant_num with phone: $phone"
34-
46+
local participant_num="$2"
47+
48+
local default_name
49+
case "$participant_num" in
50+
1) default_name="Test Participant One" ;;
51+
2) default_name="Test Participant Two" ;;
52+
3) default_name="Test Participant Three" ;;
53+
*) default_name="Test Participant $participant_num" ;;
54+
esac
55+
56+
local name
57+
local gender
58+
local ethnicity
59+
local background
60+
local timezone
61+
62+
name="$(get_participant_field "$participant_num" "NAME" "$default_name")"
63+
gender="$(get_participant_field "$participant_num" "GENDER" "")"
64+
ethnicity="$(get_participant_field "$participant_num" "ETHNICITY" "")"
65+
background="$(get_participant_field "$participant_num" "BACKGROUND" "")"
66+
timezone="$(get_participant_field "$participant_num" "TIMEZONE" "$DEFAULT_TIMEZONE")"
67+
68+
log "Enrolling participant $participant_num with phone: $phone (name: $name)"
69+
70+
payload=$(jq -n \
71+
--arg phone_number "$phone" \
72+
--arg name "$name" \
73+
--arg gender "$gender" \
74+
--arg ethnicity "$ethnicity" \
75+
--arg background "$background" \
76+
--arg timezone "$timezone" \
77+
'{
78+
phone_number: $phone_number
79+
}
80+
+ (if ($name | length) > 0 then {name: $name} else {} end)
81+
+ (if ($gender | length) > 0 then {gender: $gender} else {} end)
82+
+ (if ($ethnicity | length) > 0 then {ethnicity: $ethnicity} else {} end)
83+
+ (if ($background | length) > 0 then {background: $background} else {} end)
84+
+ (if ($timezone | length) > 0 then {timezone: $timezone} else {} end)
85+
')
86+
3587
response=$(curl -s -w "HTTPSTATUS:%{http_code}" -X POST \
3688
-H "Content-Type: application/json" \
37-
-d "{
38-
\"phone_number\": \"$phone\",
39-
\"name\": \"$name\",
40-
\"timezone\": \"America/Toronto\"
41-
}" \
89+
-d "$payload" \
4290
"$API_BASE_URL/conversation/participants")
4391

4492
status=$(echo "$response" | grep -o "HTTPSTATUS:[0-9]*" | cut -d: -f2)
@@ -74,13 +122,13 @@ enroll_participant() {
74122
}
75123

76124
# Enroll participant 1
77-
enroll_participant "$PARTICIPANT_1_PHONE" "Test Participant One" "1" || exit 1
125+
enroll_participant "$PARTICIPANT_1_PHONE" "1" || exit 1
78126

79127
# Enroll participant 2
80-
enroll_participant "$PARTICIPANT_2_PHONE" "Test Participant Two" "2" || exit 1
128+
enroll_participant "$PARTICIPANT_2_PHONE" "2" || exit 1
81129

82130
# Enroll participant 3
83-
enroll_participant "$PARTICIPANT_3_PHONE" "Test Participant Three" "3" || exit 1
131+
enroll_participant "$PARTICIPANT_3_PHONE" "3" || exit 1
84132

85133
echo
86134
log "All participants enrolled successfully!"

0 commit comments

Comments
 (0)