2017-06-20 19:57:03 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_static/angel_static.dart';
|
|
|
|
import 'package:angel_test/angel_test.dart';
|
2017-09-23 21:57:54 +00:00
|
|
|
import 'package:file/file.dart';
|
|
|
|
import 'package:file/local.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2017-06-20 19:57:03 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
final Directory swaggerUiDistDir =
|
2017-09-23 21:57:54 +00:00
|
|
|
const LocalFileSystem().directory('test/node_modules/swagger-ui-dist');
|
2017-06-20 19:57:03 +00:00
|
|
|
|
|
|
|
main() async {
|
|
|
|
TestClient client;
|
|
|
|
String swaggerUiCssContents, swaggerTestJsContents;
|
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
// Load file contents
|
2017-09-23 21:57:54 +00:00
|
|
|
swaggerUiCssContents = await const LocalFileSystem()
|
|
|
|
.file(swaggerUiDistDir.uri.resolve('swagger-ui.css'))
|
|
|
|
.readAsString();
|
|
|
|
swaggerTestJsContents = await const LocalFileSystem()
|
|
|
|
.file(swaggerUiDistDir.uri.resolve('test.js'))
|
|
|
|
.readAsString();
|
2017-06-20 19:57:03 +00:00
|
|
|
|
|
|
|
// Initialize app
|
2019-05-02 23:29:09 +00:00
|
|
|
var app = Angel();
|
|
|
|
app.logger = Logger('angel')..onRecord.listen(print);
|
2017-09-23 21:57:54 +00:00
|
|
|
|
2018-08-28 14:58:28 +00:00
|
|
|
app.fallback(
|
2019-05-02 23:29:09 +00:00
|
|
|
VirtualDirectory(app, const LocalFileSystem(),
|
2017-09-23 21:57:54 +00:00
|
|
|
source: swaggerUiDistDir, publicPath: 'swagger/')
|
|
|
|
.handleRequest,
|
|
|
|
);
|
2017-06-20 19:57:03 +00:00
|
|
|
|
|
|
|
app.dumpTree();
|
|
|
|
client = await connectTo(app);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() => client.close());
|
|
|
|
|
|
|
|
test('prefix is not replaced in file paths', () async {
|
|
|
|
var response = await client.get('/swagger/swagger-ui.css');
|
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response, hasBody(swaggerUiCssContents));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('get a file without prefix in name', () async {
|
|
|
|
var response = await client.get('/swagger/test.js');
|
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response, hasBody(swaggerTestJsContents));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('trailing slash at root', () async {
|
|
|
|
var response = await client.get('/swagger');
|
|
|
|
var body1 = response.body;
|
|
|
|
print('Response #1: $body1');
|
|
|
|
|
|
|
|
response = await client.get('/swagger/');
|
|
|
|
var body2 = response.body;
|
|
|
|
print('Response #2: $body2');
|
|
|
|
|
|
|
|
expect(body1, body2);
|
|
|
|
});
|
|
|
|
}
|