Skip to content

Commit 0a2f000

Browse files
committed
test(examples): add kitchen_sink example w/e2e tests
1 parent 70067b6 commit 0a2f000

22 files changed

+377
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: examples/kitchen_sink
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
pull_request:
9+
paths:
10+
- "examples/kitchen_sink/routes/**"
11+
- "examples/kitchen_sink/lib/**"
12+
- "examples/kitchen_sink/test/**"
13+
- "examples/kitchen_sink/e2e/**"
14+
- ".github/workflows/examples_kitchen_sink.yaml"
15+
- "packages/dart_frog/lib/**"
16+
- "packages/dart_frog/pubspec.yaml"
17+
- "packages/dart_frog_cli/lib/**"
18+
- "packages/dart_frog_cli/pubspec.yaml"
19+
branches:
20+
- main
21+
22+
jobs:
23+
build:
24+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
25+
with:
26+
working_directory: examples/kitchen_sink
27+
analyze_directories: "routes test"
28+
report_on: "routes"
29+
30+
docker:
31+
uses: ./.github/workflows/.docker_tests.yaml
32+
with:
33+
setup: rm pubspec_overrides.yaml && dart pub global activate --source path ../../packages/dart_frog_cli
34+
working_directory: examples/kitchen_sink

examples/kitchen_sink/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See https://www.dartlang.org/guides/libraries/private-files
2+
3+
# Files and directories created by pub
4+
.dart_tool/
5+
.packages
6+
pubspec.lock
7+
8+
# Files and directories created by dart_frog
9+
build/
10+
.dart_frog
11+
12+
# Test related files
13+
coverage/

examples/kitchen_sink/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Kitchen Sink
2+
3+
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
4+
[![License: MIT][license_badge]][license_link]
5+
[![Powered by Dart Frog](https://img.shields.io/endpoint?url=https://tinyurl.com/dartfrog-badge)](https://dartfrog.vgv.dev)
6+
7+
A kitchen sink example app built with `dart_frog`.
8+
9+
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
10+
[license_link]: https://opensource.org/licenses/MIT
11+
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
12+
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include: package:very_good_analysis/analysis_options.3.1.0.yaml
2+
analyzer:
3+
exclude:
4+
- build/**
5+
linter:
6+
rules:
7+
file_names: false
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'dart:io';
2+
3+
import 'package:http/http.dart' as http;
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
group('E2E', () {
8+
const greeting = 'Hello';
9+
test('GET / responds with "Hello"', () async {
10+
final response = await http.get(Uri.parse('http://localhost:8080'));
11+
expect(response.statusCode, equals(HttpStatus.ok));
12+
expect(response.body, equals(greeting));
13+
});
14+
15+
test('GET /favicon.ico responds with the favicon.ico', () async {
16+
final response = await http.get(
17+
Uri.parse('http://localhost:8080/favicon.ico'),
18+
);
19+
expect(response.statusCode, equals(HttpStatus.ok));
20+
expect(response.body, isNotEmpty);
21+
});
22+
23+
test('GET /greet/<name> responds with the "Hello <name>"', () async {
24+
const name = 'Frog';
25+
final response = await http.get(
26+
Uri.parse('http://localhost:8080/greet/$name'),
27+
);
28+
expect(response.statusCode, equals(HttpStatus.ok));
29+
expect(response.body, equals('Hello $name'));
30+
});
31+
32+
test('GET /users/<id> responds with the "Hello user <id>"', () async {
33+
const id = 'id';
34+
final response = await http.get(
35+
Uri.parse('http://localhost:8080/users/$id'),
36+
);
37+
expect(response.statusCode, equals(HttpStatus.ok));
38+
expect(response.body, equals('$greeting user $id'));
39+
});
40+
41+
test('GET /users/<id>/<name> responds with the "Hello <name> (user <id>)"',
42+
() async {
43+
const id = 'id';
44+
const name = 'Frog';
45+
final response = await http.get(
46+
Uri.parse('http://localhost:8080/users/$id/$name'),
47+
);
48+
expect(response.statusCode, equals(HttpStatus.ok));
49+
expect(response.body, equals('$greeting $name (user $id)'));
50+
});
51+
52+
test('GET /api/pets responds with unauthorized when header is missing',
53+
() async {
54+
final response = await http.get(
55+
Uri.parse('http://localhost:8080/api/pets'),
56+
);
57+
expect(response.statusCode, equals(HttpStatus.unauthorized));
58+
});
59+
60+
test('GET /api/pets responds with "Hello pets"', () async {
61+
final response = await http.get(
62+
Uri.parse('http://localhost:8080/api/pets'),
63+
headers: {HttpHeaders.authorizationHeader: 'token'},
64+
);
65+
expect(response.statusCode, equals(HttpStatus.ok));
66+
expect(response.body, equals('$greeting pets'));
67+
});
68+
69+
test('GET /api/pets/<name> responds with "Hello <name>"', () async {
70+
const name = 'Frog';
71+
final response = await http.get(
72+
Uri.parse('http://localhost:8080/api/pets/$name'),
73+
headers: {HttpHeaders.authorizationHeader: 'token'},
74+
);
75+
expect(response.statusCode, equals(HttpStatus.ok));
76+
expect(response.body, equals('$greeting $name'));
77+
});
78+
});
79+
}
1.67 KB
Binary file not shown.

examples/kitchen_sink/pubspec.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: kitchen_sink
2+
description: A kitchen sink example with Dart Frog.
3+
version: 1.0.0+1
4+
publish_to: none
5+
6+
environment:
7+
sdk: ">=2.18.0 <3.0.0"
8+
9+
dependencies:
10+
dart_frog: ^0.2.0
11+
12+
dev_dependencies:
13+
http: ^0.13.5
14+
mocktail: ^0.3.0
15+
test: ^1.19.2
16+
very_good_analysis: ^3.1.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependency_overrides:
2+
dart_frog:
3+
path: ../../packages/dart_frog
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:dart_frog/dart_frog.dart';
2+
3+
const _greeting = 'Hello';
4+
5+
Handler middleware(Handler handler) {
6+
return handler.use(provider<String>((_) => _greeting));
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'dart:io';
2+
3+
import 'package:dart_frog/dart_frog.dart';
4+
5+
Handler middleware(Handler handler) {
6+
return (context) {
7+
if (!context.request.headers.containsKey(HttpHeaders.authorizationHeader)) {
8+
return Response(statusCode: HttpStatus.unauthorized);
9+
}
10+
return handler(context);
11+
};
12+
}

0 commit comments

Comments
 (0)