Files
mtusi2026lab4/student-tests/test_attachment_wrong_chat.sh
2026-10-30 21:09:56 +03:00

38 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# attachment_id from another chat in POST messages → 404.
set -eu
. "$(dirname "$0")/lib.sh"
png="$FIXTURES/tiny.png"
[ -f "$png" ] || die "missing fixture $png"
register_user alice
ALICE_ID=$USER_ID
create_chat 'chat-a' "[\"$ALICE_ID\"]"
CHAT_A=$CHAT_ID
upload_file "$CHAT_A" "$png" 'tiny.png' 'image/png'
expect_code 201
AID=$(printf '%s' "$HTTP_BODY" | jq -r .id)
create_chat 'chat-b' "[\"$ALICE_ID\"]"
CHAT_B=$CHAT_ID
http_json POST "/api/v1/chats/$CHAT_B/messages" \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $(uniq_name idem)" \
-d "{\"text\":\"hi\",\"attachment_ids\":[\"$AID\"]}"
expect_code 404
assert_eq "$(printf '%s' "$HTTP_BODY" | jq -r .error.code)" not_found
# Empty/whitespace text without attachments → 400
http_json POST "/api/v1/chats/$CHAT_B/messages" \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $(uniq_name idem)" \
-d '{"text":" "}'
expect_code 400
printf 'PASS test_attachment_wrong_chat\n'