Skip to content

Commit ff5f7af

Browse files
committed
Add test to check that OfflineFeatures doesn't use the API client
1 parent 5af7feb commit ff5f7af

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import test from "ava";
2+
import * as sinon from "sinon";
3+
4+
import * as apiClient from "../api-client";
5+
import { Feature, featureConfig } from "../feature-flags";
6+
import { mockCCR, setupTests } from "../testing-utils";
7+
import { initializeEnvironment, withTmpDir } from "../util";
8+
9+
import {
10+
getFeatureIncludingCodeQlIfRequired,
11+
setUpFeatureFlagTests,
12+
} from "./test-util";
13+
14+
setupTests(test);
15+
16+
test.beforeEach(() => {
17+
initializeEnvironment("1.2.3");
18+
mockCCR();
19+
});
20+
21+
test("OfflineFeatures makes no API requests", async (t) => {
22+
await withTmpDir(async (tmpDir) => {
23+
const features = setUpFeatureFlagTests(tmpDir);
24+
t.is("OfflineFeatures", features.constructor.name);
25+
26+
sinon
27+
.stub(apiClient, "getApiClient")
28+
.throws(new Error("Should not have called getApiClient"));
29+
30+
for (const feature of Object.values(Feature)) {
31+
t.deepEqual(
32+
await getFeatureIncludingCodeQlIfRequired(features, feature),
33+
featureConfig[feature].defaultValue,
34+
);
35+
}
36+
});
37+
});

0 commit comments

Comments
 (0)