|
| 1 | +import { expect, describe, test } from "vitest"; |
| 2 | +import { FakeCabidela } from "./lib/fake-cabidela"; |
| 3 | + |
| 4 | +describe("$merge", () => { |
| 5 | + test.skipIf(process.env.AJV)("two objects", () => { |
| 6 | + let schema = { |
| 7 | + $merge: { |
| 8 | + source: { |
| 9 | + type: "object", |
| 10 | + properties: { p: { type: "string" } }, |
| 11 | + additionalProperties: false, |
| 12 | + }, |
| 13 | + with: { |
| 14 | + properties: { q: { type: "number" } }, |
| 15 | + }, |
| 16 | + }, |
| 17 | + }; |
| 18 | + const cabidela = new FakeCabidela(schema, { useMerge: true }); |
| 19 | + schema = cabidela.getSchema(); |
| 20 | + expect(schema).toStrictEqual({ |
| 21 | + type: "object", |
| 22 | + properties: { p: { type: "string" }, q: { type: "number" } }, |
| 23 | + additionalProperties: false, |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + test.skipIf(process.env.AJV)("two objects, with arrays", () => { |
| 28 | + let schema = { |
| 29 | + $merge: { |
| 30 | + source: { |
| 31 | + type: "object", |
| 32 | + properties: { p: [1, 2] }, |
| 33 | + }, |
| 34 | + with: { |
| 35 | + properties: { p: [3, 4] }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }; |
| 39 | + const cabidela = new FakeCabidela(schema, { useMerge: true }); |
| 40 | + schema = cabidela.getSchema(); |
| 41 | + expect(schema).toStrictEqual({ |
| 42 | + type: "object", |
| 43 | + properties: { p: [1, 2, 3, 4] }, |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + test.skipIf(process.env.AJV)("two objects, with $defs and $ref", () => { |
| 48 | + let schema = { |
| 49 | + $merge: { |
| 50 | + source: { |
| 51 | + type: "object", |
| 52 | + properties: { p: { type: "string" } }, |
| 53 | + additionalProperties: false, |
| 54 | + }, |
| 55 | + with: { |
| 56 | + properties: { |
| 57 | + q: { |
| 58 | + type: "string", |
| 59 | + maxLength: { $ref: "$defs#/max_tokens" }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + $defs: { |
| 65 | + max_tokens: 250, |
| 66 | + }, |
| 67 | + }; |
| 68 | + const cabidela = new FakeCabidela(schema, { useMerge: true }); |
| 69 | + schema = cabidela.getSchema(); |
| 70 | + expect(schema).toStrictEqual({ |
| 71 | + type: "object", |
| 72 | + properties: { p: { type: "string" }, q: { type: "string", maxLength: 250 } }, |
| 73 | + additionalProperties: false, |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments