2021-05-15 13:28:26 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_static/angel3_static.dart';
|
|
|
|
import 'package:angel3_test/angel3_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
|
|
|
|
2021-05-01 03:53:04 +00:00
|
|
|
void main() async {
|
|
|
|
late TestClient client;
|
|
|
|
late String swaggerUiCssContents, swaggerTestJsContents;
|
2017-06-20 19:57:03 +00:00
|
|
|
|
|
|
|
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
|
2024-10-12 10:35:14 +00:00
|
|
|
var app = Protevus();
|
|
|
|
app.logger = Logger('protevus')..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 {
|
2021-03-08 13:22:29 +00:00
|
|
|
var response = await client.get(Uri.parse('/swagger/swagger-ui.css'));
|
2017-06-20 19:57:03 +00:00
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response, hasBody(swaggerUiCssContents));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('get a file without prefix in name', () async {
|
2021-03-08 13:22:29 +00:00
|
|
|
var response = await client.get(Uri.parse('/swagger/test.js'));
|
2017-06-20 19:57:03 +00:00
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response, hasBody(swaggerTestJsContents));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('trailing slash at root', () async {
|
2021-03-08 13:22:29 +00:00
|
|
|
var response = await client.get(Uri.parse('/swagger'));
|
2017-06-20 19:57:03 +00:00
|
|
|
var body1 = response.body;
|
|
|
|
print('Response #1: $body1');
|
|
|
|
|
2021-03-08 13:22:29 +00:00
|
|
|
response = await client.get(Uri.parse('/swagger/'));
|
2017-06-20 19:57:03 +00:00
|
|
|
var body2 = response.body;
|
|
|
|
print('Response #2: $body2');
|
|
|
|
|
|
|
|
expect(body1, body2);
|
|
|
|
});
|
|
|
|
}
|