diff --git a/supertest/lib/supertest.dart b/supertest/lib/supertest.dart index cfd8d2ce..10dcba67 100644 --- a/supertest/lib/supertest.dart +++ b/supertest/lib/supertest.dart @@ -14,6 +14,24 @@ abstract interface class Tester { Object? body, }); + Future put( + String path, { + Map? headers, + Object? body, + }); + + Future patch( + String path, { + Map? headers, + Object? body, + }); + + Future delete( + String path, { + Map? headers, + Object? body, + }); + Future get( String path, { Map? headers, @@ -41,12 +59,36 @@ class _$TesterImpl extends Tester { Map? headers, }) => http.get(getUri(path), headers: headers); + + @override + Future delete( + String path, { + Map? headers, + Object? body, + }) => + http.delete(getUri(path), headers: headers, body: body); + + @override + Future patch( + String path, { + Map? headers, + Object? body, + }) => + http.patch(getUri(path), headers: headers, body: body); + + @override + Future put( + String path, { + Map? headers, + Object? body, + }) => + http.put(getUri(path), headers: headers, body: body); } class TestAgent { static _$TesterImpl? _instance; - static Future create(TestApp app) async { + static Future create(TestApp app) async { if (_instance != null) { await _instance!._server.close(); _instance = null; @@ -77,6 +119,6 @@ Uri getServerUri(HttpServer server) { } Future request(T app) async { - final tester = await TestAgent.create((app as dynamic).handleRequest); + final tester = await TestAgent.create((app as dynamic).handleRequest); return tester; } diff --git a/test/http/res.json_test.dart b/test/http/res.json_test.dart index abdb91ad..7f82e6d9 100644 --- a/test/http/res.json_test.dart +++ b/test/http/res.json_test.dart @@ -8,14 +8,11 @@ void main() { group('.json(Object)', () { test('should not override previous Content-Types', () async { final app = Pharaoh().get('/', (req, res) { - return res - .type(ContentType.parse('application/vnd.example+json')) - .json({"hello": "world"}); + return res.type(ContentType.parse('application/vnd.example+json')).json({"hello": "world"}); }); - final result = await (await request(app)).get('/'); - expect(result.headers['content-type'], - 'application/vnd.example+json; charset=utf-8'); + final result = await (await request(app)).get('/'); + expect(result.headers['content-type'], 'application/vnd.example+json; charset=utf-8'); expect(result.statusCode, 200); expect(result.body, '{"hello":"world"}'); }); @@ -26,7 +23,7 @@ void main() { next(res.json(null)); }); - final result = await (await request(app)).get('/'); + final result = await (await request(app)).get('/'); expect(result.statusCode, 200); expect(result.body, 'null'); });