-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sort-neurons-by-rewards-timestamp
- Loading branch information
Showing
9 changed files
with
139 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontend/src/tests/lib/constants/environment.constants.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { defaultFeatureFlagValues } from "$lib/constants/environment.constants"; | ||
import * as envVarsUtils from "$lib/utils/env-vars.utils"; | ||
|
||
describe("FEATURE_FLAG_ENVIRONMENT", () => { | ||
const environmentVars = envVarsUtils.getEnvVars(); | ||
|
||
beforeEach(() => { | ||
// The FEATURE_FLAG_ENVIRONMENT is a constant that is set once when the module | ||
// `environment.constants` is imported. To test different states of it, | ||
// we need to reset the imported modules and reimport `environment.constants` for each test. | ||
vi.resetModules(); | ||
}); | ||
|
||
it("should equal the environment values", async () => { | ||
const { FEATURE_FLAG_ENVIRONMENT } = await import( | ||
"$lib/constants/environment.constants" | ||
); | ||
const expectedFlags = JSON.parse(environmentVars.featureFlags); | ||
expect(FEATURE_FLAG_ENVIRONMENT).toEqual(expectedFlags); | ||
}); | ||
|
||
it("should contain missing entries substituted with default values", async () => { | ||
vi.spyOn(envVarsUtils, "getEnvVars").mockReturnValue({ | ||
...environmentVars, | ||
featureFlags: JSON.stringify({}), | ||
}); | ||
|
||
const { FEATURE_FLAG_ENVIRONMENT } = await import( | ||
"$lib/constants/environment.constants" | ||
); | ||
expect(FEATURE_FLAG_ENVIRONMENT).toEqual(defaultFeatureFlagValues); | ||
}); | ||
|
||
it("should fallback to default on error", async () => { | ||
const spyConsoleError = vi | ||
.spyOn(console, "error") | ||
.mockImplementation(() => undefined); | ||
vi.spyOn(envVarsUtils, "getEnvVars").mockReturnValue({ | ||
...environmentVars, | ||
featureFlags: `{"TEST_FLAG_NOT_EDITABLE": TRUE}`, | ||
}); | ||
|
||
const { FEATURE_FLAG_ENVIRONMENT } = await import( | ||
"$lib/constants/environment.constants" | ||
); | ||
expect(FEATURE_FLAG_ENVIRONMENT).toEqual(defaultFeatureFlagValues); | ||
expect(spyConsoleError).toBeCalledTimes(1); | ||
expect(spyConsoleError).toBeCalledWith( | ||
"Error parsing featureFlags", | ||
new SyntaxError("Unexpected token T in JSON at position 27") | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters