| | | 1 | | #include "../../api/handlers/maintenance_handler.h" |
| | | 2 | | #include "../../api/http_server.h" |
| | | 3 | | |
| | | 4 | | #include <assert.h> |
| | | 5 | | #include <string.h> |
| | | 6 | | #include <stdio.h> |
| | | 7 | | #include <stdlib.h> |
| | | 8 | | |
| | 1 | 9 | | void test_serialize_maintenance() { |
| | 1 | 10 | | char *json = serialize_maintenance_to_json(); |
| | 1 | 11 | | assert(json != NULL); |
| | 1 | 12 | | assert(strstr(json, "Routine oil change") != NULL); |
| | 1 | 13 | | assert(strstr(json, "completed") != NULL); |
| | 1 | 14 | | free(json); |
| | 1 | 15 | | printf("[PASS] serialize_maintenance_to_json\n"); |
| | 1 | 16 | | } |
| | | 17 | | |
| | 1 | 18 | | void test_handle_maintenance_get() { |
| | 1 | 19 | | HttpRequest req = {0}; |
| | 1 | 20 | | HttpResponse res = {0}; |
| | 1 | 21 | | strcpy(req.method, "GET"); |
| | 1 | 22 | | handle_maintenance_request(&req, &res); |
| | 1 | 23 | | assert(res.status_code == 200); |
| | 1 | 24 | | assert(strcmp(res.content_type, "application/json") == 0); |
| | 1 | 25 | | assert(strstr(res.body, "Routine oil change") != NULL); |
| | 1 | 26 | | printf("[PASS] handle_maintenance_request GET\n"); |
| | 1 | 27 | | } |
| | | 28 | | |
| | 1 | 29 | | void test_handle_maintenance_not_allowed() { |
| | 1 | 30 | | HttpRequest req = {0}; |
| | 1 | 31 | | HttpResponse res = {0}; |
| | 1 | 32 | | strcpy(req.method, "POST"); // GET dışında bir şey |
| | 1 | 33 | | handle_maintenance_request(&req, &res); |
| | 1 | 34 | | assert(res.status_code == 405); |
| | 1 | 35 | | assert(strstr(res.body, "Only GET supported") != NULL); |
| | 1 | 36 | | printf("[PASS] handle_maintenance_request 405\n"); |
| | 1 | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | int main() { |
| | 1 | 40 | | test_serialize_maintenance(); |
| | 1 | 41 | | test_handle_maintenance_get(); |
| | 1 | 42 | | test_handle_maintenance_not_allowed(); |
| | 1 | 43 | | return 0; |
| | | 44 | | } |