Skip to content

Commit

Permalink
fixup! TF-3278 Handle open app via deep link at MailboxDashboard screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Nov 20, 2024
1 parent 08f8961 commit cc2c216
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
4 changes: 3 additions & 1 deletion lib/main/deep_links/deep_links_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class DeepLinksManager with MessageDialogActionMixin {

DeepLinkData? parseDeepLink(String url) {
try {
final updatedUrl = url.replaceFirst(
final decodedUrl = Uri.decodeFull(url);

final updatedUrl = decodedUrl.replaceFirst(
OIDCConstant.twakeWorkplaceUrlScheme,
'https',
);
Expand Down
41 changes: 29 additions & 12 deletions test/main/deep_links/deep_links_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ void main() {
final deepLinkManager = DeepLinksManager(mockAutoSignInViaDeepLinkInteractor);

group('DeepLinksManager::parseDeepLink::test', () {
test('Valid deep link with multiple query parameters', () {
const deepLink = 'twake.mail://openApp?access_token=ey123456&refresh_token=ey7890&id_token=token&expires_in=3600&[email protected]';
test('SHOULD parse valid URL with all parameters', () {
const url = 'twake.mail://openApp?access_token=ey123456&refresh_token=ey7890&id_token=token&expires_in=3600&[email protected]';
final expectedData = DeepLinkData(
action: 'openapp',
accessToken: 'ey123456',
Expand All @@ -21,31 +21,48 @@ void main() {
expiresIn: 3600,
username: '[email protected]',
);
final deepLinkData = deepLinkManager.parseDeepLink(deepLink);
final deepLinkData = deepLinkManager.parseDeepLink(url);

expect(deepLinkData, equals(expectedData));
});

test('Deep link with no query parameters', () {
const deepLink = 'twake.mail://openApp';
test('SHOULD handle URL with missing parameters', () {
const url = 'twake.mail://openApp';
final expectedData = DeepLinkData(action: 'openapp');
final deepLinkData = deepLinkManager.parseDeepLink(deepLink);
final deepLinkData = deepLinkManager.parseDeepLink(url);

expect(deepLinkData, expectedData);
});

test('Deep link with one query parameter', () {
const deepLink = 'twake.mail://openApp?access_token=ey123456';
test('SHOULD parse valid URL with one query parameter', () {
const url = 'twake.mail://openApp?access_token=ey123456';
final expectedData = DeepLinkData(action: 'openapp', accessToken: 'ey123456',);
final deepLinkData = deepLinkManager.parseDeepLink(deepLink);
final deepLinkData = deepLinkManager.parseDeepLink(url);

expect(deepLinkData, equals(expectedData));
});

test('Invalid deep link format', () {
const deepLink = 'Invalid link: invalid';
final deepLinkData = deepLinkManager.parseDeepLink(deepLink);
test('SHOULD return null for an invalid URL', () {
const url = 'Invalid link: invalid';
final deepLinkData = deepLinkManager.parseDeepLink(url);
expect(deepLinkData, isNull);
});

test('SHOULD decode encoded URL correctly', () {
const encodedUrl = 'twake.mail://openApp?access_token=abc%20123&username=test%20user';
final result = deepLinkManager.parseDeepLink(encodedUrl);

expect(result, isNotNull);
expect(result!.accessToken, 'abc 123');
expect(result.username, 'test user');
});

test('SHOULD return null WHEN Uri.decodeFull throws an exception', () {
const invalidUrl = 'twake-workplace://login?access_token=%ZZ';

final result = deepLinkManager.parseDeepLink(invalidUrl);

expect(result, isNull);
});
});
}

0 comments on commit cc2c216

Please sign in to comment.