|
9 | 9 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
10 | 10 | import { map, mergeMap } from 'rxjs/operators';
|
11 | 11 | import { SchemaFormat } from './interface';
|
12 |
| -import { CoreSchemaRegistry } from './registry'; |
| 12 | +import { CoreSchemaRegistry, SchemaValidationException } from './registry'; |
13 | 13 | import { addUndefinedDefaults } from './transforms';
|
14 | 14 |
|
15 | 15 | describe('CoreSchemaRegistry', () => {
|
@@ -138,6 +138,31 @@ describe('CoreSchemaRegistry', () => {
|
138 | 138 | .then(done, done.fail);
|
139 | 139 | });
|
140 | 140 |
|
| 141 | + it('fails on invalid enum value', (done) => { |
| 142 | + const registry = new CoreSchemaRegistry(); |
| 143 | + registry.addPostTransform(addUndefinedDefaults); |
| 144 | + const data = { packageManager: 'foo' }; |
| 145 | + |
| 146 | + registry |
| 147 | + .compile({ |
| 148 | + properties: { |
| 149 | + packageManager: { type: 'string', enum: ['npm', 'yarn', 'pnpm', 'cnpm'] }, |
| 150 | + }, |
| 151 | + additionalProperties: false, |
| 152 | + }) |
| 153 | + .pipe( |
| 154 | + mergeMap((validator) => validator(data)), |
| 155 | + map((result) => { |
| 156 | + expect(result.success).toBe(false); |
| 157 | + expect(new SchemaValidationException(result.errors).message).toContain( |
| 158 | + `Data path "/packageManager" must be equal to one of the allowed values. Allowed values are: "npm", "yarn", "pnpm", "cnpm".`, |
| 159 | + ); |
| 160 | + }), |
| 161 | + ) |
| 162 | + .toPromise() |
| 163 | + .then(done, done.fail); |
| 164 | + }); |
| 165 | + |
141 | 166 | it('fails on invalid additionalProperties async', (done) => {
|
142 | 167 | const registry = new CoreSchemaRegistry();
|
143 | 168 | registry.addPostTransform(addUndefinedDefaults);
|
|
0 commit comments