Skip to content

Commit f5f3801

Browse files
test(sdk-spec): Run the experimentation steps against the SDK
Spec v0.6.0 adds scenarios for getting an experiment flag, tracking an event and tracking an exposure event, all with events enabled. The SDK already implements these (#226), so the steps file wires each step to FlagsmithClient.getExperimentFlag, trackEvent and trackExposureEvent, and creates the events-enabled client through FlagsmithConfig. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent eecc3dc commit f5f3801

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎sdk-spec/Steps.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import com.flagsmith.FlagsmithClient;
2+
import com.flagsmith.config.FlagsmithConfig;
23
import com.flagsmith.exceptions.FlagsmithClientError;
34
import com.flagsmith.models.BaseFlag;
45
import com.flagsmith.models.Flags;
6+
import java.util.Collections;
57
import java.util.List;
68
import java.util.Map;
79
import java.util.stream.Collectors;
@@ -35,6 +37,20 @@ static FlagsmithClient createClient(String environmentKey, String apiUrl) {
3537
return FlagsmithClient.newBuilder().setApiKey(environmentKey).withApiUrl(apiUrl).build();
3638
}
3739

40+
// Create the SDK client with events enabled
41+
static FlagsmithClient createClientWithEvents(
42+
String environmentKey, String apiUrl, String eventsUrl) {
43+
return FlagsmithClient.newBuilder()
44+
.setApiKey(environmentKey)
45+
.withConfiguration(
46+
FlagsmithConfig.newBuilder()
47+
.baseUri(apiUrl)
48+
.withEnableEvents(true)
49+
.eventsUri(eventsUrl)
50+
.build())
51+
.build();
52+
}
53+
3854
// When the application gets the environment flags
3955
static List<SpecFlag> getEnvironmentFlags(FlagsmithClient flagsmith)
4056
throws FlagsmithClientError {
@@ -47,4 +63,32 @@ static List<SpecFlag> getIdentityFlags(
4763
throws FlagsmithClientError {
4864
return asSpecFlags(flagsmith.getIdentityFlags(identifier, traits));
4965
}
66+
67+
// When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits:
68+
static List<SpecFlag> getExperimentFlag(
69+
FlagsmithClient flagsmith, String feature, String identifier, Map<String, Object> traits)
70+
throws FlagsmithClientError {
71+
return Collections.singletonList(
72+
new SpecFlag(flagsmith.getExperimentFlag(feature, identifier, traits)));
73+
}
74+
75+
// When the application tracks event "{event}" for identity "{identifier}" with value {value} and metadata:
76+
static void trackEvent(
77+
FlagsmithClient flagsmith,
78+
String event,
79+
String identifier,
80+
Object value,
81+
Map<String, Object> metadata) {
82+
flagsmith.trackEvent(event, identifier, value, null, metadata);
83+
}
84+
85+
// When the application tracks an exposure of feature "{feature}" for identity "{identifier}" with value {value} and metadata:
86+
static void trackExposureEvent(
87+
FlagsmithClient flagsmith,
88+
String feature,
89+
String identifier,
90+
Object value,
91+
Map<String, Object> metadata) {
92+
flagsmith.trackExposureEvent(feature, identifier, value, null, metadata);
93+
}
5094
}

0 commit comments

Comments
 (0)