diff --git a/example/lib/Providers/fs_data.dart b/example/lib/Providers/fs_data.dart index a0b7441..fdefcff 100644 --- a/example/lib/Providers/fs_data.dart +++ b/example/lib/Providers/fs_data.dart @@ -63,7 +63,7 @@ class FSData extends ChangeNotifier { } class UserData extends ChangeNotifier { - String _visitorId = "flutter_user252"; + String _visitorId = "flutter_user253"; Map context = { "testing_tracking_manager": true, "isQA": true, diff --git a/example/lib/widgets/Modifications.dart b/example/lib/widgets/Modifications.dart index 1d14614..f97427f 100644 --- a/example/lib/widgets/Modifications.dart +++ b/example/lib/widgets/Modifications.dart @@ -2,8 +2,6 @@ import 'dart:convert'; import 'package:flagship/model/flag.dart'; import 'package:flagship/status.dart'; -import 'package:flagship/visitor.dart'; -import 'package:flagship/model/visitor_flag.dart'; import 'package:flagship_qa/widgets/FSinputField.dart'; import 'package:flagship_qa/widgets/modifications_json_screen.dart'; import 'package:flutter/material.dart'; @@ -128,31 +126,23 @@ class _ModificationsState extends State { // Get json view _getJsonView(BuildContext ctx) { - // var flagCollection = Flagship.getCurrentVisitor()?.getFlags(); - - // if (flagCollection != null) { - // flagCollection.flags.forEach((itemkey, itemValue) { - // print(itemValue.metadata().toJson().toString()); - // }); - // } - Navigator.of(ctx) .pushNamed(ModificationsJSONScreen.routeName, arguments: {}); } - _getCollection() { - Visitor? v1 = Flagship.getCurrentVisitor(); + // _getCollection() { + // Visitor? v1 = Flagship.getCurrentVisitor(); - if (v1 != null) { - FSFlagCollection flagCollection = v1.getFlags(); + // if (v1 != null) { + // FSFlagCollection flagCollection = v1.getFlags(); - var flag = flagCollection['btnColor']; + // var flag = flagCollection['btnColor']; - flag.value(12121); + // flag.value(12121); - flag.visitorExposed(); - } - } + // flag.visitorExposed(); + // } + // } void _resetField() { variationId = "None"; @@ -308,8 +298,7 @@ class _ModificationsState extends State { child: ElevatedButton( child: Text("JSON VIEW"), onPressed: () { - _getCollection(); - // _getJsonView(context); + _getJsonView(context); }, ), ), diff --git a/lib/api/endpoints.dart b/lib/api/endpoints.dart index 8bed059..b2409ed 100644 --- a/lib/api/endpoints.dart +++ b/lib/api/endpoints.dart @@ -5,7 +5,7 @@ class Endpoints { static const String DECISION_API = "https://decision.flagship.io/v2/"; static const String CAMPAIGNS = "/campaigns/?exposeAllKeys=true&extras[]=accountSettings"; - static const String ACTIVATION = "activate"; // TODO remove extra + static const String ACTIVATION = "activate"; // Bucketing static const String BUCKETING_SCRIPT = diff --git a/lib/flagship_config.dart b/lib/flagship_config.dart index a42480f..edf8f6e 100644 --- a/lib/flagship_config.dart +++ b/lib/flagship_config.dart @@ -93,7 +93,7 @@ class ConfigBuilder { // _pollingTime int _pollingTime = 60; - // StatusListener + // _onSdkStatusChanged SdkStatusChanged? _onSdkStatusChanged; // Tracking Config @@ -135,7 +135,7 @@ class ConfigBuilder { return this; } - // StatusListener + // onSdkStatusChanged ConfigBuilder onSdkStatusChanged(SdkStatusChanged pSdkStatusChanged) { _onSdkStatusChanged = pSdkStatusChanged; return this; diff --git a/lib/hits/activate.dart b/lib/hits/activate.dart index 1c76fa9..7322a54 100644 --- a/lib/hits/activate.dart +++ b/lib/hits/activate.dart @@ -1,6 +1,4 @@ import 'dart:convert'; - -import 'package:collection/collection.dart'; import 'package:flagship/flagship.dart'; import 'package:flagship/hits/hit.dart'; import 'package:flagship/model/exposed_flag.dart'; @@ -114,7 +112,6 @@ class Activate extends BaseHit { this.modification != null); } - /// TODO create a real one later FSExposedInfo? getExposedInfo() { if (this.exposure_flag != null) { // Create map for exposeFlag diff --git a/lib/visitor.dart b/lib/visitor.dart index 5f370dc..d6566f2 100644 --- a/lib/visitor.dart +++ b/lib/visitor.dart @@ -203,7 +203,6 @@ class Visitor { // if the context still the same then no need to raise the warning // Update flagSyncStatus to raise a warning when access to flag this._flagSyncStatus = FlagSyncStatus.CONTEXT_UPDATED; - // TODO factorise with syncStaus flagStatus = FlagStatus.FETCH_REQUIRED; _fetchReasons = FetchFlagsRequiredStatusReason.VISITOR_CONTEXT_UPDATED; } diff --git a/lib/visitor/strategy/default_strategy.dart b/lib/visitor/strategy/default_strategy.dart index a552d8b..111283c 100644 --- a/lib/visitor/strategy/default_strategy.dart +++ b/lib/visitor/strategy/default_strategy.dart @@ -225,8 +225,6 @@ class DefaultStrategy implements IVisitor { DataUsageTracking.sharedInstance() .processTroubleShootingException(visitor, error); return FetchResponse(FlagStatus.FETCH_REQUIRED, Error()); - // TODO create better object error - // return Error(); // Return Error } } @@ -248,6 +246,11 @@ class DefaultStrategy implements IVisitor { @override authenticateVisitor(String pVisitorId) { if (visitor.config.decisionMode == Mode.DECISION_API) { + if (visitor.anonymousId == null) { + visitor.anonymousId = visitor.visitorId; + visitor.visitorId = pVisitorId; + } + DataUsageTracking.sharedInstance() .processTSXpc(CriticalPoints.VISITOR_AUTHENTICATE.name, this.visitor); } else { @@ -259,12 +262,12 @@ class DefaultStrategy implements IVisitor { @override unAuthenticateVisitor() { if (visitor.config.decisionMode == Mode.DECISION_API) { - DataUsageTracking.sharedInstance().processTSXpc( - CriticalPoints.VISITOR_UNAUTHENTICATE.name, this.visitor); if (visitor.anonymousId != null) { visitor.visitorId = visitor.anonymousId as String; visitor.anonymousId = null; } + DataUsageTracking.sharedInstance().processTSXpc( + CriticalPoints.VISITOR_UNAUTHENTICATE.name, this.visitor); } else { Flagship.logger(Level.ALL, "unAuthenticateVisitor method will be ignored in Bucketing configuration"); @@ -363,19 +366,19 @@ class DefaultStrategy implements IVisitor { FlagMetadata.withMap(pModification.toJsonInformation()))); } - void onExposureBis(List exposureInfos) { - print(" @@@@@@@@@ callback exposure is called with " + - exposureInfos.length.toString() + - " Activate @@@@@@@@@@@@@@@@@"); - exposureInfos.forEach((item) { - print(" onExposure item " + item.visitorExposed.id); + // void onExposureBis(List exposureInfos) { + // print(" @@@@@@@@@ callback exposure is called with " + + // exposureInfos.length.toString() + + // " Activate @@@@@@@@@@@@@@@@@"); + // exposureInfos.forEach((item) { + // print(" onExposure item " + item.visitorExposed.id); - Flagship.sharedInstance() - .getConfiguration() - ?.onVisitorExposed - ?.call(item.visitorExposed, item.exposedFlag); - }); - } + // Flagship.sharedInstance() + // .getConfiguration() + // ?.onVisitorExposed + // ?.call(item.visitorExposed, item.exposedFlag); + // }); + // } @override FlagStatus getFlagStatus(String key) { diff --git a/lib/visitor/strategy/no_consent_strategy.dart b/lib/visitor/strategy/no_consent_strategy.dart index 2bc3895..3aebd63 100644 --- a/lib/visitor/strategy/no_consent_strategy.dart +++ b/lib/visitor/strategy/no_consent_strategy.dart @@ -35,11 +35,15 @@ class NoConsentStrategy extends DefaultStrategy { } } - // TODO, not consent have not lookup visitor + @override + Future lookupVisitor(String visitoId) async { + Flagship.logger(Level.INFO, "No lookup Visitor when not consent"); + return false; + } @override void lookupHits() async { - Flagship.logger(Level.INFO, "No lookup Hits when not ready"); + Flagship.logger(Level.INFO, "No lookup Hits when not consent"); } @override diff --git a/lib/visitor/visitor_delegate.dart b/lib/visitor/visitor_delegate.dart index e12f743..68eaab4 100644 --- a/lib/visitor/visitor_delegate.dart +++ b/lib/visitor/visitor_delegate.dart @@ -28,7 +28,7 @@ class VisitorDelegate implements IVisitor { } else { return DefaultStrategy(visitor); } - case FSSdkStatus.SDK_INITIALIZING: // TODO check this part + case FSSdkStatus.SDK_INITIALIZING: return NotReadyStrategy(visitor); } } diff --git a/test/activate_test.dart b/test/activate_test.dart index 37807fc..5ff549f 100644 --- a/test/activate_test.dart +++ b/test/activate_test.dart @@ -1,8 +1,16 @@ +import 'package:flagship/flagship.dart'; +import 'package:flagship/flagship_config.dart'; +import 'package:flagship/model/exposed_flag.dart'; +import 'package:flagship/model/flag.dart'; import 'package:flagship/model/modification.dart'; +import 'package:flagship/model/visitor_exposed.dart'; +import 'package:flagship/visitor/strategy/default_strategy.dart'; +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flagship/hits/activate.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); test("Activate with Modification object ", () { Modification fakeModif = Modification( "key", @@ -26,4 +34,68 @@ void main() { expect(fakeJson["cid"], "envId"); expect(fakeJson["aid"], "anonym1"); }); + + test("OnExposureCallback", () { + var expoConfig = ConfigBuilder().withOnVisitorExposed((v, f) { + expect(f.metadata().campaignId, "campaignId"); + expect(v.id, "expoVisitor"); + }).build(); + Flagship.start("bkk9glocmjcg0vtmdlrr", "apiKey", config: expoConfig); + var expoVisitor = + Flagship.newVisitor(visitorId: "expoVisitor", hasConsented: true) + .withContext({"expoKey": "expoVal"}).build(); + // Create a default strategy + var dfltStrategy = DefaultStrategy(expoVisitor); + + // Create Modification + var expoModif = Modification( + "key", + "campaignId", + "campaignName", + "variationGroupId", + "variationGroupName", + "variationId", + "variationName", + true, + "AB", + "slug", + "value"); + // Trigger the callback + dfltStrategy.onExposure(expoModif); + }); + + test("OnExposureObject", () { + var expoConfig = ConfigBuilder().withOnVisitorExposed((v, f) { + expect(f.metadata().campaignId, "campaignId"); + expect(v.id, "expoVisitorObj"); + }).build(); + Flagship.start("bkk9glocmjcg0vtmdlrr", "apiKey", config: expoConfig); + var expoVisitorObj = + Flagship.newVisitor(visitorId: "expoVisitorObj", hasConsented: true) + .withContext({"expoKey": "expoVal"}).build(); + // Create a default strategy + var dfltStrategy = DefaultStrategy(expoVisitorObj); + + // Create Modification + var expoModif = Modification( + "key", + "campaignId", + "campaignName", + "variationGroupId", + "variationGroupName", + "variationId", + "variationName", + true, + "AB", + null, + "value"); + // Trigger the callback + dfltStrategy.onExposure(expoModif); + + // Check brut objs + var vE = VisitorExposed("is", null, {}); + expect(vE.anonymousId, null); + var eF = ExposedFlag("key", 12, 12, FlagMetadata.withMap({})); + expect(eF.metadata().campaignId, ""); + }); }