|
13 | 13 | * permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 |
|
16 | | -import {LengthTests} from "@aws-smithy/typescript-integ-test-types"; |
| 16 | +import { LengthTests } from "@aws-smithy/typescript-integ-test-types"; |
17 | 17 |
|
18 | 18 | describe("length constraints", () => { |
19 | | - it("work for strings", () => { |
20 | | - expect(LengthTests.validate({ minMaxLengthString: "much longer than 7" })).toEqual([{ |
21 | | - constraintType: "length", |
22 | | - constraintValues: [ 2, 7 ], |
23 | | - failureValue: 18, |
24 | | - memberName: "minMaxLengthString", |
25 | | - }]); |
26 | | - expect(LengthTests.validate({ minMaxLengthString: "a" })).toEqual([{ |
27 | | - constraintType: "length", |
28 | | - constraintValues: [ 2, 7 ], |
29 | | - failureValue: 1, |
30 | | - memberName: "minMaxLengthString", |
31 | | - }]); |
32 | | - }); |
33 | | - it("work for maps", () => { |
34 | | - expect(LengthTests.validate({ minMaxLengthMap: { "abc": 1 }})).toEqual([{ |
35 | | - constraintType: "length", |
36 | | - constraintValues: [ 2, 4 ], |
37 | | - failureValue: 1, |
38 | | - memberName: "minMaxLengthMap", |
39 | | - }]); |
40 | | - expect(LengthTests.validate({ minMaxLengthMap: { "abc": 1, "bcd": 2, "cde": 3, "def": 4, "efg": 5 }})).toEqual([{ |
41 | | - constraintType: "length", |
42 | | - constraintValues: [ 2, 4 ], |
43 | | - failureValue: 5, |
44 | | - memberName: "minMaxLengthMap", |
45 | | - }]); |
46 | | - }); |
47 | | - it("also work on map keys", () => { |
48 | | - expect(LengthTests.validate({ minMaxLengthMap: { "a": 1, "bcd": 2, "cde": 3 }})).toEqual([{ |
49 | | - constraintType: "length", |
50 | | - constraintValues: [ 2, 7 ], |
51 | | - failureValue: 1, |
52 | | - memberName: "minMaxLengthMap", |
53 | | - }]); |
54 | | - expect(LengthTests.validate({ minMaxLengthMap: { "abcdefghijk": 5, "bcd": 2, "cde": 3 }})).toEqual([{ |
55 | | - constraintType: "length", |
56 | | - constraintValues: [ 2, 7 ], |
57 | | - failureValue: 11, |
58 | | - memberName: "minMaxLengthMap", |
59 | | - }]); |
60 | | - }); |
61 | | - it("work for lists", () => { |
62 | | - expect(LengthTests.validate({ minMaxLengthList: ["abc"]})).toEqual([{ |
63 | | - constraintType: "length", |
64 | | - constraintValues: [ 2, 4 ], |
65 | | - failureValue: 1, |
66 | | - memberName: "minMaxLengthList", |
67 | | - }]); |
68 | | - expect(LengthTests.validate({ minMaxLengthList: [ "abc", "bcd", "cde", "def", "efg" ]})).toEqual([{ |
69 | | - constraintType: "length", |
70 | | - constraintValues: [ 2, 4 ], |
71 | | - failureValue: 5, |
72 | | - memberName: "minMaxLengthList", |
73 | | - }]); |
74 | | - }); |
75 | | - it("also work on list values", () => { |
76 | | - expect(LengthTests.validate({ minMaxLengthList: ["abcdefghijk", "def"]})).toEqual([{ |
77 | | - constraintType: "length", |
78 | | - constraintValues: [ 2, 7 ], |
79 | | - failureValue: 11, |
80 | | - memberName: "minMaxLengthList", |
81 | | - }]); |
82 | | - }); |
83 | | - it("work for blobs", () => { |
84 | | - expect(LengthTests.validate({ minMaxLengthBlob: Buffer.of(1) })).toEqual([{ |
85 | | - constraintType: "length", |
86 | | - constraintValues: [ 2, 4 ], |
87 | | - failureValue: 1, |
88 | | - memberName: "minMaxLengthBlob", |
89 | | - }]); |
90 | | - expect(LengthTests.validate({ minMaxLengthBlob: Buffer.of(1, 2, 3, 4, 5)})).toEqual([{ |
91 | | - constraintType: "length", |
92 | | - constraintValues: [ 2, 4 ], |
93 | | - failureValue: 5, |
94 | | - memberName: "minMaxLengthBlob", |
95 | | - }]); |
96 | | - }); |
97 | | - it("can be overridden on members", () => { |
98 | | - expect(LengthTests.validate({ minMaxLengthOverride: "abcdef" })).toEqual([{ |
99 | | - constraintType: "length", |
100 | | - constraintValues: [ 13, 27 ], |
101 | | - failureValue: 6, |
102 | | - memberName: "minMaxLengthOverride", |
103 | | - }]); |
104 | | - }) |
| 19 | + it("work for strings", () => { |
| 20 | + expect( |
| 21 | + LengthTests.validate({ minMaxLengthString: "much longer than 7" }) |
| 22 | + ).toEqual([ |
| 23 | + { |
| 24 | + constraintType: "length", |
| 25 | + constraintValues: [2, 7], |
| 26 | + failureValue: 18, |
| 27 | + memberName: "minMaxLengthString", |
| 28 | + }, |
| 29 | + ]); |
| 30 | + expect(LengthTests.validate({ minMaxLengthString: "a" })).toEqual([ |
| 31 | + { |
| 32 | + constraintType: "length", |
| 33 | + constraintValues: [2, 7], |
| 34 | + failureValue: 1, |
| 35 | + memberName: "minMaxLengthString", |
| 36 | + }, |
| 37 | + ]); |
| 38 | + }); |
| 39 | + it("work for maps", () => { |
| 40 | + expect(LengthTests.validate({ minMaxLengthMap: { abc: 1 } })).toEqual([ |
| 41 | + { |
| 42 | + constraintType: "length", |
| 43 | + constraintValues: [2, 4], |
| 44 | + failureValue: 1, |
| 45 | + memberName: "minMaxLengthMap", |
| 46 | + }, |
| 47 | + ]); |
| 48 | + expect( |
| 49 | + LengthTests.validate({ |
| 50 | + minMaxLengthMap: { abc: 1, bcd: 2, cde: 3, def: 4, efg: 5 }, |
| 51 | + }) |
| 52 | + ).toEqual([ |
| 53 | + { |
| 54 | + constraintType: "length", |
| 55 | + constraintValues: [2, 4], |
| 56 | + failureValue: 5, |
| 57 | + memberName: "minMaxLengthMap", |
| 58 | + }, |
| 59 | + ]); |
| 60 | + }); |
| 61 | + it("also work on map keys", () => { |
| 62 | + expect( |
| 63 | + LengthTests.validate({ minMaxLengthMap: { a: 1, bcd: 2, cde: 3 } }) |
| 64 | + ).toEqual([ |
| 65 | + { |
| 66 | + constraintType: "length", |
| 67 | + constraintValues: [2, 7], |
| 68 | + failureValue: 1, |
| 69 | + memberName: "minMaxLengthMap", |
| 70 | + }, |
| 71 | + ]); |
| 72 | + expect( |
| 73 | + LengthTests.validate({ |
| 74 | + minMaxLengthMap: { abcdefghijk: 5, bcd: 2, cde: 3 }, |
| 75 | + }) |
| 76 | + ).toEqual([ |
| 77 | + { |
| 78 | + constraintType: "length", |
| 79 | + constraintValues: [2, 7], |
| 80 | + failureValue: 11, |
| 81 | + memberName: "minMaxLengthMap", |
| 82 | + }, |
| 83 | + ]); |
| 84 | + }); |
| 85 | + it("work for lists", () => { |
| 86 | + expect(LengthTests.validate({ minMaxLengthList: ["abc"] })).toEqual([ |
| 87 | + { |
| 88 | + constraintType: "length", |
| 89 | + constraintValues: [2, 4], |
| 90 | + failureValue: 1, |
| 91 | + memberName: "minMaxLengthList", |
| 92 | + }, |
| 93 | + ]); |
| 94 | + expect( |
| 95 | + LengthTests.validate({ |
| 96 | + minMaxLengthList: ["abc", "bcd", "cde", "def", "efg"], |
| 97 | + }) |
| 98 | + ).toEqual([ |
| 99 | + { |
| 100 | + constraintType: "length", |
| 101 | + constraintValues: [2, 4], |
| 102 | + failureValue: 5, |
| 103 | + memberName: "minMaxLengthList", |
| 104 | + }, |
| 105 | + ]); |
| 106 | + }); |
| 107 | + it("also work on list values", () => { |
| 108 | + expect( |
| 109 | + LengthTests.validate({ minMaxLengthList: ["abcdefghijk", "def"] }) |
| 110 | + ).toEqual([ |
| 111 | + { |
| 112 | + constraintType: "length", |
| 113 | + constraintValues: [2, 7], |
| 114 | + failureValue: 11, |
| 115 | + memberName: "minMaxLengthList", |
| 116 | + }, |
| 117 | + ]); |
| 118 | + }); |
| 119 | + it("work for blobs", () => { |
| 120 | + expect(LengthTests.validate({ minMaxLengthBlob: Buffer.of(1) })).toEqual([ |
| 121 | + { |
| 122 | + constraintType: "length", |
| 123 | + constraintValues: [2, 4], |
| 124 | + failureValue: 1, |
| 125 | + memberName: "minMaxLengthBlob", |
| 126 | + }, |
| 127 | + ]); |
| 128 | + expect( |
| 129 | + LengthTests.validate({ minMaxLengthBlob: Buffer.of(1, 2, 3, 4, 5) }) |
| 130 | + ).toEqual([ |
| 131 | + { |
| 132 | + constraintType: "length", |
| 133 | + constraintValues: [2, 4], |
| 134 | + failureValue: 5, |
| 135 | + memberName: "minMaxLengthBlob", |
| 136 | + }, |
| 137 | + ]); |
| 138 | + }); |
| 139 | + it("can be overridden on members", () => { |
| 140 | + expect(LengthTests.validate({ minMaxLengthOverride: "abcdef" })).toEqual([ |
| 141 | + { |
| 142 | + constraintType: "length", |
| 143 | + constraintValues: [13, 27], |
| 144 | + failureValue: 6, |
| 145 | + memberName: "minMaxLengthOverride", |
| 146 | + }, |
| 147 | + ]); |
| 148 | + }); |
105 | 149 | }); |
0 commit comments