-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathschema-testing.test.ts
55 lines (42 loc) · 1.92 KB
/
schema-testing.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// @ts-nocheck
import jsonSchemaDiff from 'json-schema-diff';
// The schema can be obtained from a repository or from Amazon EventBridge Schema Registry (the latter supports only OpenAPI 3.0 and Json Schema Draft 4 versions).
// Here we're just reading schemas from a local json file for simplicity.
import schema_v1_0_0 from '../schemas/json/customerCreated-v1.0.0.json';
import schema_v1_1_0 from '../schemas/json/customerCreated-v1.1.0.json';
import schema_v1_2_0 from '../schemas/json/customerCreated-v1.2.0.json';
import schema_v1_3_0 from '../schemas/json/customerCreated-v1.3.0.json';
describe('Schema testing examples', () => {
test('adding new optional elements is backward compatible', async () => {
const initialSchema = schema_v1_0_0;
const updatedSchema = schema_v1_1_0;
const result = await jsonSchemaDiff.diffSchemas({
sourceSchema: updatedSchema,
destinationSchema: initialSchema,
});
const isBreakingChange = result.removalsFound;
expect(isBreakingChange).toBeFalsy();
});
test('removing elements is a breaking change', async () => {
const initialSchema = schema_v1_1_0;
const updatedSchema = schema_v1_2_0;
const result = await jsonSchemaDiff.diffSchemas({
sourceSchema: updatedSchema,
destinationSchema: initialSchema,
});
const isBreakingChange = result.removalsFound;
expect(isBreakingChange).toBeTruthy();
});
test('adding new optional elements is considered backward compatible in spite of the logic change', async () => {
const initialSchema = schema_v1_0_0;
const updatedSchema = schema_v1_3_0;
const result = await jsonSchemaDiff.diffSchemas({
sourceSchema: updatedSchema,
destinationSchema: initialSchema,
});
const isBreakingChange = result.removalsFound;
expect(isBreakingChange).toBeFalsy();
});
});