|
| 1 | +/* ============================================================================ |
| 2 | + * Copyright (c) Cloud Annotations |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * ========================================================================== */ |
| 7 | + |
| 8 | +import { getQualifierMessage } from "./schema"; |
| 9 | + |
| 10 | +describe("getQualifierMessage", () => { |
| 11 | + it("should render nothing", () => { |
| 12 | + const actual = getQualifierMessage({}); |
| 13 | + expect(actual).toBeUndefined(); |
| 14 | + }); |
| 15 | + |
| 16 | + // |
| 17 | + // minLength + maxLength |
| 18 | + // |
| 19 | + it("should render minLength", () => { |
| 20 | + const expected = "**Possible values:** 1 ≤ length"; |
| 21 | + const actual = getQualifierMessage({ minLength: 1 }); |
| 22 | + expect(actual).toBe(expected); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should render maxLength", () => { |
| 26 | + const expected = "**Possible values:** length ≤ 40"; |
| 27 | + const actual = getQualifierMessage({ maxLength: 40 }); |
| 28 | + expect(actual).toBe(expected); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should render minLength and maxLength", () => { |
| 32 | + const expected = "**Possible values:** 1 ≤ length ≤ 40"; |
| 33 | + const actual = getQualifierMessage({ minLength: 1, maxLength: 40 }); |
| 34 | + expect(actual).toBe(expected); |
| 35 | + }); |
| 36 | + |
| 37 | + // |
| 38 | + // pattern |
| 39 | + // |
| 40 | + it("should render pattern", () => { |
| 41 | + const expected = |
| 42 | + "**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`"; |
| 43 | + const actual = getQualifierMessage({ pattern: "^[a-zA-Z0-9_-]*$" }); |
| 44 | + expect(actual).toBe(expected); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should render multiple string qualifiers", () => { |
| 48 | + const expected = |
| 49 | + "**Possible values:** 1 ≤ length ≤ 40, Value must match regular expression `^[a-zA-Z0-9_-]*$`"; |
| 50 | + const actual = getQualifierMessage({ |
| 51 | + minLength: 1, |
| 52 | + maxLength: 40, |
| 53 | + pattern: "^[a-zA-Z0-9_-]*$", |
| 54 | + }); |
| 55 | + expect(actual).toBe(expected); |
| 56 | + }); |
| 57 | + |
| 58 | + // |
| 59 | + // enum |
| 60 | + // |
| 61 | + it("should render enum", () => { |
| 62 | + const expected = "**Possible values:** [`cat`, `dog`, `mouse`]"; |
| 63 | + const actual = getQualifierMessage({ enum: ["cat", "dog", "mouse"] }); |
| 64 | + expect(actual).toBe(expected); |
| 65 | + }); |
| 66 | + |
| 67 | + // |
| 68 | + // minimum + maximum + exclusiveMinimum + exclusiveMaximum |
| 69 | + // |
| 70 | + it("should render minimum", () => { |
| 71 | + const expected = "**Possible values:** 1 ≤ value"; |
| 72 | + const actual = getQualifierMessage({ minimum: 1 }); |
| 73 | + expect(actual).toBe(expected); |
| 74 | + }); |
| 75 | + |
| 76 | + it("should render maximum", () => { |
| 77 | + const expected = "**Possible values:** value ≤ 40"; |
| 78 | + const actual = getQualifierMessage({ maximum: 40 }); |
| 79 | + expect(actual).toBe(expected); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should render numeric exclusiveMinimum", () => { |
| 83 | + const expected = "**Possible values:** 1 < value"; |
| 84 | + const actual = getQualifierMessage({ exclusiveMinimum: 1 }); |
| 85 | + expect(actual).toBe(expected); |
| 86 | + }); |
| 87 | + |
| 88 | + it("should render numeric exclusiveMaximum", () => { |
| 89 | + const expected = "**Possible values:** value < 40"; |
| 90 | + const actual = getQualifierMessage({ exclusiveMaximum: 40 }); |
| 91 | + expect(actual).toBe(expected); |
| 92 | + }); |
| 93 | + |
| 94 | + it("should render boolean exclusiveMinimum", () => { |
| 95 | + const expected = "**Possible values:** 1 < value"; |
| 96 | + const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: true }); |
| 97 | + expect(actual).toBe(expected); |
| 98 | + }); |
| 99 | + |
| 100 | + it("should render boolean exclusiveMaximum", () => { |
| 101 | + const expected = "**Possible values:** value < 40"; |
| 102 | + const actual = getQualifierMessage({ maximum: 40, exclusiveMaximum: true }); |
| 103 | + expect(actual).toBe(expected); |
| 104 | + }); |
| 105 | + |
| 106 | + it("should render minimum when exclusiveMinimum is false", () => { |
| 107 | + const expected = "**Possible values:** 1 ≤ value"; |
| 108 | + const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: false }); |
| 109 | + expect(actual).toBe(expected); |
| 110 | + }); |
| 111 | + |
| 112 | + it("should render maximum when exclusiveMaximum is false", () => { |
| 113 | + const expected = "**Possible values:** value ≤ 40"; |
| 114 | + const actual = getQualifierMessage({ |
| 115 | + maximum: 40, |
| 116 | + exclusiveMaximum: false, |
| 117 | + }); |
| 118 | + expect(actual).toBe(expected); |
| 119 | + }); |
| 120 | + |
| 121 | + it("should render minimum and maximum", () => { |
| 122 | + const expected = "**Possible values:** 1 ≤ value ≤ 40"; |
| 123 | + const actual = getQualifierMessage({ minimum: 1, maximum: 40 }); |
| 124 | + expect(actual).toBe(expected); |
| 125 | + }); |
| 126 | + |
| 127 | + it("should render boolean exclusiveMinimum and maximum", () => { |
| 128 | + const expected = "**Possible values:** 1 < value ≤ 40"; |
| 129 | + const actual = getQualifierMessage({ |
| 130 | + minimum: 1, |
| 131 | + maximum: 40, |
| 132 | + exclusiveMinimum: true, |
| 133 | + }); |
| 134 | + expect(actual).toBe(expected); |
| 135 | + }); |
| 136 | + |
| 137 | + it("should render minimum and boolean exclusiveMaximum", () => { |
| 138 | + const expected = "**Possible values:** 1 ≤ value < 40"; |
| 139 | + const actual = getQualifierMessage({ |
| 140 | + minimum: 1, |
| 141 | + maximum: 40, |
| 142 | + exclusiveMaximum: true, |
| 143 | + }); |
| 144 | + expect(actual).toBe(expected); |
| 145 | + }); |
| 146 | + |
| 147 | + it("should render numeric exclusiveMinimum and maximum", () => { |
| 148 | + const expected = "**Possible values:** 1 < value ≤ 40"; |
| 149 | + const actual = getQualifierMessage({ |
| 150 | + exclusiveMinimum: 1, |
| 151 | + maximum: 40, |
| 152 | + }); |
| 153 | + expect(actual).toBe(expected); |
| 154 | + }); |
| 155 | + |
| 156 | + it("should render minimum and numeric exclusiveMaximum", () => { |
| 157 | + const expected = "**Possible values:** 1 ≤ value < 40"; |
| 158 | + const actual = getQualifierMessage({ |
| 159 | + minimum: 1, |
| 160 | + exclusiveMaximum: 40, |
| 161 | + }); |
| 162 | + expect(actual).toBe(expected); |
| 163 | + }); |
| 164 | + |
| 165 | + it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => { |
| 166 | + const expected = "**Possible values:** 1 < value < 40"; |
| 167 | + const actual = getQualifierMessage({ |
| 168 | + exclusiveMinimum: 1, |
| 169 | + maximum: 40, |
| 170 | + exclusiveMaximum: true, |
| 171 | + }); |
| 172 | + expect(actual).toBe(expected); |
| 173 | + }); |
| 174 | + |
| 175 | + it("should render nothing with empty boolean exclusiveMinimum", () => { |
| 176 | + const actual = getQualifierMessage({ |
| 177 | + exclusiveMinimum: true, |
| 178 | + }); |
| 179 | + expect(actual).toBeUndefined(); |
| 180 | + }); |
| 181 | + |
| 182 | + it("should render nothing with empty boolean exclusiveMaximum", () => { |
| 183 | + const actual = getQualifierMessage({ |
| 184 | + exclusiveMaximum: true, |
| 185 | + }); |
| 186 | + expect(actual).toBeUndefined(); |
| 187 | + }); |
| 188 | + |
| 189 | + it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => { |
| 190 | + const actual = getQualifierMessage({ |
| 191 | + exclusiveMinimum: true, |
| 192 | + exclusiveMaximum: true, |
| 193 | + }); |
| 194 | + expect(actual).toBeUndefined(); |
| 195 | + }); |
| 196 | +}); |
0 commit comments