Skip to content

Commit

Permalink
[Typescript] test for save() (#198)
Browse files Browse the repository at this point in the history
[Typescript] test for save()
  • Loading branch information
Ankush-lastmile authored Dec 21, 2023
2 parents eafd36a + b6ad813 commit b1d367f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions typescript/__tests__/testSave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// FileWriter.test.ts
import * as fs from "fs";
import * as path from "path";
import { tmpdir } from "os";
import { AIConfigRuntime } from "../lib/config";

describe("AIConfigRuntime save()", () => {
it("saves the config and checks if the config json doesn't have key filePath", () => {
const tmpDir = tmpdir(); // Get the system's temporary directory
const newFileName = "modified_config.json";
const tempFilePath = path.join(tmpDir, newFileName);

const filePath = path.join(
__dirname,
"samples",
"basic_chatgpt_query_config.json"
);

const aiconfig = AIConfigRuntime.load(filePath);
// Modify and save the configuration
aiconfig.save(tempFilePath);

// Open and parse the saved JSON file
const savedConfig = JSON.parse(fs.readFileSync(tempFilePath, "utf8"));

// Perform your assertions
expect(savedConfig.hasOwnProperty("filePath")).toBe(false);
});
});

0 comments on commit b1d367f

Please sign in to comment.