forked from mtusi2026/mtusi2026lab4
lab4
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/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'
|
||||
Reference in New Issue
Block a user