Skip to content

Commit

Permalink
Update token improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyandreichuk committed Apr 20, 2021
1 parent 6470ad3 commit 90a441a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sdk/Notifo.SDK.FirebasePlugin/PluginEventsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public PluginEventsProvider()
CrossFirebasePushNotification.Current.OnNotificationOpened += FirebasePushNotification_OnNotificationOpened;
}

public string Token => CrossFirebasePushNotification.Current.Token;

private void FirebasePushNotification_OnTokenRefresh(object source, FirebasePushNotificationTokenEventArgs e)
{
var args = new TokenRefreshEventArgs(e.Token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ public void Register()
bool notRefreshing = refreshExecutingCount == 0;
if (notRefreshing)
{
_ = EnsureTokenRefreshedAsync(settings.Token);
string token =
string.IsNullOrWhiteSpace(pushEventsProvider?.Token)
? settings.Token
: pushEventsProvider.Token;

_ = EnsureTokenRefreshedAsync(token);
}
}

Expand Down
5 changes: 5 additions & 0 deletions sdk/Notifo.SDK/PushEventProvider/IPushEventsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ public interface IPushEventsProvider
/// Event triggered when a notification is opened.
/// </summary>
event EventHandler<NotificationEventArgs> OnNotificationOpened;

/// <summary>
/// Push notification token.
/// </summary>
public string Token { get; }
}
}
1 change: 1 addition & 0 deletions tests/Notifo.SDK.UnitTests/Mocks/EventsProviderMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class EventsProviderMock : IPushEventsProvider
public event EventHandler<TokenRefreshEventArgs> OnTokenRefresh;
public event EventHandler<NotificationEventArgs> OnNotificationReceived;
public event EventHandler<NotificationEventArgs> OnNotificationOpened;
public string Token => "test token";

protected virtual void OnRefreshTokenEvent(TokenRefreshEventArgs args) =>
OnTokenRefresh?.Invoke(this, args);
Expand Down
5 changes: 3 additions & 2 deletions tests/Notifo.SDK.UnitTests/NotifoMobilePushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ public void Register_ShouldSetTokenRefreshedFalse_IfHttpServiceThrewException()
[Fact]
public void Register_ShouldNotRefreshToken_IfTokenIsEmpty()
{
var eventsProvider = new EventsProviderMock();

var handler = new Mock<HttpMessageHandler>();
handler.SetupAnyRequest()
.ReturnsResponse(HttpStatusCode.Unauthorized);
Expand All @@ -408,8 +406,11 @@ public void Register_ShouldNotRefreshToken_IfTokenIsEmpty()

var mocker = new AutoMocker();
mocker.Use(client);
mocker.Setup<IPushEventsProvider, string>(x => x.Token).Returns(string.Empty);
mocker.Setup<ISettings, string>(x => x.Token).Returns(string.Empty);

var eventsProvider = mocker.GetMock<IPushEventsProvider>().Object;

var notifoMobilePush = mocker.CreateInstance<NotifoMobilePushImplementation>();
notifoMobilePush
.SetPushEventsProvider(eventsProvider)
Expand Down

0 comments on commit 90a441a

Please sign in to comment.