Skip to content

Commit

Permalink
fix flags bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ABTastyAdel committed Jan 16, 2024
1 parent 85f1f02 commit 5d91934
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
14 changes: 1 addition & 13 deletions example/lib/widgets/Modifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,10 @@ class _ModificationsState extends State<Modifications> {
defaultValue = jsonDecode(defaultValueFlagController.text);
}

myFlag = currentVisitor?.getFlag(keyFlagController.text, true);

var myFlagBis = currentVisitor?.getFlag(keyFlagController.text, null);

var retBis = myFlagBis?.value();

print(retBis);

// var myFlagBis = currentVisitor?.getFlag("btnTitle", defaultValue);
// var retBis = myFlagBis?.value(visitorExposed: false);
myFlag = currentVisitor?.getFlag(keyFlagController.text, defaultValue);

var ret = myFlag?.value();

// var ret =
// currentVisitor?.getModification(keyFlagController.text, defaultValue);

setState(() {
valueForFlag = ret.toString();
});
Expand Down
30 changes: 29 additions & 1 deletion test/flag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,23 @@ void main() async {
});

test("Flag with null as value", () {
// PathProviderPlatform.instance = FakePathProviderPlatform();
var v3 = Flagship.newVisitor("flagVisitor").build();
v3.fetchFlags().whenComplete(() {
// String as default value
Flag myFlag = v3.getFlag("keyNull", "nullValue");
expect(myFlag.value(), "nullValue");
// bool as default value
Flag myFlagBool = v3.getFlag("keyNull", false);
expect(myFlagBool.value(), false);
// Double as default value
Flag myFlagDouble = v3.getFlag("keyNull", 12.0);
expect(myFlagDouble.value(), 12.0);
// Int as default value
Flag myFlagInt = v3.getFlag("keyNull", 2);
expect(myFlagInt.value(), 2);
// is existing
expect(myFlag.exists(), true);
// Get metadata
FlagMetadata metadata = myFlag.metadata();
expect(metadata.campaignId, "bsffhle242b2l3igq4dg");
expect(metadata.variationGroupId, "bsffhle242b2l3igq4egaa");
Expand Down Expand Up @@ -257,6 +268,23 @@ void main() async {
});
});

test("Flag with default value = null", () {
//PathProviderPlatform.instance = FakePathProviderPlatform();
var v4 = Flagship.newVisitor("flagVisitor").build();
v4.fetchFlags().whenComplete(() {
Flag myFlag = v4.getFlag("key_A", null);
expect(myFlag.value(), "val_A");
expect(myFlag.exists(), true);
FlagMetadata metadata = myFlag.metadata();
expect(metadata.campaignId, "bsffhle242b2l3igq4dg");
expect(metadata.variationGroupId, "bsffhle242b2l3igq4egaa");
expect(metadata.variationId, "bsffhle242b2l3igq4f0");
expect(metadata.isReference, true);
expect(metadata.slug, "flutter");
expect(metadata.campaignType, "ab");
});
});

test("Failed Activate Flag", () {
when(fakeService.sendHttpRequest(RequestType.Post,
'https://decision.flagship.io/v2/activate', any, any,
Expand Down

0 comments on commit 5d91934

Please sign in to comment.