import { Document } from "mongodb"; import { getDb } from "../../index"; import { flowMongoSchema } from "../flows.schema"; describe("flowMongoSchema", () => { it("defines disableGenericPrompt as optional bool", () => { const schema: any = flowMongoSchema; expect(schema.properties).toHaveProperty("disableGenericPrompt"); expect(schema.properties.disableGenericPrompt.bsonType).toBe("bool"); expect(schema.required).not.toContain("disableGenericPrompt"); }); it("allows legacy flows without disableGenericPrompt", async () => { const collection = await getDb().createCollection("legacy_flows", { validator: { $jsonSchema: flowMongoSchema as Document }, }); await expect( collection.insertOne({ flowName: "Legacy Flow", systemInstructions: "Use the default instructions.", initialSentence: "Hello", interactions: [], }), ).resolves.toBeDefined(); }); it("defines conversationSettings as optional object or null", () => { const schema: any = flowMongoSchema; expect(schema.properties).toHaveProperty("conversationSettings"); expect(schema.properties.conversationSettings.bsonType).toEqual([ "object", "null", ]); expect(schema.required).not.toContain("conversationSettings"); expect(schema.additionalProperties).toBe(false); }); it("defines conversationSettings with expected nested properties", () => { const schema: any = flowMongoSchema; const convSettings = schema.properties.conversationSettings.properties; expect(convSettings).toHaveProperty("interruptions"); expect(convSettings.interruptions.bsonType).toEqual(["object", "null"]); const interruptions = convSettings.interruptions.properties; expect(interruptions.enableInterruptionDetection.bsonType).toEqual("bool"); expect(interruptions.interruptionWindowSeconds.bsonType).toEqual("number"); expect(interruptions.interruptionThresholdSeconds.bsonType).toEqual( "number", ); expect(interruptions.interruptionInstruction.bsonType).toEqual("string"); expect(convSettings).toHaveProperty("silence"); expect(convSettings.silence.bsonType).toEqual(["object", "null"]); const silence = convSettings.silence.properties; expect(silence.enableSilenceDetection.bsonType).toEqual("bool"); expect(silence.firstWarningSilenceSeconds.bsonType).toEqual("number"); expect(silence.firstWarningInstruction.bsonType).toEqual("string"); expect(silence.secondWarningSilenceSeconds.bsonType).toEqual("number"); expect(silence.secondWarningInstruction.bsonType).toEqual("string"); expect(silence.disconnectSilenceSeconds.bsonType).toEqual("number"); expect(convSettings).toHaveProperty("liveTimeUpdates"); expect(convSettings.liveTimeUpdates.bsonType).toEqual("bool"); }); it("should define tools schema and return a backgroundToolType enum with allowed values", () => { const schema: any = flowMongoSchema; expect(schema.properties).toHaveProperty("tools"); expect(schema.properties.tools.bsonType).toEqual(["array", "null"]); const toolItem = schema.properties.tools.items; expect(toolItem.bsonType).toBe("object"); expect(toolItem.properties).toHaveProperty("runInBackground"); expect(toolItem.properties.runInBackground.bsonType).toBe("bool"); expect(toolItem.properties).toHaveProperty("useRedisTranscription"); expect(toolItem.properties.useRedisTranscription.bsonType).toBe("bool"); expect(toolItem.properties).toHaveProperty("backgroundToolType"); expect(toolItem.properties.backgroundToolType.bsonType).toBe("string"); expect(toolItem.properties.backgroundToolType.enum).toEqual([ "backgroundToolAlways", "backgroundToolOnce", ]); expect(toolItem.properties).toHaveProperty( "backgroundContinuationInstructions", ); expect( toolItem.properties.backgroundContinuationInstructions.bsonType, ).toBe("string"); }); it("defines internalTools as an optional map of tool configs", () => { const schema: any = flowMongoSchema; expect(schema.properties).toHaveProperty("internalTools"); expect(schema.required).not.toContain("internalTools"); expect(schema.properties.internalTools.bsonType).toEqual([ "object", "null", ]); const toolConfig = schema.properties.internalTools.additionalProperties; expect(toolConfig.required).toEqual(["enabled"]); expect(toolConfig.properties.enabled.bsonType).toBe("bool"); expect(toolConfig.properties.maxCalls.bsonType).toEqual(["number", "null"]); const param = toolConfig.properties.params.additionalProperties; expect(param.properties.value.bsonType).toEqual([ "string", "number", "bool", "array", "null", ]); }); });