From e1ac0538b8143f93074c1c248a5739358b3ddfd1 Mon Sep 17 00:00:00 2001 From: code-october <148516338+code-october@users.noreply.github.com> Date: Sat, 30 Nov 2024 07:22:24 +0000 Subject: [PATCH] add unit test --- test/model-available.test.ts | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/model-available.test.ts diff --git a/test/model-available.test.ts b/test/model-available.test.ts new file mode 100644 index 000000000..09a7143e2 --- /dev/null +++ b/test/model-available.test.ts @@ -0,0 +1,43 @@ +import { isModelNotavailableInServer } from "../app/utils/model"; + +describe("isModelNotavailableInServer", () => { + test("test model will return false, which means the model is available", () => { + const customModels = ""; + const modelName = "gpt-4"; + const providerNames = "OpenAI"; + const result = isModelNotavailableInServer(customModels, modelName, providerNames); + expect(result).toBe(false); + }); + + test("test model will return false, which means the model is not available", () => { + const customModels = "-all,gpt-4o-mini"; + const modelName = "gpt-4"; + const providerNames = "OpenAI"; + const result = isModelNotavailableInServer(customModels, modelName, providerNames); + expect(result).toBe(true); + }); + + test("support passing multiple providers, model unavailable on one of the providers will return true", () => { + const customModels = "-all,gpt-4@Google"; + const modelName = "gpt-4"; + const providerNames = ["OpenAI", "Azure"]; + const result = isModelNotavailableInServer(customModels, modelName, providerNames); + expect(result).toBe(true); + }); + + test("support passing multiple providers, model available on one of the providers will return false", () => { + const customModels = "-all,gpt-4@Google"; + const modelName = "gpt-4"; + const providerNames = ["OpenAI", "Google"]; + const result = isModelNotavailableInServer(customModels, modelName, providerNames); + expect(result).toBe(false); + }); + + test("test custom model without setting provider", () => { + const customModels = "-all,mistral-large"; + const modelName = "mistral-large"; + const providerNames = modelName; + const result = isModelNotavailableInServer(customModels, modelName, providerNames); + expect(result).toBe(false); + }); +}) \ No newline at end of file