feat: change api framework to angel3.

This commit is contained in:
2021-12-17 18:24:32 +08:00
parent 8face6f724
commit ed863ecb41
39 changed files with 1008 additions and 368 deletions
+43
View File
@@ -0,0 +1,43 @@
import 'package:dde_gesture_manager_api/dde_gesture_manager_api.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_test/angel3_test.dart';
import 'package:test/test.dart';
// Angel also includes facilities to make testing easier.
//
// `package:angel_test` ships a client that can test
// both plain HTTP and WebSockets.
//
// Tests do not require your server to actually be mounted on a port,
// so they will run faster than they would in other frameworks, where you
// would have to first bind a socket, and then account for network latency.
//
// See the documentation here:
// https://github.com/angel-dart/test
//
// If you are unfamiliar with Dart's advanced testing library, you can read up
// here:
// https://github.com/dart-lang/test
void main() async {
late TestClient client;
setUp(() async {
var app = Angel();
await app.configure(configureServer);
client = await connectTo(app);
});
tearDown(() async {
await client.close();
});
test('index returns 200', () async {
// Request a resource at the given path.
var response = await client.get(Uri.parse('/'));
// Expect a 200 response.
expect(response, hasStatus(200));
});
}
-38
View File
@@ -1,38 +0,0 @@
import 'package:conduit_test/conduit_test.dart';
import 'package:dde_gesture_manager/dde_gesture_manager.dart';
export 'package:conduit/conduit.dart';
export 'package:conduit_test/conduit_test.dart';
export 'package:dde_gesture_manager/dde_gesture_manager.dart';
export 'package:test/test.dart';
/// A testing harness for dde_gesture_manager.
///
/// A harness for testing an conduit application. Example test file:
///
/// void main() {
/// Harness harness = Harness()..install();
///
/// test("GET /path returns 200", () async {
/// final response = await harness.agent.get("/path");
/// expectResponse(response, 200);
/// });
/// }
///
class Harness extends TestHarness<DdeGestureManagerChannel> with TestHarnessORMMixin {
@override
ManagedContext? get context => channel?.context;
@override
Future onSetUp() async {
await resetData();
}
@override
Future onTearDown() async {}
@override
Future seed() async {
// restore any static data. called by resetData.
}
}
-32
View File
@@ -1,32 +0,0 @@
import 'harness/app.dart';
Future main() async {
final harness = Harness()..install();
tearDown(() async {
await harness.resetData();
});
test("POST /model", () async {
final response = await harness.agent!.post("/model", body: {"name": "Bob"});
expect(
response,
hasResponse(200,
body: {"id": isNotNull, "name": "Bob", "createdAt": isTimestamp}));
});
test("GET /model/:id returns previously created object", () async {
var response = await harness.agent!.post("/model", body: {"name": "Bob"});
final createdObject = response?.body.as();
response =
await harness.agent!.request("/model/${createdObject["id"]}").get();
expect(
response,
hasResponse(200, body: {
"id": createdObject["id"],
"name": createdObject["name"],
"createdAt": createdObject["createdAt"]
}));
});
}