From b6ad8136190189714b130f859d7a546b7e28d2f7 Mon Sep 17 00:00:00 2001 From: "Ankush Pala ankush@lastmileai.dev" <> Date: Thu, 21 Dec 2023 18:12:53 -0500 Subject: [PATCH] [Typescript] test for save() --- typescript/__tests__/testSave.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 typescript/__tests__/testSave.ts diff --git a/typescript/__tests__/testSave.ts b/typescript/__tests__/testSave.ts new file mode 100644 index 000000000..929a43361 --- /dev/null +++ b/typescript/__tests__/testSave.ts @@ -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); + }); +});