@wise/dynamic-flow-client 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/build/flow/DynamicFlow.d.ts +1 -0
  2. package/build/flow/DynamicFlow.js +15 -5
  3. package/build/flow/DynamicFlowStep.d.ts +1 -0
  4. package/build/flow/errorBoundary/ErrorBoundaryAlert.d.ts +1 -0
  5. package/build/flow/fixtures/components/alert.d.ts +2 -2
  6. package/build/flow/fixtures/components/box.d.ts +2 -2
  7. package/build/flow/fixtures/components/button.d.ts +2 -2
  8. package/build/flow/fixtures/components/columns.d.ts +2 -2
  9. package/build/flow/fixtures/components/copyable.d.ts +2 -2
  10. package/build/flow/fixtures/components/decision.d.ts +2 -2
  11. package/build/flow/fixtures/components/heading.d.ts +2 -2
  12. package/build/flow/fixtures/components/image.d.ts +3 -2
  13. package/build/flow/fixtures/components/image.js +22 -3
  14. package/build/flow/fixtures/components/info.d.ts +2 -2
  15. package/build/flow/fixtures/components/list.d.ts +2 -2
  16. package/build/flow/fixtures/components/loading-indicator.d.ts +2 -2
  17. package/build/flow/fixtures/components/paragraph.d.ts +2 -2
  18. package/build/flow/fixtures/components/review.d.ts +2 -2
  19. package/build/flow/fixtures/examples/camera-capture.d.ts +2 -2
  20. package/build/flow/fixtures/examples/recipient-update.d.ts +2 -2
  21. package/build/flow/fixtures/examples/recipient-update.js +2 -2
  22. package/build/flow/fixtures/examples/recipient.d.ts +2 -2
  23. package/build/flow/fixtures/examples/single-file-upload.d.ts +2 -2
  24. package/build/flow/fixtures/examples/single-file-upload.js +32 -30
  25. package/build/flow/fixtures/examples/step-validation-errors.d.ts +2 -2
  26. package/build/flow/fixtures/features/action-response.d.ts +2 -2
  27. package/build/flow/fixtures/features/external.d.ts +2 -2
  28. package/build/flow/fixtures/features/persist-async.d.ts +2 -2
  29. package/build/flow/fixtures/features/polling.d.ts +2 -2
  30. package/build/flow/fixtures/features/validation-async.d.ts +3 -0
  31. package/build/flow/fixtures/features/validation-async.js +38 -0
  32. package/build/flow/fixtures/index.d.ts +34 -28
  33. package/build/flow/fixtures/index.js +8 -1
  34. package/build/flow/fixtures/responses/action-response-final.d.ts +2 -2
  35. package/build/flow/fixtures/responses/recipient-update-final.d.ts +2 -2
  36. package/build/flow/fixtures/schemas/basic-form.d.ts +2 -2
  37. package/build/flow/fixtures/schemas/number-and-integer.d.ts +2 -2
  38. package/build/flow/fixtures/schemas/one-of.d.ts +2 -2
  39. package/build/flow/fixtures/schemas/string-formats.d.ts +2 -2
  40. package/build/flow/fixtures/schemas/string-formats.js +6 -2
  41. package/build/flow/stories/DynamicFlow.story.d.ts +1 -0
  42. package/build/flow/stories/DynamicFlow.story.js +30 -0
  43. package/build/flow/stories/EditableDynamicFlow.d.ts +1 -0
  44. package/build/flow/stories/EditableDynamicFlow.js +2 -1
  45. package/build/flow/stories/fixtureFetcher.d.ts +2 -0
  46. package/build/flow/stories/fixtureFetcher.js +114 -0
  47. package/build/jsonSchemaForm/JsonSchemaForm.d.ts +1 -0
  48. package/build/jsonSchemaForm/allOfSchema/AllOfSchema.d.ts +1 -0
  49. package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.d.ts +1 -0
  50. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.d.ts +1 -0
  51. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.d.ts +1 -0
  52. package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.d.ts +1 -0
  53. package/build/jsonSchemaForm/controlFeedback/ControlFeedback.d.ts +1 -0
  54. package/build/jsonSchemaForm/genericSchema/GenericSchema.d.ts +1 -0
  55. package/build/jsonSchemaForm/help/Help.d.ts +1 -0
  56. package/build/jsonSchemaForm/objectSchema/ObjectSchema.d.ts +1 -0
  57. package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.d.ts +1 -0
  58. package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.d.ts +1 -0
  59. package/build/jsonSchemaForm/persistAsyncSchema/basic/PersistAsyncBasicSchema.d.ts +1 -0
  60. package/build/jsonSchemaForm/persistAsyncSchema/blob/PersistAsyncBlobSchema.d.ts +1 -0
  61. package/build/jsonSchemaForm/persistAsyncSchema/blob/UploadInputAdapter.d.ts +1 -0
  62. package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.d.ts +1 -0
  63. package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfCheckboxControl.d.ts +1 -0
  64. package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfRadioControl.d.ts +1 -0
  65. package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.d.ts +1 -0
  66. package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.d.ts +2 -1
  67. package/build/jsonSchemaForm/schemaFormControl/optionMapper.d.ts +7 -11
  68. package/build/jsonSchemaForm/schemaFormControl/optionMapper.js +12 -6
  69. package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.d.ts +1 -0
  70. package/build/layout/DynamicLayout.d.ts +1 -0
  71. package/build/layout/alert/index.d.ts +1 -0
  72. package/build/layout/box/index.d.ts +1 -0
  73. package/build/layout/button/index.d.ts +1 -0
  74. package/build/layout/columns/index.d.ts +1 -0
  75. package/build/layout/decision/index.d.ts +1 -0
  76. package/build/layout/divider/index.d.ts +1 -0
  77. package/build/layout/external/DynamicExternal.d.ts +1 -0
  78. package/build/layout/form/index.d.ts +1 -0
  79. package/build/layout/heading/index.d.ts +1 -0
  80. package/build/layout/icon/index.d.ts +1 -0
  81. package/build/layout/image/index.d.ts +4 -2
  82. package/build/layout/image/index.js +17 -38
  83. package/build/layout/info/index.d.ts +1 -0
  84. package/build/layout/list/index.d.ts +1 -0
  85. package/build/layout/loading-indicator/index.d.ts +1 -0
  86. package/build/layout/paragraph/DynamicParagraph.d.ts +1 -0
  87. package/build/layout/review/index.d.ts +1 -0
  88. package/build/main.css +45 -0
  89. package/build/step/cameraStep/CameraStep.d.ts +1 -0
  90. package/build/step/cameraStep/cameraCapture/CameraCapture.d.ts +1 -0
  91. package/build/step/cameraStep/cameraCapture/components/index.d.ts +1 -0
  92. package/build/step/cameraStep/cameraCapture/overlay/Overlay.d.ts +1 -0
  93. package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.d.ts +1 -0
  94. package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.d.ts +1 -0
  95. package/build/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +1 -0
  96. package/build/step/layoutStep/LayoutStep.d.ts +1 -0
  97. package/package.json +7 -5
  98. package/build/common/hooks/useDebouncedFunction.test.d.ts +0 -1
  99. package/build/common/hooks/useDebouncedFunction.test.js +0 -59
  100. package/build/common/logging/spec.d.ts +0 -1
  101. package/build/common/logging/spec.js +0 -45
  102. package/build/common/tracking/spec.d.ts +0 -1
  103. package/build/common/tracking/spec.js +0 -49
  104. package/build/common/utils/generate-random-id.test.d.ts +0 -1
  105. package/build/common/utils/generate-random-id.test.js +0 -12
  106. package/build/common/validation/rule-validators/spec.d.ts +0 -1
  107. package/build/common/validation/rule-validators/spec.js +0 -145
  108. package/build/common/validation/schema-validators/spec.d.ts +0 -1
  109. package/build/common/validation/schema-validators/spec.js +0 -137
  110. package/build/common/validation/valid-model/spec.d.ts +0 -1
  111. package/build/common/validation/valid-model/spec.js +0 -605
  112. package/build/common/validation/validation-failures/spec.d.ts +0 -1
  113. package/build/common/validation/validation-failures/spec.js +0 -185
  114. package/build/flow/response-parsers/spec.d.ts +0 -1
  115. package/build/flow/response-parsers/spec.js +0 -263
  116. package/build/layout/loading-indicator/spec.d.ts +0 -1
  117. package/build/layout/loading-indicator/spec.js +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Wise Dynamic Flow web client",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -33,10 +33,10 @@
33
33
  "@storybook/manager-webpack5": "6.5.16",
34
34
  "@storybook/react": "6.5.16",
35
35
  "@storybook/testing-library": "0.0.13",
36
- "@testing-library/dom": "8.20.0",
37
- "@testing-library/jest-dom": "5.14.1",
38
- "@testing-library/react-hooks": "^8.0.1",
39
- "@testing-library/react": "^12.0.0",
36
+ "@testing-library/dom": "9.2.0",
37
+ "@testing-library/jest-dom": "5.16.5",
38
+ "@testing-library/react-hooks": "8.0.1",
39
+ "@testing-library/react": "14.0.0",
40
40
  "@testing-library/user-event": "13.2.1",
41
41
  "@transferwise/components": "43.13.49",
42
42
  "@transferwise/eslint-config": "8.0.1",
@@ -61,6 +61,7 @@
61
61
  "eslint": "8.36.0",
62
62
  "jest-environment-jsdom": "29.5.0",
63
63
  "jest-fetch-mock": "^3.0.3",
64
+ "jest-watch-typeahead": "^2.2.2",
64
65
  "jest": "29.5.0",
65
66
  "npm-run-all": "4.1.5",
66
67
  "postcss-cli": "^10.1.0",
@@ -112,6 +113,7 @@
112
113
  "build:compiled-messages": "cpx 'src/i18n/*.json' build/i18n",
113
114
  "test": "npm-run-all test:once test:tz",
114
115
  "test:once": "jest --config jest.config.js --env=jsdom",
116
+ "test:coverage": "jest --config jest.config.js --env=jsdom --coverage",
115
117
  "test:tz": "TZ=US/Pacific jest ./src/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.errors.spec.js ./src/formControl/FormControl.spec.js",
116
118
  "test:watch": "pnpm test:once --watch",
117
119
  "lint": "npm-run-all lint:ts lint:css",
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { waitFor } from '@testing-library/react';
38
- import { renderHook } from '@testing-library/react-hooks';
39
- import { useDebouncedFunction } from './useDebouncedFunction';
40
- describe('useDebouncedFunction hook', function () {
41
- it('debounces a callback', function () { return __awaiter(void 0, void 0, void 0, function () {
42
- var callback, result;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0:
46
- callback = jest.fn();
47
- result = renderHook(function () { return useDebouncedFunction(callback, 200); }).result;
48
- result.current();
49
- expect(callback).not.toHaveBeenCalled();
50
- return [4 /*yield*/, waitFor(function () {
51
- expect(callback).toHaveBeenCalledTimes(1);
52
- }, { interval: 200 })];
53
- case 1:
54
- _a.sent();
55
- return [2 /*return*/];
56
- }
57
- });
58
- }); });
59
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,45 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { render } from '@testing-library/react';
14
- import { useEffect } from 'react';
15
- import { useLogger, LogProvider } from '.';
16
- describe('Logging Provider', function () {
17
- var TestChild = function () {
18
- var log = useLogger();
19
- useEffect(function () {
20
- // eslint-disable-next-line testing-library/no-debugging-utils
21
- log.debug('Deprecation advanced warning', 'Some description.');
22
- log.info('Invalid schema or model', 'Some description.');
23
- log.warning('Action supressed', 'Some description.');
24
- log.error('Deprecated schema', 'This schema is no longer supported.');
25
- log.critical('Deprecated schema', 'This schema is no longer supported.');
26
- }, []);
27
- return _jsx("span", { children: "info,error" });
28
- };
29
- describe('when provider is initialised with flowId and stepId', function () {
30
- describe('and is called within a component', function () {
31
- function renderComponent(onLog) {
32
- render(_jsx(LogProvider, __assign({ flowId: "myFlowId", stepId: "myStepId", onLog: onLog }, { children: _jsx(TestChild, {}) })));
33
- }
34
- it('calls the onLog callback', function () {
35
- var onLog = jest.fn();
36
- renderComponent(onLog);
37
- expect(onLog).toHaveBeenCalledWith('debug', 'Dynamic Flow debug - Deprecation advanced warning - Some description.', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId' }));
38
- expect(onLog).toHaveBeenCalledWith('info', 'Dynamic Flow info - Invalid schema or model - Some description.', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId' }));
39
- expect(onLog).toHaveBeenCalledWith('warning', 'Dynamic Flow warning - Action supressed - Some description.', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId' }));
40
- expect(onLog).toHaveBeenCalledWith('error', 'Dynamic Flow error - Deprecated schema - This schema is no longer supported.', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId' }));
41
- expect(onLog).toHaveBeenCalledWith('critical', 'Dynamic Flow critical - Deprecated schema - This schema is no longer supported.', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId' }));
42
- });
43
- });
44
- });
45
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,49 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { render } from '@testing-library/react';
14
- import { useEffect } from 'react';
15
- import { TrackingContextProvider, useTracking } from '.';
16
- describe('Tracking Provider', function () {
17
- var TestChild = function (_a) {
18
- var eventName = _a.eventName, properties = _a.properties;
19
- var trackEvent = useTracking();
20
- useEffect(function () {
21
- trackEvent(eventName, properties);
22
- }, []);
23
- return _jsx("span", { children: eventName });
24
- };
25
- describe('when provider is initialised with metadata', function () {
26
- describe('and is called upon mounting', function () {
27
- function renderComponent(onTrackableEvent) {
28
- render(_jsx(TrackingContextProvider, __assign({ metadata: { flowId: 'myFlowId', stepId: 'myStepId', custom: 'property' }, onTrackableEvent: onTrackableEvent }, { children: _jsx(TestChild, { eventName: "Dynamic Flow - Flow Started", properties: { custom: 'property' } }) })));
29
- }
30
- describe('it calls the onTrackableEvent callback', function () {
31
- it('with the specified eventName', function () {
32
- var onTrackableEvent = jest.fn();
33
- renderComponent(onTrackableEvent);
34
- expect(onTrackableEvent).toHaveBeenCalledWith('Dynamic Flow - Flow Started', expect.anything());
35
- });
36
- it('with the specified custom properties', function () {
37
- var onTrackableEvent = jest.fn();
38
- renderComponent(onTrackableEvent);
39
- expect(onTrackableEvent).toHaveBeenCalledWith('Dynamic Flow - Flow Started', expect.objectContaining({ custom: 'property' }));
40
- });
41
- it('with the specified flow and step ids any custom properties', function () {
42
- var onTrackableEvent = jest.fn();
43
- renderComponent(onTrackableEvent);
44
- expect(onTrackableEvent).toHaveBeenCalledWith('Dynamic Flow - Flow Started', expect.objectContaining({ flowId: 'myFlowId', stepId: 'myStepId', custom: 'property' }));
45
- });
46
- });
47
- });
48
- });
49
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { generateRandomId } from './generate-random-id';
2
- jest.spyOn(Math, 'random').mockReturnValue(0.123456789);
3
- describe('generateRandomId', function () {
4
- it('should generate a random id', function () {
5
- var id = generateRandomId();
6
- expect(id).toBe('12345678');
7
- });
8
- it('should generate a random id with a prefix', function () {
9
- var id = generateRandomId('prefix');
10
- expect(id).toBe('prefix-12345678');
11
- });
12
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,145 +0,0 @@
1
- import { isValidRequired, isValidMinLength, isValidMaxLength, isValidMinimum, isValidMaximum, isValidPattern, isValidMinItems, isValidMaxItems, isValidRequiredArray, } from '.';
2
- describe('Given a library for validating json schema rules', function () {
3
- describe('when establishing if a value passes required validation', function () {
4
- it('should return true if required and value defined', function () {
5
- expect(isValidRequired('something', true)).toBe(true);
6
- });
7
- it('should return false if required and value undefined', function () {
8
- expect(isValidRequired(undefined, true)).toBe(false);
9
- });
10
- it('should return true if not required', function () {
11
- expect(isValidRequired(undefined, false)).toBe(true);
12
- expect(isValidRequired('something', false)).toBe(true);
13
- });
14
- });
15
- describe('when establishing if a value passes minLength validation', function () {
16
- it('should return true if minLength exists and value matches or exceeds it', function () {
17
- expect(isValidMinLength('a', 1)).toBe(true);
18
- expect(isValidMinLength('ab', 1)).toBe(true);
19
- });
20
- it('should return false if minLength exists and value undefined', function () {
21
- expect(isValidMinLength(undefined, 1)).toBe(false);
22
- });
23
- it('should return false if minLength exists and value too short', function () {
24
- expect(isValidMinLength('', 1)).toBe(false);
25
- });
26
- it('should return true if minLength not defined', function () {
27
- expect(isValidMinLength('a', undefined)).toBe(true);
28
- });
29
- });
30
- describe('when establishing if a value passes maxLength validation', function () {
31
- it('should return true if maxLength exists and value matches or shorter than it', function () {
32
- expect(isValidMaxLength('', 2)).toBe(true);
33
- expect(isValidMaxLength('a', 2)).toBe(true);
34
- expect(isValidMaxLength('ab', 2)).toBe(true);
35
- });
36
- it('should return false if maxLength exists and value undefined', function () {
37
- expect(isValidMaxLength(undefined, 2)).toBe(false);
38
- });
39
- it('should return false if maxLength exists and value too long', function () {
40
- expect(isValidMaxLength('abc', 2)).toBe(false);
41
- });
42
- it('should return true if maxLength not defined', function () {
43
- expect(isValidMaxLength('a', undefined)).toBe(true);
44
- });
45
- });
46
- describe('when establishing if a value passes pattern validation', function () {
47
- it('should return true if pattern exists and value matches it', function () {
48
- expect(isValidPattern('a', '[a-z]+')).toBe(true);
49
- });
50
- it('should return false if pattern exists and value undefined', function () {
51
- expect(isValidPattern(undefined, '[a-z]+')).toBe(false);
52
- });
53
- it('should return false if pattern exists and value invalid', function () {
54
- expect(isValidPattern('012', '[a-z]+')).toBe(false);
55
- });
56
- it('should return true if pattern not defined', function () {
57
- expect(isValidPattern('a', undefined)).toBe(true);
58
- });
59
- });
60
- describe('when establishing if a value passes minimum validation', function () {
61
- it('should return true if min exists and value matches or exceeds it', function () {
62
- expect(isValidMinimum(1, 1)).toBe(true);
63
- expect(isValidMinimum(0, 0)).toBe(true);
64
- // FIXME - these are not valid
65
- // expect(isValidMinimum('2', '1')).toBe(true);
66
- // expect(isValidMinimum('1', '1')).toBe(true);
67
- // expect(isValidMinimum('0', '0')).toBe(true);
68
- });
69
- it('should return false if min exists and value undefined', function () {
70
- expect(isValidMinimum(undefined, 1)).toBe(false);
71
- });
72
- it('should return false if min exists and value too low', function () {
73
- expect(isValidMinimum(1, 2)).toBe(false);
74
- expect(isValidMinimum(-1, 0)).toBe(false);
75
- });
76
- it('should return true if min not defined', function () {
77
- expect(isValidMinimum(1, undefined)).toBe(true);
78
- });
79
- });
80
- describe('when establishing if a value passes maximum validation', function () {
81
- it('should return true if max exists and value matches or is lower than it', function () {
82
- expect(isValidMaximum(2, 2)).toBe(true);
83
- expect(isValidMaximum(-1, 0)).toBe(true);
84
- // FIXME - these are not valid
85
- // expect(isValidMaximum('2', '2')).toBe(true);
86
- // expect(isValidMaximum('0', '2')).toBe(true);
87
- });
88
- it('should return false if max exists and value undefined', function () {
89
- expect(isValidMaximum(undefined, 2)).toBe(false);
90
- });
91
- it('should return false if max exists and value too high', function () {
92
- expect(isValidMaximum(3, 2)).toBe(false);
93
- });
94
- it('should return true if max not defined', function () {
95
- expect(isValidMaximum(2, undefined)).toBe(true);
96
- });
97
- });
98
- describe('when establishing if an array passes minItems validation', function () {
99
- it('should return true if minItems exists and value length matches or exceeds it', function () {
100
- expect(isValidMinItems([1], 1)).toBe(true);
101
- expect(isValidMinItems([], 0)).toBe(true);
102
- });
103
- it('should return false if minItems exists and value undefined', function () {
104
- expect(isValidMinItems(undefined, 1)).toBe(false);
105
- });
106
- it('should return false if minItems exists and value too short', function () {
107
- expect(isValidMinItems([1], 2)).toBe(false);
108
- expect(isValidMinItems([], 1)).toBe(false);
109
- });
110
- it('should return true if minItems not defined', function () {
111
- expect(isValidMinItems([], undefined)).toBe(true);
112
- });
113
- });
114
- describe('when establishing if an array passes maxItems validation', function () {
115
- it('should return true if maxItems exists and value length matches or is less than it', function () {
116
- expect(isValidMaxItems([1], 1)).toBe(true);
117
- expect(isValidMaxItems([], 0)).toBe(true);
118
- });
119
- it('should return false if maxItems exists and value undefined', function () {
120
- expect(isValidMaxItems(undefined, 1)).toBe(false);
121
- });
122
- it('should return false if maxItems exists and value too long', function () {
123
- expect(isValidMaxItems([1, 2], 1)).toBe(false);
124
- });
125
- it('should return true if maxItems not defined', function () {
126
- expect(isValidMaxItems([], undefined)).toBe(true);
127
- });
128
- });
129
- describe('when establishing validations an array', function () {
130
- it('should return true all values for a non-required input', function () {
131
- expect(isValidRequiredArray([1], false)).toBe(true);
132
- expect(isValidRequiredArray([], false)).toBe(true);
133
- expect(isValidRequiredArray(undefined, false)).toBe(true);
134
- expect(isValidRequiredArray(null, false)).toBe(true);
135
- });
136
- it('should return true for only array values for a required input', function () {
137
- expect(isValidRequiredArray([1], true)).toBe(true);
138
- expect(isValidRequiredArray([], true)).toBe(true);
139
- });
140
- it('should return false for values for a required input', function () {
141
- expect(isValidRequiredArray(null, true)).toBe(false);
142
- expect(isValidRequiredArray(undefined, true)).toBe(false);
143
- });
144
- });
145
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,137 +0,0 @@
1
- import { isValidSchema } from '.';
2
- describe('Given a library for validating json schema models', function () {
3
- var schema;
4
- describe('when validating an object schema', function () {
5
- beforeEach(function () {
6
- schema = {
7
- type: 'object',
8
- properties: {
9
- a: {
10
- type: 'number',
11
- minimum: 2
12
- },
13
- b: {
14
- type: 'string',
15
- minLength: 3
16
- },
17
- c: {
18
- "const": true
19
- }
20
- },
21
- required: ['a', 'c'],
22
- displayOrder: ['a', 'b', 'c']
23
- };
24
- });
25
- it('should return false if the value is of an incorrect type', function () {
26
- expect(isValidSchema([1], schema)).toBe(false);
27
- });
28
- it('should return false if a required property is missing', function () {
29
- expect(isValidSchema({}, schema)).toBe(false);
30
- });
31
- it('should return false is a required property does not validate', function () {
32
- expect(isValidSchema({ a: 1, c: true }, schema)).toBe(false);
33
- });
34
- it('should return false if an optional property is invalid', function () {
35
- expect(isValidSchema({ a: 2, b: 'c', c: true }, schema)).toBe(false);
36
- });
37
- it('should return true if required properties validate and non-required fields are missing', function () {
38
- expect(isValidSchema({ a: 2, c: true }, schema)).toBe(true);
39
- });
40
- it('should return true if all properties validate', function () {
41
- expect(isValidSchema({ a: 2, b: 'cde', c: true }, schema)).toBe(true);
42
- });
43
- });
44
- describe('when validating an array schema', function () {
45
- beforeEach(function () {
46
- schema = {
47
- type: 'array',
48
- items: {
49
- type: 'string',
50
- minLength: 2
51
- },
52
- minItems: 2,
53
- maxItems: 2
54
- };
55
- });
56
- it('should return false if not an array', function () {
57
- expect(isValidSchema({ a: 1 }, schema)).toBe(false);
58
- });
59
- it('should return false if the array is too small', function () {
60
- expect(isValidSchema(['ab'], schema)).toBe(false);
61
- });
62
- it('should return false if the array is too long', function () {
63
- expect(isValidSchema(['ab', 'cd', 'ef'], schema)).toBe(false);
64
- });
65
- it('should return false if any of the items do not validate', function () {
66
- expect(isValidSchema(['ab', 'c'], schema)).toBe(false);
67
- });
68
- it('should return true is the array is correct size and items are valid', function () {
69
- expect(isValidSchema(['ab', 'cd'], schema)).toBe(true);
70
- });
71
- });
72
- describe('when validating a oneOf schema', function () {
73
- beforeEach(function () {
74
- schema = {
75
- oneOf: [
76
- {
77
- type: 'string',
78
- minLength: 2
79
- },
80
- {
81
- type: 'number',
82
- minimum: 2
83
- },
84
- ]
85
- };
86
- });
87
- it('should return false if neither schema validates', function () {
88
- expect(isValidSchema(true, schema)).toBe(false);
89
- expect(isValidSchema('a', schema)).toBe(false);
90
- expect(isValidSchema(1, schema)).toBe(false);
91
- });
92
- it('should return true if either schema validates', function () {
93
- expect(isValidSchema('ab', schema)).toBe(true);
94
- expect(isValidSchema(2, schema)).toBe(true);
95
- });
96
- });
97
- describe('when validating an allOf schema', function () {
98
- beforeEach(function () {
99
- schema = {
100
- allOf: [
101
- {
102
- type: 'object',
103
- properties: {
104
- a: {
105
- type: 'string',
106
- minLength: 2
107
- }
108
- },
109
- displayOrder: ['a'],
110
- required: ['a']
111
- },
112
- {
113
- type: 'object',
114
- properties: {
115
- b: {
116
- type: 'number',
117
- minimum: 2
118
- }
119
- },
120
- displayOrder: ['b'],
121
- required: ['b']
122
- },
123
- ]
124
- };
125
- });
126
- it('should return false if only one schema is present', function () {
127
- expect(isValidSchema({ a: 'bc' }, schema)).toBe(false);
128
- expect(isValidSchema({ b: 2 }, schema)).toBe(false);
129
- });
130
- it('should return false if any schemas are invalid', function () {
131
- expect(isValidSchema({ a: 'bc', b: 1 }, schema)).toBe(false);
132
- });
133
- it('should return true if both schemas validate', function () {
134
- expect(isValidSchema({ a: 'bc', b: 2 }, schema)).toBe(true);
135
- });
136
- });
137
- });
@@ -1 +0,0 @@
1
- export {};