Skip to content

Commit

Permalink
fix(notifications): allow configuration when auth token is expired (#…
Browse files Browse the repository at this point in the history
…5117)

Co-authored-by: Nika Hassani <[email protected]>
  • Loading branch information
NikaHsn and Nika Hassani authored Jul 9, 2024
1 parent 7cca276 commit 15aa405
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ class PinpointProvider implements ServiceProviderClient {
// `AnalyticsException` converts `AWSHttpException` to `NetworkException`.
} on NetworkException catch (e) {
_logger.error('Network problem when registering device: ', e);
// This is to allow configuration if `EndpointClient.updateEndpoint()`
// throws UnknownException due to expired token.
// the underlying exception is `NotAuthorizedException` with
// `Invalid login token. Token expired` message.
} on UnknownException catch (e) {
_logger.error(
'Could not update Pinpoint endpoint to register the device: ',
e,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,48 @@ void main() {
verify(mockEndpointClient.updateEndpoint);
});

test('registerDevice should run successfully when token is expired',
() async {
when(
() => mockAmplifyAuthProviderRepository.getAuthProvider(
APIAuthorizationType.iam.authProviderToken,
),
).thenReturn(awsIamAmplifyAuthProvider);
when(
() => mockAnalyticsClient.init(
pinpointAppId: any(named: 'pinpointAppId'),
region: any(named: 'region'),
authProvider: any(named: 'authProvider'),
),
).thenAnswer((realInvocation) async {});

final mockEndpointClient = MockEndpointClient();

when(mockEndpointClient.updateEndpoint)
.thenThrow(const UnknownException('message'));

when(
() => mockAnalyticsClient.endpointClient,
).thenReturn(mockEndpointClient);

await expectLater(
pinpointProvider.init(
config: notificationsPinpointConfig,
authProviderRepo: mockAmplifyAuthProviderRepository,
analyticsClient: mockAnalyticsClient,
),
completes,
);

expect(
pinpointProvider.registerDevice(
'',
),
completes,
);
verify(mockEndpointClient.updateEndpoint);
});

test('recordEvent should run successfully', () async {
when(
() => mockAmplifyAuthProviderRepository.getAuthProvider(
Expand Down

0 comments on commit 15aa405

Please sign in to comment.