Stage 7
This commit is contained in:
121
test/core_ticket_tests.erl
Normal file
121
test/core_ticket_tests.erl
Normal file
@@ -0,0 +1,121 @@
|
||||
-module(core_ticket_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
setup() ->
|
||||
mnesia:start(),
|
||||
mnesia:create_table(ticket, [
|
||||
{attributes, record_info(fields, ticket)},
|
||||
{ram_copies, [node()]}
|
||||
]),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
mnesia:delete_table(ticket),
|
||||
mnesia:stop(),
|
||||
ok.
|
||||
|
||||
core_ticket_test_() ->
|
||||
{foreach,
|
||||
fun setup/0,
|
||||
fun cleanup/1,
|
||||
[
|
||||
{"Create ticket test", fun test_create_ticket/0},
|
||||
{"Update existing ticket test", fun test_update_ticket/0},
|
||||
{"Get ticket by id test", fun test_get_by_id/0},
|
||||
{"Get ticket by error hash test", fun test_get_by_error_hash/0},
|
||||
{"List all tickets test", fun test_list_all/0},
|
||||
{"List by status test", fun test_list_by_status/0},
|
||||
{"Update status test", fun test_update_status/0},
|
||||
{"Assign ticket test", fun test_assign_ticket/0},
|
||||
{"Add resolution test", fun test_add_resolution/0}
|
||||
]}.
|
||||
|
||||
test_create_ticket() ->
|
||||
ErrorMsg = <<"Test error">>,
|
||||
Stacktrace = <<"line 1\nline 2">>,
|
||||
Context = #{user_id => <<"user123">>},
|
||||
|
||||
{ok, Ticket} = core_ticket:create_or_update(ErrorMsg, Stacktrace, Context),
|
||||
|
||||
?assertEqual(ErrorMsg, Ticket#ticket.error_message),
|
||||
?assertEqual(Stacktrace, Ticket#ticket.stacktrace),
|
||||
?assertEqual(1, Ticket#ticket.count),
|
||||
?assertEqual(open, Ticket#ticket.status),
|
||||
?assert(is_binary(Ticket#ticket.id)),
|
||||
?assert(is_binary(Ticket#ticket.error_hash)).
|
||||
|
||||
test_update_ticket() ->
|
||||
ErrorMsg = <<"Test error">>,
|
||||
Stacktrace = <<"line 1">>,
|
||||
Context = #{},
|
||||
|
||||
{ok, Ticket1} = core_ticket:create_or_update(ErrorMsg, Stacktrace, Context),
|
||||
?assertEqual(1, Ticket1#ticket.count),
|
||||
|
||||
{ok, Ticket2} = core_ticket:create_or_update(ErrorMsg, Stacktrace, Context),
|
||||
?assertEqual(Ticket1#ticket.id, Ticket2#ticket.id),
|
||||
?assertEqual(2, Ticket2#ticket.count),
|
||||
?assert(Ticket2#ticket.last_seen >= Ticket1#ticket.last_seen).
|
||||
|
||||
test_get_by_id() ->
|
||||
{ok, Ticket} = core_ticket:create_or_update(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Found} = core_ticket:get_by_id(Ticket#ticket.id),
|
||||
?assertEqual(Ticket#ticket.id, Found#ticket.id),
|
||||
|
||||
{error, not_found} = core_ticket:get_by_id(<<"nonexistent">>).
|
||||
|
||||
test_get_by_error_hash() ->
|
||||
ErrorMsg = <<"Unique error">>,
|
||||
Stacktrace = <<"stack">>,
|
||||
{ok, Ticket} = core_ticket:create_or_update(ErrorMsg, Stacktrace, #{}),
|
||||
|
||||
{ok, Found} = core_ticket:get_by_error_hash(Ticket#ticket.error_hash),
|
||||
?assertEqual(Ticket#ticket.id, Found#ticket.id),
|
||||
|
||||
{error, not_found} = core_ticket:get_by_error_hash(<<"badhash">>).
|
||||
|
||||
test_list_all() ->
|
||||
{ok, _} = core_ticket:create_or_update(<<"Error 1">>, <<"">>, #{}),
|
||||
{ok, _} = core_ticket:create_or_update(<<"Error 2">>, <<"">>, #{}),
|
||||
{ok, _} = core_ticket:create_or_update(<<"Error 3">>, <<"">>, #{}),
|
||||
|
||||
{ok, Tickets} = core_ticket:list_all(),
|
||||
?assertEqual(3, length(Tickets)).
|
||||
|
||||
test_list_by_status() ->
|
||||
{ok, T1} = core_ticket:create_or_update(<<"E1">>, <<"">>, #{}),
|
||||
{ok, T2} = core_ticket:create_or_update(<<"E2">>, <<"">>, #{}),
|
||||
|
||||
core_ticket:update_status(T2#ticket.id, resolved),
|
||||
|
||||
{ok, Open} = core_ticket:list_by_status(open),
|
||||
?assertEqual(1, length(Open)),
|
||||
|
||||
{ok, Resolved} = core_ticket:list_by_status(resolved),
|
||||
?assertEqual(1, length(Resolved)).
|
||||
|
||||
test_update_status() ->
|
||||
{ok, Ticket} = core_ticket:create_or_update(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Updated} = core_ticket:update_status(Ticket#ticket.id, in_progress),
|
||||
?assertEqual(in_progress, Updated#ticket.status),
|
||||
|
||||
{ok, Resolved} = core_ticket:update_status(Ticket#ticket.id, resolved),
|
||||
?assertEqual(resolved, Resolved#ticket.status).
|
||||
|
||||
test_assign_ticket() ->
|
||||
AdminId = <<"admin123">>,
|
||||
{ok, Ticket} = core_ticket:create_or_update(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Assigned} = core_ticket:assign(Ticket#ticket.id, AdminId),
|
||||
?assertEqual(AdminId, Assigned#ticket.assigned_to),
|
||||
?assertEqual(in_progress, Assigned#ticket.status).
|
||||
|
||||
test_add_resolution() ->
|
||||
Note = <<"Fixed in version 1.0">>,
|
||||
{ok, Ticket} = core_ticket:create_or_update(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Updated} = core_ticket:add_resolution(Ticket#ticket.id, Note),
|
||||
?assertEqual(Note, Updated#ticket.resolution_note).
|
||||
105
test/logic_ticket_tests.erl
Normal file
105
test/logic_ticket_tests.erl
Normal file
@@ -0,0 +1,105 @@
|
||||
-module(logic_ticket_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
setup() ->
|
||||
mnesia:start(),
|
||||
mnesia:create_table(user, [{attributes, record_info(fields, user)}, {ram_copies, [node()]}]),
|
||||
mnesia:create_table(ticket, [{attributes, record_info(fields, ticket)}, {ram_copies, [node()]}]),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
mnesia:delete_table(ticket),
|
||||
mnesia:delete_table(user),
|
||||
mnesia:stop(),
|
||||
ok.
|
||||
|
||||
logic_ticket_test_() ->
|
||||
{foreach,
|
||||
fun setup/0,
|
||||
fun cleanup/1,
|
||||
[
|
||||
{"Report error test", fun test_report_error/0},
|
||||
{"List tickets admin only", fun test_list_tickets_admin_only/0},
|
||||
{"Update status test", fun test_update_status/0},
|
||||
{"Assign ticket test", fun test_assign_ticket/0},
|
||||
{"Resolve ticket test", fun test_resolve_ticket/0},
|
||||
{"Close ticket test", fun test_close_ticket/0},
|
||||
{"Get statistics test", fun test_get_statistics/0}
|
||||
]}.
|
||||
|
||||
create_test_user(Role) ->
|
||||
UserId = base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}),
|
||||
User = #user{id = UserId, email = <<UserId/binary, "@test.com">>, password_hash = <<"hash">>,
|
||||
role = Role, status = active, created_at = calendar:universal_time(), updated_at = calendar:universal_time()},
|
||||
mnesia:dirty_write(User),
|
||||
UserId.
|
||||
|
||||
test_report_error() ->
|
||||
{ok, Ticket} = logic_ticket:report_error(<<"Test error">>, <<"stack">>, #{}),
|
||||
?assertEqual(<<"Test error">>, Ticket#ticket.error_message),
|
||||
?assertEqual(1, Ticket#ticket.count),
|
||||
|
||||
{ok, Ticket2} = logic_ticket:report_error(<<"Test error">>, <<"stack">>, #{}),
|
||||
?assertEqual(2, Ticket2#ticket.count).
|
||||
|
||||
test_list_tickets_admin_only() ->
|
||||
AdminId = create_test_user(admin),
|
||||
UserId = create_test_user(user),
|
||||
|
||||
{ok, _} = logic_ticket:report_error(<<"E1">>, <<"">>, #{}),
|
||||
{ok, _} = logic_ticket:report_error(<<"E2">>, <<"">>, #{}),
|
||||
|
||||
{ok, Tickets} = logic_ticket:list_tickets(AdminId),
|
||||
?assertEqual(2, length(Tickets)),
|
||||
|
||||
{error, access_denied} = logic_ticket:list_tickets(UserId).
|
||||
|
||||
test_update_status() ->
|
||||
AdminId = create_test_user(admin),
|
||||
UserId = create_test_user(user),
|
||||
{ok, Ticket} = logic_ticket:report_error(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Updated} = logic_ticket:update_status(AdminId, Ticket#ticket.id, in_progress),
|
||||
?assertEqual(in_progress, Updated#ticket.status),
|
||||
|
||||
{error, access_denied} = logic_ticket:update_status(UserId, Ticket#ticket.id, resolved).
|
||||
|
||||
test_assign_ticket() ->
|
||||
AdminId = create_test_user(admin),
|
||||
AssignToId = create_test_user(admin),
|
||||
{ok, Ticket} = logic_ticket:report_error(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Assigned} = logic_ticket:assign_ticket(AdminId, Ticket#ticket.id, AssignToId),
|
||||
?assertEqual(AssignToId, Assigned#ticket.assigned_to),
|
||||
?assertEqual(in_progress, Assigned#ticket.status).
|
||||
|
||||
test_resolve_ticket() ->
|
||||
AdminId = create_test_user(admin),
|
||||
{ok, Ticket} = logic_ticket:report_error(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Resolved} = logic_ticket:resolve_ticket(AdminId, Ticket#ticket.id, <<"Fixed">>),
|
||||
?assertEqual(<<"Fixed">>, Resolved#ticket.resolution_note),
|
||||
?assertEqual(resolved, Resolved#ticket.status).
|
||||
|
||||
test_close_ticket() ->
|
||||
AdminId = create_test_user(admin),
|
||||
{ok, Ticket} = logic_ticket:report_error(<<"Error">>, <<"">>, #{}),
|
||||
|
||||
{ok, Closed} = logic_ticket:close_ticket(AdminId, Ticket#ticket.id),
|
||||
?assertEqual(closed, Closed#ticket.status).
|
||||
|
||||
test_get_statistics() ->
|
||||
AdminId = create_test_user(admin),
|
||||
|
||||
{ok, _} = logic_ticket:report_error(<<"E1">>, <<"">>, #{}),
|
||||
{ok, _} = logic_ticket:report_error(<<"E2">>, <<"">>, #{}),
|
||||
{ok, T3} = logic_ticket:report_error(<<"E3">>, <<"">>, #{}),
|
||||
|
||||
logic_ticket:update_status(AdminId, T3#ticket.id, resolved),
|
||||
|
||||
Stats = logic_ticket:get_statistics(AdminId),
|
||||
?assertEqual(3, maps:get(total_tickets, Stats)),
|
||||
?assertEqual(2, maps:get(open, Stats)),
|
||||
?assertEqual(1, maps:get(resolved, Stats)),
|
||||
?assertEqual(3, maps:get(total_errors, Stats)).
|
||||
282
test/scripts/test_tickets_api.sh
Normal file
282
test/scripts/test_tickets_api.sh
Normal file
@@ -0,0 +1,282 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:8080"
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
extract_json() {
|
||||
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
|
||||
}
|
||||
|
||||
extract_json_number() {
|
||||
echo "$1" | grep -o "\"$2\":[0-9]*" | head -1 | sed "s/\"$2\"://"
|
||||
}
|
||||
|
||||
http_post() {
|
||||
local url=$1; local data=$2; local token=$3
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X POST "$url" -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d "$data"
|
||||
else
|
||||
curl -s -X POST "$url" -H "Content-Type: application/json" -d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url=$1; local token=$2
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X GET "$url" -H "Authorization: Bearer $token"
|
||||
else
|
||||
curl -s -X GET "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
http_put() {
|
||||
local url=$1; local data=$2; local token=$3
|
||||
curl -s -X PUT "$url" -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d "$data"
|
||||
}
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB TICKETS API TEST SCRIPT"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
log_info "Checking if server is running..."
|
||||
if ! curl -s "$BASE_URL/health" | grep -q "ok"; then
|
||||
log_error "Server is not running"
|
||||
exit 1
|
||||
fi
|
||||
log_success "Server is running"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 1: Create test users"
|
||||
log_info "============================================================"
|
||||
|
||||
# Админ (первый пользователь)
|
||||
ADMIN_EMAIL="ticket_admin_$(date +%s)@example.com"
|
||||
ADMIN_PASSWORD="admin123"
|
||||
|
||||
log_info "Creating admin user..."
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}" "")
|
||||
ADMIN_TOKEN=$(extract_json "$response" "token")
|
||||
ADMIN_ID=$(extract_json "$response" "id")
|
||||
log_success "Admin created"
|
||||
|
||||
# Обычный пользователь
|
||||
USER_EMAIL="ticket_user_$(date +%s)@example.com"
|
||||
USER_PASSWORD="user123"
|
||||
|
||||
log_info "Creating regular user..."
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$USER_EMAIL\",\"password\":\"$USER_PASSWORD\"}" "")
|
||||
USER_TOKEN=$(extract_json "$response" "token")
|
||||
USER_ID=$(extract_json "$response" "id")
|
||||
log_success "User created"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 1: Report error (user)"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "User reporting error..."
|
||||
response=$(http_post "$BASE_URL/v1/tickets" \
|
||||
"{\"error_message\":\"Test error occurred\",\"stacktrace\":\"line 1\\nline 2\",\"context\":{\"user_id\":\"$USER_ID\"}}" "$USER_TOKEN")
|
||||
TICKET1_ID=$(extract_json "$response" "id")
|
||||
|
||||
if [ -n "$TICKET1_ID" ]; then
|
||||
log_success "Ticket created: $TICKET1_ID"
|
||||
else
|
||||
log_error "Failed to create ticket: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 2: Report same error again (should increment count)"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "User reporting same error..."
|
||||
response=$(http_post "$BASE_URL/v1/tickets" \
|
||||
"{\"error_message\":\"Test error occurred\",\"stacktrace\":\"line 1\\nline 2\"}" "$USER_TOKEN")
|
||||
COUNT=$(extract_json_number "$response" "count")
|
||||
|
||||
if [ "$COUNT" -eq 2 ]; then
|
||||
log_success "Ticket count incremented to $COUNT"
|
||||
else
|
||||
log_error "Count should be 2, got $COUNT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 3: Report different error"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "User reporting different error..."
|
||||
response=$(http_post "$BASE_URL/v1/tickets" \
|
||||
"{\"error_message\":\"Another error\"}" "$USER_TOKEN")
|
||||
TICKET2_ID=$(extract_json "$response" "id")
|
||||
|
||||
if [ -n "$TICKET2_ID" ] && [ "$TICKET2_ID" != "$TICKET1_ID" ]; then
|
||||
log_success "New ticket created: $TICKET2_ID"
|
||||
else
|
||||
log_error "Failed to create new ticket"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 4: Admin views all tickets"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin getting all tickets..."
|
||||
response=$(http_get "$BASE_URL/v1/admin/tickets" "$ADMIN_TOKEN")
|
||||
TICKET_COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
|
||||
|
||||
if [ "$TICKET_COUNT" -eq 2 ]; then
|
||||
log_success "Admin sees $TICKET_COUNT tickets"
|
||||
else
|
||||
log_error "Admin should see 2 tickets, found $TICKET_COUNT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 5: User cannot view tickets"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "User trying to view tickets..."
|
||||
response=$(http_get "$BASE_URL/v1/admin/tickets" "$USER_TOKEN")
|
||||
|
||||
if echo "$response" | grep -q "Admin access required"; then
|
||||
log_success "User correctly denied access"
|
||||
else
|
||||
log_error "User should be denied: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 6: Admin views tickets by status"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin getting open tickets..."
|
||||
response=$(http_get "$BASE_URL/v1/admin/tickets?status=open" "$ADMIN_TOKEN")
|
||||
OPEN_COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
|
||||
|
||||
if [ "$OPEN_COUNT" -eq 2 ]; then
|
||||
log_success "Found $OPEN_COUNT open tickets"
|
||||
else
|
||||
log_error "Should find 2 open tickets, found $OPEN_COUNT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 7: Admin updates ticket status"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin marking ticket as in_progress..."
|
||||
response=$(http_put "$BASE_URL/v1/admin/tickets/$TICKET1_ID" \
|
||||
"{\"action\":\"status\",\"status\":\"in_progress\"}" "$ADMIN_TOKEN")
|
||||
|
||||
STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
|
||||
if [ "$STATUS" = "in_progress" ]; then
|
||||
log_success "Ticket status updated to in_progress"
|
||||
else
|
||||
log_error "Failed to update status: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 8: Admin assigns ticket"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin assigning ticket..."
|
||||
response=$(http_put "$BASE_URL/v1/admin/tickets/$TICKET1_ID" \
|
||||
"{\"action\":\"assign\",\"admin_id\":\"$ADMIN_ID\"}" "$ADMIN_TOKEN")
|
||||
|
||||
ASSIGNED=$(echo "$response" | grep -o "\"assigned_to\":\"[^\"]*\"" | sed 's/"assigned_to":"//;s/"//')
|
||||
if [ "$ASSIGNED" = "$ADMIN_ID" ]; then
|
||||
log_success "Ticket assigned to admin"
|
||||
else
|
||||
log_error "Failed to assign ticket: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 9: Admin resolves ticket"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin resolving ticket..."
|
||||
response=$(http_put "$BASE_URL/v1/admin/tickets/$TICKET1_ID" \
|
||||
"{\"action\":\"resolve\",\"note\":\"Fixed in version 1.0\"}" "$ADMIN_TOKEN")
|
||||
|
||||
STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
|
||||
NOTE=$(echo "$response" | grep -o "\"resolution_note\":\"[^\"]*\"" | sed 's/"resolution_note":"//;s/"//')
|
||||
|
||||
if [ "$STATUS" = "resolved" ] && [ "$NOTE" = "Fixed in version 1.0" ]; then
|
||||
log_success "Ticket resolved with note"
|
||||
else
|
||||
log_error "Failed to resolve ticket: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 10: Admin closes ticket"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin closing ticket..."
|
||||
response=$(http_put "$BASE_URL/v1/admin/tickets/$TICKET1_ID" \
|
||||
"{\"action\":\"close\"}" "$ADMIN_TOKEN")
|
||||
|
||||
STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
|
||||
if [ "$STATUS" = "closed" ]; then
|
||||
log_success "Ticket closed"
|
||||
else
|
||||
log_error "Failed to close ticket: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 11: Admin views statistics"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin getting statistics..."
|
||||
response=$(http_get "$BASE_URL/v1/admin/tickets/stats" "$ADMIN_TOKEN")
|
||||
|
||||
TOTAL=$(extract_json_number "$response" "total_tickets")
|
||||
OPEN=$(extract_json_number "$response" "open")
|
||||
CLOSED=$(extract_json_number "$response" "closed")
|
||||
|
||||
if [ "$TOTAL" -eq 2 ] && [ "$OPEN" -eq 1 ] && [ "$CLOSED" -eq 1 ]; then
|
||||
log_success "Statistics: total=$TOTAL, open=$OPEN, closed=$CLOSED"
|
||||
else
|
||||
log_error "Statistics incorrect: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 12: Get single ticket"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Admin getting ticket $TICKET2_ID..."
|
||||
response=$(http_get "$BASE_URL/v1/admin/tickets/$TICKET2_ID" "$ADMIN_TOKEN")
|
||||
|
||||
if echo "$response" | grep -q "$TICKET2_ID"; then
|
||||
log_success "Ticket retrieved"
|
||||
else
|
||||
log_error "Failed to get ticket: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
log_success "TICKETS API TESTS COMPLETED!"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
echo "Summary of created resources:"
|
||||
echo " Admin: $ADMIN_EMAIL"
|
||||
echo " User: $USER_EMAIL"
|
||||
echo " Tickets: $TICKET1_ID, $TICKET2_ID"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user