From d0bc904a968f0d188afcfa85e038e1b937134326 Mon Sep 17 00:00:00 2001 From: Alexandertp Date: Wed, 14 Aug 2024 11:47:04 +0200 Subject: [PATCH] Check for status code in integration tests as well Co-authored-by: Reimar --- API/integration-tests.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/API/integration-tests.sh b/API/integration-tests.sh index 849c8fd..f0388e3 100644 --- a/API/integration-tests.sh +++ b/API/integration-tests.sh @@ -1,8 +1,25 @@ -USER_ID=`curl -X POST http://localhost:5287/api/Users -d '{"Email":"hej@example.com","Username":"Gamer","Password":"Gamer123!"}' --header 'Content-Type: application/json'` +#!/bin/sh +RESPONSE=`curl -sSX POST http://localhost:5287/api/Users -d '{"Email":"hej@example.com","Username":"Gamer","Password":"Gamer123!"}' --header 'Content-Type: application/json' --write-out '\n%{http_code}' --output -` +HTTP_STATUS=`echo -n "$RESPONSE" | tail -n 1` +USER_ID=`echo "$RESPONSE" | head -n -1` -TOKEN=`curl -X POST http://localhost:5287/api/Users/login -d '{"Email":"hej@example.com","Password":"Gamer123!"}' --header 'Content-Type: application/json'` +echo "POST /api/Users - $HTTP_STATUS" +echo -e " User ID: $USER_ID\n" -curl http://localhost:5287/api/Users/$USER_ID +RESPONSE=`curl -sSX POST http://localhost:5287/api/Users/login -d '{"Email":"hej@example.com","Password":"Gamer123!"}' --header 'Content-Type: application/json' --write-out '\n%{http_code}' --output -` +HTTP_STATUS=`echo -n "$RESPONSE" | tail -n 1` +TOKEN=`echo "$RESPONSE" | head -n -1` -curl -X DELETE http://localhost:5287/api/Users/$USER_ID +echo "POST /api/Users/login - $HTTP_STATUS" +echo -e " Received token: $TOKEN\n" + +RESPONSE=`curl -sS http://localhost:5287/api/Users/$USER_ID --write-out '\n%{http_code}' --output -` +HTTP_STATUS=`echo -n "$RESPONSE" | tail -n 1` +USER_DATA=`echo "$RESPONSE" | head -n -1` + +echo "GET /api/Users/$USER_ID - $HTTP_STATUS" +echo -e " User data: $USER_DATA\n" + +HTTP_STATUS=`curl -sSX DELETE http://localhost:5287/api/Users/$USER_ID --write-out '%{http_code}'` +echo "DELETE /api/Users/$USER_ID - $HTTP_STATUS"