Skip to content

Commit

Permalink
Perform url decode to allow dot values in json key
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Apr 28, 2024
1 parent 443d394 commit ebdf68a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/domain/services/script_executor_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScriptExecutorService {

double? _getValueFromJsonPath(String json, String jsonPath) {
Map<String, dynamic> map = jsonDecode(json);
List<String> keys = jsonPath.split('.');
List<String> keys = jsonPath.split('.').map((e) => Uri.decodeFull(e)).toList();
dynamic current = map;

for (String key in keys) {
Expand Down
21 changes: 21 additions & 0 deletions test/domain/services/script_executor_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ void main() {

expect(value, equals(3.0));
});

test('should fetch data from script for dot values', () async {
const String script = 'test_script';
when(mockDSLParser.parse(script)).thenReturn(
ParsedScript(
url: 'https://api.mfapi.in/mf/128074/latest?user=11',
headers: {'Authorization': 'Bearer'},
responsePath: 'Global Quote.05%2e price',
),
);
final scriptExecutorService = ScriptExecutorService.withMock(
client: mockClient, dslParser: mockDSLParser);
when(mockClient.get(
Uri.parse('https://api.mfapi.in/mf/128074/latest?user=11'),
headers: {'Authorization': 'Bearer'}))
.thenAnswer((_) async => http.Response('{"Global Quote":{"05. price": "3"}}', 200));
final value =
await scriptExecutorService.executeScript(script: script);

expect(value, equals(3.0));
});
}

0 comments on commit ebdf68a

Please sign in to comment.