Skip to content

Commit

Permalink
fix(validation): Caching validation (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboure authored Jun 15, 2022
1 parent 6085941 commit bc26f2e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/__tests__/validation/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Valdiation Caching Invalid should validate a Invalid 1`] = `
"/caching/enabled: must be boolean
/caching/behavior: must be one of 'FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'
/caching/type: must be one of 'SMALL', 'MEDIUM', 'LARGE', 'XLARGE', 'LARGE_2X', 'LARGE_4X', 'LARGE_8X', 'LARGE_12X'
/caching/ttl: must be integer
/caching/atRestEncryption: must be boolean
/caching/transitEncryption: must be boolean"
`;

exports[`Valdiation Caching Invalid should validate a Ttl max value 1`] = `"/caching/ttl: must be <= 3600"`;

exports[`Valdiation Caching Invalid should validate a Ttl min value 1`] = `"/caching/ttl: must be >= 1"`;

exports[`Valdiation Domain Invalid should validate a Invalid 1`] = `
"/domain/enabled: must be boolean
/domain/name: must be a valid domain name
Expand Down
83 changes: 83 additions & 0 deletions src/__tests__/validation/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,87 @@ describe('Valdiation', () => {
});
});
});

describe('Caching', () => {
describe('Valid', () => {
const assertions = [
{
name: 'Minimum',
config: {
...basicConfig,
caching: {
behavior: 'PER_RESOLVER_CACHING',
},
} as AppSyncConfigInput,
},
{
name: 'Full',
config: {
...basicConfig,
caching: {
enabled: true,
behavior: 'PER_RESOLVER_CACHING',
type: 'SMALL',
ttl: 3600,
atRestEncryption: true,
transitEncryption: true,
},
} as AppSyncConfigInput,
},
];

assertions.forEach((config) => {
it(`should validate a ${config.name}`, () => {
expect(validateConfig(config.config)).toBe(true);
});
});
});

describe('Invalid', () => {
const assertions = [
{
name: 'Invalid',
config: {
...basicConfig,
caching: {
enabled: 'foo',
behavior: 'bar',
type: 'INVALID',
ttl: 'bizz',
atRestEncryption: 'bizz',
transitEncryption: 'bazz',
},
},
},
{
name: 'Ttl min value',
config: {
...basicConfig,
caching: {
behavior: 'PER_RESOLVER_CACHING',
ttl: 0,
},
},
},
{
name: 'Ttl max value',
config: {
...basicConfig,
caching: {
behavior: 'PER_RESOLVER_CACHING',
ttl: 3601,
},
},
},
];

assertions.forEach((config) => {
it(`should validate a ${config.name}`, () => {
expect(function () {
validateConfig(config.config);
}).toThrowErrorMatchingSnapshot();
});
});
});
});
});
11 changes: 7 additions & 4 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const appSyncSchema = {
{
type: 'object',
properties: {
ttl: { type: 'integer' },
ttl: { type: 'integer', minimum: 1, maximum: 3600 },
keys: {
type: 'array',
items: { type: 'string' },
Expand Down Expand Up @@ -681,7 +681,9 @@ export const appSyncSchema = {
enabled: { type: 'boolean' },
behavior: {
type: 'string',
enum: ['FULL_REQUEST_CACHING' || 'PER_RESOLVER_CACHING'],
enum: ['FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'],
errorMessage:
"must be one of 'FULL_REQUEST_CACHING', 'PER_RESOLVER_CACHING'",
},
type: {
enum: [
Expand All @@ -694,13 +696,14 @@ export const appSyncSchema = {
'LARGE_8X',
'LARGE_12X',
],
errorMessage:
"must be one of 'SMALL', 'MEDIUM', 'LARGE', 'XLARGE', 'LARGE_2X', 'LARGE_4X', 'LARGE_8X', 'LARGE_12X'",
},
ttl: { type: 'number' },
ttl: { type: 'integer', minimum: 1, maximum: 3600 },
atRestEncryption: { type: 'boolean' },
transitEncryption: { type: 'boolean' },
},
required: ['behavior'],
errorMessage: 'must be a valid caching config',
},
additionalAuthentications: {
type: 'array',
Expand Down

0 comments on commit bc26f2e

Please sign in to comment.