Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/onesignal_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:onesignal_flutter/src/location.dart';
import 'package:onesignal_flutter/src/notifications.dart';
import 'package:onesignal_flutter/src/session.dart';
import 'package:onesignal_flutter/src/user.dart';
import 'package:onesignal_flutter/src/utils.dart';

export 'src/defines.dart';
export 'src/inappmessage.dart';
Expand Down Expand Up @@ -49,7 +48,6 @@ class OneSignal {
/// The initializer accepts an [appId] which the developer can get
/// from the OneSignal consoleas well as a dictonary of [launchOptions]
static Future<void> initialize(String appId) async {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: no test covers initialize('') now. Could you add one asserting '' is forwarded and the lifecycle methods still run? As is, restoring the old guard would still pass the suite.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and the part that matters is your point that restoring the old guard would still pass the suite as written. Not added yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now added in 685a8eb. Asserts '' is forwarded and that the lifecycle methods still run. Revert-checked: restoring the guard turns it red, which was your actual point.

if (isMissing(appId, 'initialize: appId')) return;
await _channel.invokeMethod('OneSignal#initialize', {'appId': appId});
await Future.wait([

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: initialize('') after a valid init now reruns lifecycleInit, which clears pending foreground display/preventDefault caches (OSFlutterNotifications.m:124). Same as calling initialize twice today, so fine to leave.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, and agreed it matches calling initialize twice today.

InAppMessages.lifecycleInit(),
Expand All @@ -64,7 +62,6 @@ class OneSignal {
/// The act of logging a user into the OneSignal SDK will switch the
/// user context to that specific user.
static Future<void> login(String externalId) async {
if (isMissing(externalId, 'login: externalId')) return;
return await _channel.invokeMethod('OneSignal#login', {
'externalId': externalId,
});
Expand Down
15 changes: 13 additions & 2 deletions test/onesignalflutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,28 @@ void main() {
expect(channelController.state.userLifecycleInitCalled, isTrue);
});

test(
'initialize forwards an empty appId and still runs lifecycle',
() async {
await OneSignal.initialize('');

expect(channelController.state.appId, equals(''));
expect(channelController.state.lifecycleInitCalled, isTrue);
expect(channelController.state.userLifecycleInitCalled, isTrue);
},
);

group('login', () {
test('login invokes native method with externalId', () async {
await OneSignal.login('user-123');

expect(channelController.state.externalId, equals('user-123'));
});

test('login rejects empty externalId', () async {
test('login forwards an empty externalId to native', () async {
await OneSignal.login('');

expect(channelController.state.externalId, isNull);
expect(channelController.state.externalId, equals(''));
});
});

Expand Down
Loading