mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
tests: update js runtime notifier tests
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:apidash/services/flutter_js_service.dart';
|
import 'package:apidash/providers/providers.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:apidash_core/apidash_core.dart';
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'package:apidash/models/models.dart';
|
import 'package:apidash/models/models.dart';
|
||||||
import 'package:apidash/utils/pre_post_script_utils.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
// Base HTTP Request Model for GET request
|
// Base HTTP Request Model for GET request
|
||||||
const HttpRequestModel baseGetRequest = HttpRequestModel(
|
const HttpRequestModel baseGetRequest = HttpRequestModel(
|
||||||
@@ -41,6 +41,38 @@ const HttpRequestModel baseGraphQLRequest = HttpRequestModel(
|
|||||||
body: '{"variables": {"id": "123"}}',
|
body: '{"variables": {"id": "123"}}',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Local test helper wrappers replicating the old top-level API but using the notifier.
|
||||||
|
// NOTE: File migrated from pre_post_script_utils_test.dart after refactor to provider-based runtime.
|
||||||
|
late ProviderContainer _testContainer;
|
||||||
|
|
||||||
|
Future<RequestModel> handlePreRequestScript(
|
||||||
|
RequestModel requestModel,
|
||||||
|
EnvironmentModel? originalEnvironmentModel,
|
||||||
|
void Function(EnvironmentModel, List<EnvironmentVariableModel>)? updateEnv,
|
||||||
|
) async {
|
||||||
|
return _testContainer
|
||||||
|
.read(jsRuntimeNotifierProvider.notifier)
|
||||||
|
.handlePreRequestScript(
|
||||||
|
requestModel,
|
||||||
|
originalEnvironmentModel,
|
||||||
|
updateEnv,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<RequestModel> handlePostResponseScript(
|
||||||
|
RequestModel requestModel,
|
||||||
|
EnvironmentModel? originalEnvironmentModel,
|
||||||
|
void Function(EnvironmentModel, List<EnvironmentVariableModel>)? updateEnv,
|
||||||
|
) async {
|
||||||
|
return _testContainer
|
||||||
|
.read(jsRuntimeNotifierProvider.notifier)
|
||||||
|
.handlePostResponseScript(
|
||||||
|
requestModel,
|
||||||
|
originalEnvironmentModel,
|
||||||
|
updateEnv,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// HTTP Response Model for successful login
|
// HTTP Response Model for successful login
|
||||||
const HttpResponseModel successLoginResponse = HttpResponseModel(
|
const HttpResponseModel successLoginResponse = HttpResponseModel(
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
@@ -306,7 +338,10 @@ RequestModel requestWithDataProcessingScript = RequestModel(
|
|||||||
void main() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
initializeJsRuntime();
|
_testContainer = ProviderContainer();
|
||||||
|
});
|
||||||
|
tearDownAll(() {
|
||||||
|
_testContainer.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: For Pre-request Script add individual tests for every `ad` object methods
|
//TODO: For Pre-request Script add individual tests for every `ad` object methods
|
||||||
@@ -1257,11 +1292,8 @@ void main() {
|
|||||||
|
|
||||||
group('Pre-request Script - Request Modification Tests', () {
|
group('Pre-request Script - Request Modification Tests', () {
|
||||||
test('should modify headers correctly', () async {
|
test('should modify headers correctly', () async {
|
||||||
List<EnvironmentVariableModel>? capturedValues;
|
|
||||||
void mockUpdateEnv(
|
void mockUpdateEnv(
|
||||||
EnvironmentModel envModel, List<EnvironmentVariableModel> values) {
|
EnvironmentModel envModel, List<EnvironmentVariableModel> values) {}
|
||||||
capturedValues = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
final result = await handlePreRequestScript(
|
final result = await handlePreRequestScript(
|
||||||
requestWithHeaderModificationScript,
|
requestWithHeaderModificationScript,
|
||||||
Reference in New Issue
Block a user