| | | 1 | | #include "../../api/handlers/inventory_handler.h" |
| | | 2 | | #include "../../api/http_server.h" |
| | | 3 | | #include <assert.h> |
| | | 4 | | #include <string.h> |
| | | 5 | | #include <stdio.h> |
| | | 6 | | |
| | 1 | 7 | | void test_inventory_get() { |
| | 1 | 8 | | HttpRequest req = {0}; |
| | 1 | 9 | | HttpResponse res = {0}; |
| | 1 | 10 | | strcpy(req.method, "GET"); |
| | 1 | 11 | | handle_inventory_request(&req, &res); |
| | 1 | 12 | | assert(res.status_code == 200); |
| | | 13 | | |
| | 1 | 14 | | if (strstr(res.body, "part_name") == NULL) { |
| | 0 | 15 | | printf("[DEBUG] Inventory GET Failed. Body: %s\n", res.body); |
| | | 16 | | } |
| | | 17 | | |
| | 1 | 18 | | assert(strstr(res.body, "part_name") != NULL); |
| | 1 | 19 | | printf("[PASS] Inventory GET\n"); |
| | 1 | 20 | | } |
| | | 21 | | |
| | 1 | 22 | | void test_inventory_post_success() { |
| | 1 | 23 | | HttpRequest req = {0}; |
| | 1 | 24 | | HttpResponse res = {0}; |
| | 1 | 25 | | strcpy(req.method, "POST"); |
| | 1 | 26 | | strcpy(req.body, "{\"part_name\": \"Bearing\", \"sku\": \"BRG-001\", \"quantity\": 10, \"min_stock\": 5, \"cost\": 15. |
| | 1 | 27 | | handle_inventory_request(&req, &res); |
| | 1 | 28 | | assert(res.status_code == 201); |
| | 1 | 29 | | assert(strstr(res.body, "success") != NULL); |
| | 1 | 30 | | printf("[PASS] Inventory POST Success\n"); |
| | 1 | 31 | | } |
| | | 32 | | |
| | 1 | 33 | | void test_inventory_invalid_method() { |
| | 1 | 34 | | HttpRequest req = {0}; |
| | 1 | 35 | | HttpResponse res = {0}; |
| | 1 | 36 | | strcpy(req.method, "DELETE"); // POST artık desteklendiği için DELETE kullanıyoruz |
| | 1 | 37 | | handle_inventory_request(&req, &res); |
| | 1 | 38 | | assert(res.status_code == 405); |
| | 1 | 39 | | assert(strstr(res.body, "Method not supported") != NULL); |
| | 1 | 40 | | printf("[PASS] Inventory 405\n"); |
| | 1 | 41 | | } |
| | | 42 | | |
| | 1 | 43 | | int main() { |
| | 1 | 44 | | test_inventory_get(); |
| | 1 | 45 | | test_inventory_post_success(); |
| | 1 | 46 | | test_inventory_invalid_method(); |
| | 1 | 47 | | printf("\n✅ [PASS] Inventory handler test suite completed\n"); |
| | 1 | 48 | | return 0; |
| | | 49 | | } |