-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create abstract layer for deep_link_client to simplify other im…
…plementations (#1158)
- Loading branch information
1 parent
5354d19
commit ee9bc1b
Showing
22 changed files
with
298 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: firebase_deep_link_client | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "flutter_news_example/packages/deep_link_client/firebase_deep_link_client/**" | ||
- ".github/workflows/firebase_deep_link_client.yaml" | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 | ||
with: | ||
flutter_version: 3.22.2 | ||
working_directory: flutter_news_example/packages/deep_link_client/firebase_deep_link_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
flutter_news_example/packages/deep_link_client/deep_link_client/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:very_good_analysis/analysis_options.5.1.0.yaml |
2 changes: 2 additions & 0 deletions
2
flutter_news_example/packages/deep_link_client/deep_link_client/lib/deep_link_client.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'src/deep_link_client.dart'; | ||
export 'src/deep_link_service.dart'; |
11 changes: 11 additions & 0 deletions
11
...ter_news_example/packages/deep_link_client/deep_link_client/lib/src/deep_link_client.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// {@template deep_link_client} | ||
/// A generic DeepLinkClient interface. | ||
/// {@endtemplate} | ||
abstract class DeepLinkClient { | ||
/// Provides a stream of URIs intercepted by the app. Will emit the latest | ||
/// received value (if any) as first. | ||
Stream<Uri> get deepLinkStream; | ||
|
||
/// Retrieves the initial deep link if present. | ||
Future<Uri?> getInitialLink(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
flutter_news_example/packages/deep_link_client/deep_link_client/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: deep_link_client | ||
description: A deep link client interface | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ">=3.0.0 <4.0.0" | ||
|
||
dependencies: | ||
equatable: ^2.0.5 | ||
rxdart: ^0.27.5 | ||
|
||
dev_dependencies: | ||
mocktail: ^1.0.4 | ||
test: ^1.25.8 | ||
very_good_analysis: ^6.0.0 |
91 changes: 91 additions & 0 deletions
91
..._news_example/packages/deep_link_client/deep_link_client/test/deep_link_service_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:deep_link_client/deep_link_client.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
typedef OnAppLinkFunction = void Function(Uri uri, String stringUri); | ||
|
||
class MockDeepLinkClient extends Mock implements DeepLinkClient {} | ||
|
||
void main() { | ||
late DeepLinkClient deepLinkClient; | ||
late StreamController<Uri> onDeepLinkStreamController; | ||
|
||
setUp(() { | ||
deepLinkClient = MockDeepLinkClient(); | ||
onDeepLinkStreamController = StreamController<Uri>(); | ||
when(() => deepLinkClient.deepLinkStream) | ||
.thenAnswer((_) => onDeepLinkStreamController.stream); | ||
}); | ||
|
||
tearDown(() { | ||
onDeepLinkStreamController.close(); | ||
}); | ||
|
||
group('DeepLinkService', () { | ||
test('retrieves and publishes latest link if present', () { | ||
final expectedUri = Uri.https('ham.app.test', '/test/path'); | ||
when(deepLinkClient.getInitialLink).thenAnswer( | ||
(_) => Future.value(expectedUri), | ||
); | ||
|
||
final service = DeepLinkService(deepLinkClient: deepLinkClient); | ||
expect(service.deepLinkStream, emits(expectedUri)); | ||
|
||
// Testing also the replay of the latest value. | ||
expect(service.deepLinkStream, emits(expectedUri)); | ||
}); | ||
|
||
test('publishes DeepLinkClientFailure to stream if upstream throws', () { | ||
final expectedError = Error(); | ||
final expectedStackTrace = StackTrace.current; | ||
|
||
when(deepLinkClient.getInitialLink).thenAnswer((_) { | ||
return Future.error(expectedError, expectedStackTrace); | ||
}); | ||
|
||
final deepLinkService = DeepLinkService(deepLinkClient: deepLinkClient); | ||
expect( | ||
deepLinkService.deepLinkStream, | ||
emitsError( | ||
isA<DeepLinkClientFailure>() | ||
.having((failure) => failure.error, 'error', expectedError), | ||
), | ||
); | ||
}); | ||
|
||
test('publishes values received through onAppLink callback', () { | ||
final expectedUri1 = Uri.https('ham.app.test', '/test/1'); | ||
final expectedUri2 = Uri.https('ham.app.test', '/test/2'); | ||
|
||
when(deepLinkClient.getInitialLink).thenAnswer((_) async => null); | ||
|
||
final deepLinkService = DeepLinkService(deepLinkClient: deepLinkClient); | ||
|
||
expect( | ||
deepLinkService.deepLinkStream, | ||
emitsInOrder( | ||
<Uri>[expectedUri1, expectedUri1, expectedUri2, expectedUri1], | ||
), | ||
); | ||
|
||
onDeepLinkStreamController | ||
..add(expectedUri1) | ||
..add(expectedUri1) | ||
..add(expectedUri2) | ||
..add(expectedUri1); | ||
}); | ||
}); | ||
|
||
group('DeepLinkClientFailure', () { | ||
final error = Exception('errorMessage'); | ||
|
||
test('has correct props', () { | ||
expect( | ||
DeepLinkClientFailure(error).props, | ||
[error], | ||
); | ||
}); | ||
}); | ||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...le/packages/deep_link_client/firebase_deep_link_client/lib/firebase_deep_link_client.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'src/firebase_deep_link_client.dart'; |
27 changes: 27 additions & 0 deletions
27
...ackages/deep_link_client/firebase_deep_link_client/lib/src/firebase_deep_link_client.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// ignore_for_file: deprecated_member_use | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:deep_link_client/deep_link_client.dart'; | ||
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart'; | ||
|
||
/// {@template firebase_deep_link_client} | ||
/// A FirebaseDynamicLinks implementation of [DeepLinkClient]. | ||
/// {@endtemplate} | ||
class FirebaseDeepLinkClient implements DeepLinkClient { | ||
/// {@macro firebase_deep_link_client} | ||
FirebaseDeepLinkClient({required FirebaseDynamicLinks firebaseDynamicLinks}) | ||
: _firebaseDynamicLinks = firebaseDynamicLinks; | ||
|
||
final FirebaseDynamicLinks _firebaseDynamicLinks; | ||
|
||
@override | ||
Stream<Uri> get deepLinkStream => | ||
_firebaseDynamicLinks.onLink.map((event) => event.link); | ||
|
||
@override | ||
Future<Uri?> getInitialLink() async { | ||
final deepLink = await _firebaseDynamicLinks.getInitialLink(); | ||
return deepLink?.link; | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...le/packages/deep_link_client/pubspec.yaml → ...nt/firebase_deep_link_client/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.