Skip to content

Commit 90a441a

Browse files
Update token improvement.
1 parent 6470ad3 commit 90a441a

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public PluginEventsProvider()
2525
CrossFirebasePushNotification.Current.OnNotificationOpened += FirebasePushNotification_OnNotificationOpened;
2626
}
2727

28+
public string Token => CrossFirebasePushNotification.Current.Token;
29+
2830
private void FirebasePushNotification_OnTokenRefresh(object source, FirebasePushNotificationTokenEventArgs e)
2931
{
3032
var args = new TokenRefreshEventArgs(e.Token);

sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ public void Register()
164164
bool notRefreshing = refreshExecutingCount == 0;
165165
if (notRefreshing)
166166
{
167-
_ = EnsureTokenRefreshedAsync(settings.Token);
167+
string token =
168+
string.IsNullOrWhiteSpace(pushEventsProvider?.Token)
169+
? settings.Token
170+
: pushEventsProvider.Token;
171+
172+
_ = EnsureTokenRefreshedAsync(token);
168173
}
169174
}
170175

sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public interface IPushEventsProvider
2828
/// Event triggered when a notification is opened.
2929
/// </summary>
3030
event EventHandler<NotificationEventArgs> OnNotificationOpened;
31+
32+
/// <summary>
33+
/// Push notification token.
34+
/// </summary>
35+
public string Token { get; }
3136
}
3237
}

tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class EventsProviderMock : IPushEventsProvider
1616
public event EventHandler<TokenRefreshEventArgs> OnTokenRefresh;
1717
public event EventHandler<NotificationEventArgs> OnNotificationReceived;
1818
public event EventHandler<NotificationEventArgs> OnNotificationOpened;
19+
public string Token => "test token";
1920

2021
protected virtual void OnRefreshTokenEvent(TokenRefreshEventArgs args) =>
2122
OnTokenRefresh?.Invoke(this, args);

tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ public void Register_ShouldSetTokenRefreshedFalse_IfHttpServiceThrewException()
398398
[Fact]
399399
public void Register_ShouldNotRefreshToken_IfTokenIsEmpty()
400400
{
401-
var eventsProvider = new EventsProviderMock();
402-
403401
var handler = new Mock<HttpMessageHandler>();
404402
handler.SetupAnyRequest()
405403
.ReturnsResponse(HttpStatusCode.Unauthorized);
@@ -408,8 +406,11 @@ public void Register_ShouldNotRefreshToken_IfTokenIsEmpty()
408406

409407
var mocker = new AutoMocker();
410408
mocker.Use(client);
409+
mocker.Setup<IPushEventsProvider, string>(x => x.Token).Returns(string.Empty);
411410
mocker.Setup<ISettings, string>(x => x.Token).Returns(string.Empty);
412411

412+
var eventsProvider = mocker.GetMock<IPushEventsProvider>().Object;
413+
413414
var notifoMobilePush = mocker.CreateInstance<NotifoMobilePushImplementation>();
414415
notifoMobilePush
415416
.SetPushEventsProvider(eventsProvider)

0 commit comments

Comments
 (0)