Skip to content

Commit

Permalink
feat: add support web (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dungngminh authored Nov 7, 2024
1 parent ef7ae0c commit e566e5e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 1.0.3 (2024-11-06)
## 1.1.0 (2024-11-07)

- Remove `dart:io` dependency to support web.
- Update more test.

## 1.0.3 (2024-11-07)

- Return `null` when provided `T` is incorrect.
- Update more test.
Expand Down
6 changes: 2 additions & 4 deletions lib/src/simple_remote_config.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart';
import 'package:simple_remote_config/src/simple_remote_config_exception.dart';
import 'package:simple_remote_config/simple_remote_config.dart';

/// A [SimpleRemoteConfig] class that fetches a JSON config from a URL and
/// provides a way to access the config values.
Expand Down Expand Up @@ -43,8 +42,7 @@ class SimpleRemoteConfig {
} catch (e) {
throw SimpleRemoteConfigException(
message: switch (e) {
SocketException() => 'No internet connection',
FormatException() => 'Invalid remote config format',
FormatException() => 'Invalid remote config',
_ => 'Error when handling: $e',
});
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.4.0 <4.0.0"
dart: ">=3.5.0 <4.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: simple_remote_config
description: A simple plugin for helping you to change your application's behaviors, settings,.. without updating the application via network JSON.
version: 1.0.3
version: 1.1.0
topics: [remote, config]
issue_tracker: https://github.com/TheQuantumCrew/simple_remote_config/issues
repository: https://github.com/TheQuantumCrew/simple_remote_config
Expand Down
19 changes: 9 additions & 10 deletions test/simple_remote_config_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:simple_remote_config/src/simple_remote_config.dart';
Expand Down Expand Up @@ -90,33 +88,34 @@ void main() {
);
});

test('initialize throws SimpleRemoteConfigException on SocketException',
test(
'initialize with invalid network JSON throws SimpleRemoteConfigException on FormatException',
() async {
final mockClient = MockClient((request) async {
throw SocketException('No internet connection');
return http.Response('Invalid JSON', 200);
});
final config = SimpleRemoteConfig(client: mockClient);

expect(
() async =>
await config.initilize(configUrl: 'http://example.com/config'),
throwsA(isA<SimpleRemoteConfigException>()
.having((e) => e.message, 'message', 'No internet connection')),
.having((e) => e.message, 'message', 'Invalid remote config')),
);
});

test('initialize throws SimpleRemoteConfigException on FormatException',
test(
'initialize with invalid config url throws SimpleRemoteConfigException on FormatException',
() async {
final mockClient = MockClient((request) async {
return http.Response('Invalid JSON', 200);
});
final config = SimpleRemoteConfig(client: mockClient);

expect(
() async =>
await config.initilize(configUrl: 'http://example.com/config'),
throwsA(isA<SimpleRemoteConfigException>().having(
(e) => e.message, 'message', 'Invalid remote config format')),
() async => await config.initilize(configUrl: 'example.com/config'),
throwsA(isA<SimpleRemoteConfigException>()
.having((e) => e.message, 'message', 'Invalid remote config')),
);
});
});
Expand Down

0 comments on commit e566e5e

Please sign in to comment.