修复代码格式

This commit is contained in:
2026-04-03 20:56:21 +08:00
parent d0f81bf18e
commit 668199ce3f
6 changed files with 87 additions and 67 deletions

View File

@@ -43,7 +43,9 @@ void main() {
});
test('GET /api/v1/echo/<message> with special characters', () async {
final response = await http.get(Uri.parse('$host/api/v1/echo/test%20message'));
final response = await http.get(
Uri.parse('$host/api/v1/echo/test%20message'),
);
expect(response.statusCode, 200);
expect(response.body, contains('test'));
});
@@ -63,7 +65,9 @@ void main() {
});
test('GET /api/v1/album/<id> with invalid id returns 400', () async {
final response = await http.get(Uri.parse('$host/api/v1/album/invalid_id'));
final response = await http.get(
Uri.parse('$host/api/v1/album/invalid_id'),
);
expect(response.statusCode, 400);
expect(response.body, contains('Invalid album id'));
});
@@ -75,7 +79,9 @@ void main() {
});
test('GET /api/v1/album/<id>/photo with invalid id returns 400', () async {
final response = await http.get(Uri.parse('$host/api/v1/album/invalid_id/photo'));
final response = await http.get(
Uri.parse('$host/api/v1/album/invalid_id/photo'),
);
expect(response.statusCode, 400);
expect(response.body, contains('Invalid album id'));
});
@@ -85,16 +91,18 @@ void main() {
final listResponse = await http.get(Uri.parse('$host/api/v1/album'));
expect(listResponse.statusCode, 200);
final albums = jsonDecode(listResponse.body) as List;
// Skip test if no albums exist
if (albums.isEmpty) {
return;
}
final album = albums.first as Map<String, dynamic>;
final albumId = album['id'];
final response = await http.get(Uri.parse('$host/api/v1/album/$albumId/photo'));
final response = await http.get(
Uri.parse('$host/api/v1/album/$albumId/photo'),
);
expect(response.statusCode, 200);
expect(response.headers['content-type'], contains('application/json'));
final photos = jsonDecode(response.body) as List;
@@ -122,41 +130,46 @@ void main() {
expect(response.body, contains('Invalid photo id'));
});
test('GET /api/v1/photo/<id>/file with non-existent id returns 404', () async {
// Use a hash that won't match any file
final response = await http.get(Uri.parse('$host/api/v1/photo/12345/file'));
expect(response.statusCode, 404);
expect(response.body, contains('Photo not found'));
});
test(
'GET /api/v1/photo/<id>/file with non-existent id returns 404',
() async {
// Use a hash that won't match any file
final response = await http.get(
Uri.parse('$host/api/v1/photo/12345/file'),
);
expect(response.statusCode, 404);
expect(response.body, contains('Photo not found'));
},
);
test('GET /api/v1/photo/<id>/file with valid id returns file', () async {
// First get a valid photo id from an album
final albumResponse = await http.get(Uri.parse('$host/api/v1/album'));
expect(albumResponse.statusCode, 200);
final albums = jsonDecode(albumResponse.body) as List;
// Skip test if no albums exist
if (albums.isEmpty) {
return;
}
final album = albums.first as Map<String, dynamic>;
final albumId = album['id'];
final photosResponse = await http.get(
Uri.parse('$host/api/v1/album/$albumId/photo'),
);
expect(photosResponse.statusCode, 200);
final photos = jsonDecode(photosResponse.body) as List;
// Skip test if no photos exist
if (photos.isEmpty) {
return;
}
final photo = photos.first as Map<String, dynamic>;
final photoId = photo['id'];
final response = await http.get(
Uri.parse('$host/api/v1/photo/$photoId/file'),
);