1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Integration tests temporarily disabled due to complex mocking requirements
// TODO: Implement proper test infrastructure with mock Docker and database
/*
use minifly_api::*;
use minifly_core::models::*;
use reqwest::StatusCode;
use serde_json::json;
mod common;
use common::*;
#[tokio::test]
async fn test_create_app() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create app request
let req = CreateAppRequest {
name: "test-app".to_string(),
org_slug: "test-org".to_string(),
};
let response = client
.post(&format!("{}/v1/apps", url))
.header("fly-region", "local")
.json(&req)
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::CREATED);
let app: App = response.json().await.expect("Failed to parse response");
assert_eq!(app.name, "test-app");
assert_eq!(app.organization.slug, "test-org");
assert_eq!(app.status, AppStatus::Running);
}
#[tokio::test]
async fn test_create_app_duplicate_name() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create first app
let req = CreateAppRequest {
name: "duplicate-app".to_string(),
org_slug: "test-org".to_string(),
};
let response = client
.post(&format!("{}/v1/apps", url))
.header("fly-region", "local")
.json(&req)
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::CREATED);
// Try to create duplicate
let response = client
.post(&format!("{}/v1/apps", url))
.header("fly-region", "local")
.json(&req)
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::BAD_REQUEST);
let error: ErrorResponse = response.json().await.expect("Failed to parse error");
assert!(error.error.contains("already exists"));
}
#[tokio::test]
async fn test_get_app() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create app first
let req = CreateAppRequest {
name: "get-test-app".to_string(),
org_slug: "test-org".to_string(),
};
client
.post(&format!("{}/v1/apps", url))
.header("fly-region", "local")
.json(&req)
.send()
.await
.expect("Failed to create app");
// Get the app
let response = client
.get(&format!("{}/v1/apps/get-test-app", url))
.header("fly-region", "local")
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::OK);
let app: App = response.json().await.expect("Failed to parse response");
assert_eq!(app.name, "get-test-app");
}
#[tokio::test]
async fn test_get_app_not_found() {
let (url, _handle) = start_test_server().await;
let client = test_client();
let response = client
.get(&format!("{}/v1/apps/nonexistent-app", url))
.header("fly-region", "local")
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::NOT_FOUND);
}
#[tokio::test]
async fn test_delete_app() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create app first
let req = CreateAppRequest {
name: "delete-test-app".to_string(),
org_slug: "test-org".to_string(),
};
client
.post(&format!("{}/v1/apps", url))
.header("fly-region", "local")
.json(&req)
.send()
.await
.expect("Failed to create app");
// Delete the app
let response = client
.delete(&format!("{}/v1/apps/delete-test-app", url))
.header("fly-region", "local")
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::NO_CONTENT);
// Verify it's gone
let response = client
.get(&format!("{}/v1/apps/delete-test-app", url))
.header("fly-region", "local")
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::NOT_FOUND);
}
#[tokio::test]
async fn test_delete_app_not_found() {
let (url, _handle) = start_test_server().await;
let client = test_client();
let response = client
.delete(&format!("{}/v1/apps/nonexistent-app", url))
.header("fly-region", "local")
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::NOT_FOUND);
}
#[tokio::test]
async fn test_region_header_required() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Try without region header
let req = CreateAppRequest {
name: "test-app".to_string(),
org_slug: "test-org".to_string(),
};
let response = client
.post(&format!("{}/v1/apps", url))
// No fly-region header
.json(&req)
.send()
.await
.expect("Failed to send request");
assert_status!(response, StatusCode::BAD_REQUEST);
let error: ErrorResponse = response.json().await.expect("Failed to parse error");
assert!(error.error.contains("region"));
}
*/