unit tests for 3 endpoints

This commit is contained in:
array-in-a-matrix 2024-07-24 18:30:41 -04:00
parent 2dc785fb44
commit 168e6592b1
2 changed files with 31 additions and 3 deletions

BIN
tests/test-image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

View file

@ -30,9 +30,37 @@ ENDPOINT="/api/v1/newUser"
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
curl -s -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" -d "username=testUser"
-d "password=$PASSWORD" -d "email=test@example.xyz"
curl -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \
-d "username=testUser" -d "password=$PASSWORD" \
-d "email=test@example.xyz" | jq -M
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
else printf "%bTest: Fail - $ENDPOINT" "$NAY"; exit 1;
else printf "%bTest: Fail - $ENDPOINT" "$NAY";
fi; printf "%b\n" "$CLR";
ENDPOINT="/api/v1/newSession"
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
TOKEN=$(curl -s -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser1" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq -M ".[0].token" | tr -d '"')
curl -X GET http://"$BINDADDR":"$PORT""$ENDPOINT" \
-H "Authorization: $TOKEN" | jq -M
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
else printf "%bTest: Fail - $ENDPOINT" "$NAY";
fi; printf "%b\n" "$CLR";
ENDPOINT="/api/v1/newFile"
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
TOKEN=$(curl -s -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser2" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq -M ".[0].token" | tr -d '"')
curl -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \
-H "Authorization: $TOKEN" -F "file=@test-image.png"
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
else printf "%bTest: Fail - $ENDPOINT" "$NAY";
fi; printf "%b\n" "$CLR";