Skip to content

Commit

Permalink
add test + comments and filter invalid flags
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Aug 16, 2024
1 parent 367c6f7 commit 1630e40
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/lib/__test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest"

Check failure on line 1 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"vitest"` with `'vitest';⏎`
import { StatsigConfig } from '../../constants/abacus'

Check failure on line 2 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
import { StatSigFlags } from "../../types/statsig"

Check failure on line 3 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"../../types/statsig"` with `'../../types/statsig';`
import abacusStateManager from "../abacus"

Check failure on line 4 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"../abacus"` with `'../abacus';`

describe('setStatsigConfigs', () => {
it('only sets properties that exist in the kotlin object', () => {

Check failure on line 7 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
abacusStateManager.setStatsigConfigs({

Check failure on line 8 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
[StatSigFlags.ffEnableEvmSwaps]: true,

Check failure on line 9 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
'nonexistent_flag': true,

Check failure on line 10 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `············'nonexistent_flag'` with `······nonexistent_flag`
})

Check failure on line 11 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········})` with `····});`
expect(StatsigConfig.ff_enable_evm_swaps).toBe(true)

Check failure on line 12 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········expect(StatsigConfig.ff_enable_evm_swaps).toBe(true)` with `····expect(StatsigConfig.ff_enable_evm_swaps).toBe(true);`
// @ts-ignore
expect(StatsigConfig.nonexistent_flag).toBeUndefined()
})
})
13 changes: 6 additions & 7 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,18 @@ class AbacusStateManager {
/**
*
* Updates Abacus' global StatsigConfig object.
* You must destructure the new flag you want to use from the config and set
* the relevant property on the StatsigConfig object.
* You must define the property in abacus first, and then add to the enum.
*
* TODO: establish standardized naming conventions between
* statsig FF name and boolean propery in abacus StatsigConfig
* https://linear.app/dydx/project/feature-experimentation-6853beb333d7/overview
*/
setStatsigConfigs = (statsigConfig: { [key in StatSigFlags]?: boolean }) => {
const { [StatSigFlags.ffSkipMigration]: useSkip = false, ...rest } = statsigConfig;
StatsigConfig.useSkip = useSkip;
Object.entries(rest).forEach(([k, v]) => {
// @ts-ignore
StatsigConfig[k] = v;
// This filters out any feature flags in the enum that are not part of the
// kotlin statsig config object
if (k in StatsigConfig) {
StatsigConfig[k] = v;
}
});
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/types/statsig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export type StatsigConfigType = Record<StatSigFlags, boolean>;

/**
* !README!:
* If you are using a flag in abacus, you must add it to the abacus
* StatsigConfig object first! Otherwise it won't be set in the StatsigConfig object
*/
export enum StatSigFlags {
ffSkipMigration = 'ff_skip_migration',
ffShowPredictionMarketsUi = 'ff_show_prediction_markets_ui',
Expand Down

0 comments on commit 1630e40

Please sign in to comment.