Skip to content

Commit bc26f2e

Browse files
authored
fix(validation): Caching validation (#512)
1 parent 6085941 commit bc26f2e

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

src/__tests__/validation/__snapshots__/base.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Valdiation Caching Invalid should validate a Invalid 1`] = `
4+
"/caching/enabled: must be boolean
5+
/caching/behavior: must be one of 'FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'
6+
/caching/type: must be one of 'SMALL', 'MEDIUM', 'LARGE', 'XLARGE', 'LARGE_2X', 'LARGE_4X', 'LARGE_8X', 'LARGE_12X'
7+
/caching/ttl: must be integer
8+
/caching/atRestEncryption: must be boolean
9+
/caching/transitEncryption: must be boolean"
10+
`;
11+
12+
exports[`Valdiation Caching Invalid should validate a Ttl max value 1`] = `"/caching/ttl: must be <= 3600"`;
13+
14+
exports[`Valdiation Caching Invalid should validate a Ttl min value 1`] = `"/caching/ttl: must be >= 1"`;
15+
316
exports[`Valdiation Domain Invalid should validate a Invalid 1`] = `
417
"/domain/enabled: must be boolean
518
/domain/name: must be a valid domain name

src/__tests__/validation/base.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,87 @@ describe('Valdiation', () => {
303303
});
304304
});
305305
});
306+
307+
describe('Caching', () => {
308+
describe('Valid', () => {
309+
const assertions = [
310+
{
311+
name: 'Minimum',
312+
config: {
313+
...basicConfig,
314+
caching: {
315+
behavior: 'PER_RESOLVER_CACHING',
316+
},
317+
} as AppSyncConfigInput,
318+
},
319+
{
320+
name: 'Full',
321+
config: {
322+
...basicConfig,
323+
caching: {
324+
enabled: true,
325+
behavior: 'PER_RESOLVER_CACHING',
326+
type: 'SMALL',
327+
ttl: 3600,
328+
atRestEncryption: true,
329+
transitEncryption: true,
330+
},
331+
} as AppSyncConfigInput,
332+
},
333+
];
334+
335+
assertions.forEach((config) => {
336+
it(`should validate a ${config.name}`, () => {
337+
expect(validateConfig(config.config)).toBe(true);
338+
});
339+
});
340+
});
341+
342+
describe('Invalid', () => {
343+
const assertions = [
344+
{
345+
name: 'Invalid',
346+
config: {
347+
...basicConfig,
348+
caching: {
349+
enabled: 'foo',
350+
behavior: 'bar',
351+
type: 'INVALID',
352+
ttl: 'bizz',
353+
atRestEncryption: 'bizz',
354+
transitEncryption: 'bazz',
355+
},
356+
},
357+
},
358+
{
359+
name: 'Ttl min value',
360+
config: {
361+
...basicConfig,
362+
caching: {
363+
behavior: 'PER_RESOLVER_CACHING',
364+
ttl: 0,
365+
},
366+
},
367+
},
368+
{
369+
name: 'Ttl max value',
370+
config: {
371+
...basicConfig,
372+
caching: {
373+
behavior: 'PER_RESOLVER_CACHING',
374+
ttl: 3601,
375+
},
376+
},
377+
},
378+
];
379+
380+
assertions.forEach((config) => {
381+
it(`should validate a ${config.name}`, () => {
382+
expect(function () {
383+
validateConfig(config.config);
384+
}).toThrowErrorMatchingSnapshot();
385+
});
386+
});
387+
});
388+
});
306389
});

src/validation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export const appSyncSchema = {
354354
{
355355
type: 'object',
356356
properties: {
357-
ttl: { type: 'integer' },
357+
ttl: { type: 'integer', minimum: 1, maximum: 3600 },
358358
keys: {
359359
type: 'array',
360360
items: { type: 'string' },
@@ -681,7 +681,9 @@ export const appSyncSchema = {
681681
enabled: { type: 'boolean' },
682682
behavior: {
683683
type: 'string',
684-
enum: ['FULL_REQUEST_CACHING' || 'PER_RESOLVER_CACHING'],
684+
enum: ['FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'],
685+
errorMessage:
686+
"must be one of 'FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'",
685687
},
686688
type: {
687689
enum: [
@@ -694,13 +696,14 @@ export const appSyncSchema = {
694696
'LARGE_8X',
695697
'LARGE_12X',
696698
],
699+
errorMessage:
700+
"must be one of 'SMALL', 'MEDIUM', 'LARGE', 'XLARGE', 'LARGE_2X', 'LARGE_4X', 'LARGE_8X', 'LARGE_12X'",
697701
},
698-
ttl: { type: 'number' },
702+
ttl: { type: 'integer', minimum: 1, maximum: 3600 },
699703
atRestEncryption: { type: 'boolean' },
700704
transitEncryption: { type: 'boolean' },
701705
},
702706
required: ['behavior'],
703-
errorMessage: 'must be a valid caching config',
704707
},
705708
additionalAuthentications: {
706709
type: 'array',

0 commit comments

Comments
 (0)