Skip to content

Commit c4c9c23

Browse files
committed
refactor: rework how nock is setup and used to harden tests
1 parent 1ca65d8 commit c4c9c23

6 files changed

Lines changed: 135 additions & 415 deletions

File tree

tests/apiExecutor.test.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import nock from "nock";
2-
2+
import { CredentialsMethod } from "../credentials";
33
import {
4-
OpenFgaClient,
5-
UserClientConfigurationParams,
64
FgaApiNotFoundError,
75
FgaApiValidationError,
6+
OpenFgaClient,
7+
type UserClientConfigurationParams,
88
} from "../index";
9-
import { CredentialsMethod } from "../credentials";
109
import { baseConfig, defaultConfiguration, OPENFGA_STORE_ID } from "./helpers/default-config";
1110

1211
describe("OpenFgaClient.executeApiRequest", () => {
@@ -16,21 +15,6 @@ describe("OpenFgaClient.executeApiRequest", () => {
1615
credentials: { method: CredentialsMethod.None }
1716
};
1817

19-
beforeAll(() => {
20-
nock.restore();
21-
nock.cleanAll();
22-
nock.activate();
23-
nock.disableNetConnect();
24-
});
25-
26-
afterEach(() => {
27-
nock.cleanAll();
28-
});
29-
30-
afterAll(() => {
31-
nock.restore();
32-
});
33-
3418
describe("GET requests", () => {
3519
it("should make GET requests successfully", async () => {
3620
const fgaClient = new OpenFgaClient(testConfig);
@@ -337,21 +321,6 @@ describe("OpenFgaClient.executeApiRequest - path parameters", () => {
337321
credentials: { method: CredentialsMethod.None }
338322
};
339323

340-
beforeAll(() => {
341-
nock.restore();
342-
nock.cleanAll();
343-
nock.activate();
344-
nock.disableNetConnect();
345-
});
346-
347-
afterEach(() => {
348-
nock.cleanAll();
349-
});
350-
351-
afterAll(() => {
352-
nock.restore();
353-
});
354-
355324
describe("path parameter replacement", () => {
356325
it("should replace path parameters with values (single_parameter)", async () => {
357326
const fgaClient = new OpenFgaClient(testConfig);

0 commit comments

Comments
 (0)