All files / app/service experiments.ts

12.5% Statements 3/24
0% Branches 0/6
0% Functions 0/2
12.5% Lines 3/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 482x 2x   2x                                                                                        
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { LogExperimentExposureReq } from "proto/bugs_pb";
 
import client from "./client";
 
export type ExposureReport = {
  experimentKey: string;
  experimentName: string;
  variationId: number;
  variationKey: string;
  variationName: string;
  hashAttribute: string;
  hashValue: string;
  featureId: string;
  inExperiment: boolean;
  bucket?: number;
  hashUsed?: boolean;
  stickyBucketUsed?: boolean;
};
 
export async function reportExposure(exposure: ExposureReport): Promise<void> {
  const req = new LogExperimentExposureReq();
  req.setExperimentKey(exposure.experimentKey);
  req.setExperimentName(exposure.experimentName);
  req.setVariationId(exposure.variationId);
  req.setVariationKey(exposure.variationKey);
  req.setVariationName(exposure.variationName);
  req.setHashAttribute(exposure.hashAttribute);
  req.setHashValue(exposure.hashValue);
  req.setFeatureId(exposure.featureId);
  req.setInExperiment(exposure.inExperiment);
  if (exposure.bucket !== undefined) {
    req.setBucket(exposure.bucket);
  }
  if (exposure.hashUsed !== undefined) {
    req.setHashUsed(exposure.hashUsed);
  }
  if (exposure.stickyBucketUsed !== undefined) {
    req.setStickyBucketUsed(exposure.stickyBucketUsed);
  }
  await client.bugs.logExperimentExposure(req);
}
 
export async function getFeatureFlagAttributes(): Promise<string> {
  const res = await client.bugs.getFeatureFlagAttributes(new Empty());
  return res.getAttributesJson();
}