@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.14
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.
- package/.mocharc.yml +1 -1
- package/Cargo.toml +5 -2
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/wasm/wasm_dpp.d.ts +3397 -1237
- package/karma.conf.js +5 -0
- package/lib/identifier/patchIdentifier.ts +5 -4
- package/lib/index.ts +1 -1
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/fixtures/getDataContractFixture.js +267 -0
- package/lib/test/fixtures/getDocumentsFixture.js +43 -0
- package/lib/test/mocks/createStateRepositoryMock.js +64 -0
- package/lib/test/mocks/getBlsAdapterMock.js +51 -0
- package/package.json +11 -8
- package/src/bls_adapter.rs +17 -1
- package/src/buffer.rs +3 -0
- package/src/dash_platform_protocol.rs +107 -10
- package/src/data_contract/data_contract.rs +59 -10
- package/src/data_contract/data_contract_facade.rs +128 -0
- package/src/data_contract/errors/invalid_data_contract.rs +16 -16
- package/src/data_contract/errors/invalid_document_type.rs +8 -8
- package/src/data_contract/errors/mod.rs +10 -16
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +4 -0
- package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +41 -10
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +35 -4
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +20 -7
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +47 -11
- package/src/data_contract_factory/data_contract_factory.rs +19 -17
- package/src/data_trigger/data_trigger_execution_context.rs +95 -0
- package/src/data_trigger/data_trigger_execution_result.rs +48 -0
- package/src/data_trigger/execute_data_triggers_factory.rs +60 -0
- package/src/data_trigger/get_data_triggers_factory.rs +65 -0
- package/src/data_trigger/mod.rs +121 -0
- package/src/document/document_facade.rs +125 -0
- package/src/document/errors/invalid_document_error.rs +10 -9
- package/src/document/errors/invalid_initial_revision_error.rs +1 -1
- package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
- package/src/document/errors/mod.rs +17 -13
- package/src/document/errors/no_documents_supplied_error.rs +4 -4
- package/src/document/factory.rs +257 -0
- package/src/document/fetch_and_validate_data_contract.rs +77 -0
- package/src/document/generate_document_id.rs +17 -0
- package/src/document/mod.rs +311 -37
- package/src/document/state_transition/document_batch_transition/apply_document_batch_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +253 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +60 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +263 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +302 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_id.rs +40 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_indices.rs +50 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/mod.rs +8 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_documents_batch_transition_basic.rs +34 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_partial_compound_indices.rs +39 -0
- package/src/document/state_transition/document_batch_transition/validation/mod.rs +2 -0
- package/src/document/state_transition/document_batch_transition/validation/state/fetch_documents.rs +43 -0
- package/src/document/state_transition/document_batch_transition/validation/state/mod.rs +3 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_batch_transitions_state.rs +27 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_uniqueness_by_indices.rs +47 -0
- package/src/document/validator.rs +52 -0
- package/src/errors/compatible_protocol_version_is_not_defined_error.rs +24 -0
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +1 -1
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +1 -1
- package/src/errors/consensus/basic/document/inconsistent_compound_index_data_error.rs +2 -2
- package/src/errors/consensus/basic/document/invalid_document_type_error.rs +15 -1
- package/src/errors/consensus/basic/document/missing_data_contract_id_error.rs +16 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +1 -1
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_core_fee_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_pooling_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_key_signature_error.rs +4 -3
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_data_error.rs +1 -1
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +1 -1
- package/src/errors/consensus/basic/identity/missing_public_key_error.rs +4 -3
- package/src/errors/consensus/basic/identity/mod.rs +2 -0
- package/src/errors/consensus/basic/invalid_identifier_error.rs +1 -1
- package/src/errors/consensus/basic/json_schema_error.rs +8 -2
- package/src/errors/consensus/basic/public_key_is_disabled_error.rs +1 -1
- package/src/errors/consensus/state/document/document_timestamp_window_violation_error.rs +9 -9
- package/src/errors/consensus/state/document/invalid_document_revision_error.rs +4 -4
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_id_state_error.rs +35 -0
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_state_error.rs +34 -0
- package/src/errors/consensus/state/identity/identity_public_key_disabled_at_window_violation_error.rs +10 -7
- package/src/errors/consensus/state/identity/identity_public_key_is_disabled_error.rs +2 -3
- package/src/errors/consensus/state/identity/identity_public_key_is_read_only_error.rs +7 -3
- package/src/errors/consensus/state/identity/invalid_identity_public_key_id_error.rs +2 -3
- package/src/errors/consensus/state/identity/invalid_identity_revision_error.rs +7 -4
- package/src/errors/consensus/state/identity/max_identity_public_key_limit_reached_error.rs +2 -1
- package/src/errors/consensus/state/identity/mod.rs +4 -0
- package/src/errors/consensus_error.rs +218 -268
- package/src/errors/data_contract_not_present_error.rs +23 -0
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +22 -0
- package/src/errors/js_conversion.rs +52 -5
- package/src/errors/mod.rs +6 -0
- package/src/errors/protocol_error.rs +14 -3
- package/src/identifier/errors.rs +30 -0
- package/src/identifier/mod.rs +95 -11
- package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
- package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
- package/src/identity/errors/invalid_identity_error.rs +32 -0
- package/src/identity/errors/mod.rs +9 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/factory_utils.rs +87 -0
- package/src/identity/identity_facade.rs +194 -20
- package/src/identity/identity_factory.rs +209 -0
- package/src/identity/identity_public_key/mod.rs +51 -40
- package/src/identity/mod.rs +31 -17
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
- package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +337 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +45 -0
- package/src/identity/state_transition/identity_public_key_transitions.rs +207 -0
- package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +278 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
- package/src/identity/state_transition/identity_update_transition/apply_identity_update_transition.rs +24 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_public_keys_validator.rs +55 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +448 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_basic_validator.rs +94 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_state_validator.rs +53 -0
- package/src/identity/state_transition/identity_update_transition/mod.rs +9 -0
- package/src/identity/state_transition/identity_update_transition/to_object.rs +66 -0
- package/src/identity/state_transition/mod.rs +12 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +61 -0
- package/src/identity/validation/identity_validator.rs +50 -0
- package/src/identity/validation/mod.rs +2 -0
- package/src/identity/validation/public_keys_validator.rs +14 -13
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +6 -0
- package/src/lodash.rs +7 -0
- package/src/metadata.rs +54 -10
- package/src/state_repository.rs +598 -101
- package/src/state_transition/conversion.rs +104 -0
- package/src/state_transition/errors/invalid_state_transition_error.rs +32 -0
- package/src/state_transition/errors/mod.rs +1 -0
- package/src/state_transition/mod.rs +46 -0
- package/src/state_transition/state_transition_facade.rs +263 -0
- package/src/state_transition/state_transition_factory.rs +216 -0
- package/src/state_transition/validation/mod.rs +1 -0
- package/src/state_transition/validation/validate_state_transition_key_signature.rs +62 -0
- package/src/utils.rs +210 -8
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +29 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +103 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +46 -30
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +45 -127
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +91 -139
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +577 -503
- package/test/integration/document/Document.spec.js +55 -29
- package/test/integration/document/DocumentFacade.spec.js +51 -64
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +38 -16
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +341 -396
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +116 -218
- package/test/integration/document/validation/validateDocumentFactory.spec.js +123 -171
- package/test/integration/identity/IdentityFacade.spec.js +52 -27
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +185 -164
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +84 -114
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +120 -137
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +106 -91
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +50 -16
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +78 -86
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +74 -30
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -147
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +65 -77
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +60 -23
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +46 -114
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +9 -3
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +12 -8
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +95 -233
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +53 -0
- package/test/unit/Identifier.spec.js +36 -36
- package/test/unit/Metadata.spec.js +17 -3
- package/test/unit/dataContract/DataContract.spec.js +9 -4
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +25 -31
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +3 -3
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +2 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +153 -153
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +59 -14
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +131 -62
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +144 -56
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +38 -8
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +11 -7
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +29 -18
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +38 -29
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +53 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +357 -493
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +133 -72
- package/test/unit/identity/Identity.spec.js +26 -9
- package/test/unit/identity/IdentityFactory.spec.js +81 -89
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +73 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +38 -38
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +34 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +85 -50
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +44 -22
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +58 -103
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +49 -101
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +23 -25
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +73 -46
- package/test/unit/version/validateProtocolVersionFactory.spec.js +45 -27
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +3397 -1237
- package/wasm/wasm_dpp.js +7158 -1384
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +777 -389
- package/webpack.config.js +9 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_update_transition.rs +0 -22
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +0 -135
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +0 -54
|
@@ -1,86 +1,65 @@
|
|
|
1
|
-
const { getRE2Class } = require('@dashevo/wasm-re2');
|
|
2
1
|
const lodashCloneDeep = require('lodash/cloneDeep');
|
|
3
|
-
|
|
4
|
-
const $RefParser = require('@apidevtools/json-schema-ref-parser');
|
|
5
|
-
|
|
6
|
-
const createAjv = require('@dashevo/dpp/lib/ajv/createAjv');
|
|
7
|
-
|
|
8
|
-
const JsonSchemaValidator = require('@dashevo/dpp/lib/validation/JsonSchemaValidator');
|
|
9
|
-
|
|
10
|
-
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
11
|
-
|
|
12
|
-
const validateDataContractFactory = require('@dashevo/dpp/lib/dataContract/validation/validateDataContractFactory');
|
|
13
|
-
const validateDataContractMaxDepthFactory = require('@dashevo/dpp/lib/dataContract/validation/validateDataContractMaxDepthFactory');
|
|
14
|
-
const enrichDataContractWithBaseSchema = require('@dashevo/dpp/lib/dataContract/enrichDataContractWithBaseSchema');
|
|
15
|
-
const validateDataContractPatternsFactory = require('@dashevo/dpp/lib/dataContract/validation/validateDataContractPatternsFactory');
|
|
16
|
-
|
|
17
2
|
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
3
|
+
const { expectJsonSchemaError, expectValidationError } = require('../../../../lib/test/expect/expectError');
|
|
18
4
|
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
const DuplicateIndexError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/DuplicateIndexError');
|
|
22
|
-
const UndefinedIndexPropertyError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/UndefinedIndexPropertyError');
|
|
23
|
-
const InvalidIndexPropertyTypeError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/InvalidIndexPropertyTypeError');
|
|
24
|
-
const SystemPropertyIndexAlreadyPresentError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/SystemPropertyIndexAlreadyPresentError');
|
|
25
|
-
const UniqueIndicesLimitReachedError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/UniqueIndicesLimitReachedError');
|
|
26
|
-
const InvalidIndexedPropertyConstraintError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/InvalidIndexedPropertyConstraintError');
|
|
27
|
-
const InvalidCompoundIndexError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/InvalidCompoundIndexError');
|
|
28
|
-
const IncompatibleRe2PatternError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/IncompatibleRe2PatternError');
|
|
29
|
-
const InvalidJsonSchemaRefError = require('@dashevo/dpp/lib/errors/consensus/basic/dataContract/InvalidJsonSchemaRefError');
|
|
30
|
-
const JsonSchemaCompilationError = require('@dashevo/dpp/lib/errors/consensus/basic/JsonSchemaCompilationError');
|
|
31
|
-
const SomeConsensusError = require('@dashevo/dpp/lib/test/mocks/SomeConsensusError');
|
|
32
|
-
const getPropertyDefinitionByPath = require('@dashevo/dpp/lib/dataContract/getPropertyDefinitionByPath');
|
|
33
|
-
|
|
34
|
-
describe('validateDataContractFactory', function main() {
|
|
35
|
-
this.timeout(15000);
|
|
5
|
+
const { default: loadWasmDpp } = require('../../../../dist');
|
|
36
6
|
|
|
7
|
+
describe('validateDataContractFactory', () => {
|
|
37
8
|
let dataContract;
|
|
38
|
-
let rawDataContract;
|
|
39
9
|
let validateDataContract;
|
|
40
|
-
|
|
41
|
-
let
|
|
10
|
+
|
|
11
|
+
let DataContractValidator;
|
|
12
|
+
let ValidationResult;
|
|
13
|
+
let JsonSchemaCompilationError;
|
|
14
|
+
let IncompatibleRe2PatternError;
|
|
15
|
+
let DuplicateIndexError;
|
|
16
|
+
let UndefinedIndexPropertyError;
|
|
17
|
+
let UniqueIndicesLimitReachedError;
|
|
18
|
+
let SystemPropertyIndexAlreadyPresentError;
|
|
19
|
+
let InvalidIndexPropertyTypeError;
|
|
20
|
+
let InvalidCompoundIndexError;
|
|
21
|
+
let InvalidIndexedPropertyConstraintError;
|
|
22
|
+
let InvalidJsonSchemaRefError;
|
|
42
23
|
|
|
43
24
|
before(async () => {
|
|
44
|
-
|
|
25
|
+
({
|
|
26
|
+
DataContractValidator,
|
|
27
|
+
ValidationResult,
|
|
28
|
+
JsonSchemaCompilationError,
|
|
29
|
+
IncompatibleRe2PatternError,
|
|
30
|
+
DuplicateIndexError,
|
|
31
|
+
UndefinedIndexPropertyError,
|
|
32
|
+
UniqueIndicesLimitReachedError,
|
|
33
|
+
SystemPropertyIndexAlreadyPresentError,
|
|
34
|
+
InvalidIndexPropertyTypeError,
|
|
35
|
+
InvalidCompoundIndexError,
|
|
36
|
+
InvalidIndexedPropertyConstraintError,
|
|
37
|
+
InvalidJsonSchemaRefError,
|
|
38
|
+
} = await loadWasmDpp());
|
|
45
39
|
});
|
|
46
40
|
|
|
47
|
-
beforeEach(async
|
|
41
|
+
beforeEach(async () => {
|
|
48
42
|
dataContract = getDataContractFixture();
|
|
49
|
-
rawDataContract = dataContract.toObject();
|
|
50
|
-
|
|
51
|
-
const ajv = createAjv(RE2);
|
|
52
|
-
const jsonSchemaValidator = new JsonSchemaValidator(ajv);
|
|
53
43
|
|
|
54
|
-
const
|
|
44
|
+
const dataContractValidator = new DataContractValidator();
|
|
55
45
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
validateProtocolVersionMock = this.sinonSandbox.stub().returns(new ValidationResult());
|
|
46
|
+
validateDataContract = (contract) => dataContractValidator.validate(contract);
|
|
47
|
+
});
|
|
59
48
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
validateDataContractPatterns,
|
|
65
|
-
validateProtocolVersionMock,
|
|
66
|
-
getPropertyDefinitionByPath,
|
|
67
|
-
);
|
|
49
|
+
it('should pass validation if created from a fixture', () => {
|
|
50
|
+
const rawDataContract = dataContract.toObject();
|
|
51
|
+
const result = validateDataContract(rawDataContract);
|
|
52
|
+
expect(result.isValid()).to.be.true();
|
|
68
53
|
});
|
|
69
54
|
|
|
70
55
|
describe('protocolVersion', () => {
|
|
71
56
|
it('should be present', async () => {
|
|
72
|
-
rawDataContract =
|
|
73
|
-
documents: {
|
|
74
|
-
someDocument: {
|
|
75
|
-
type: 'object',
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
57
|
+
const rawDataContract = dataContract.toObject();
|
|
79
58
|
delete rawDataContract.protocolVersion;
|
|
80
59
|
|
|
81
|
-
const result =
|
|
60
|
+
const result = validateDataContract(rawDataContract);
|
|
82
61
|
|
|
83
|
-
expectJsonSchemaError(result);
|
|
62
|
+
await expectJsonSchemaError(result);
|
|
84
63
|
|
|
85
64
|
const [error] = result.getErrors();
|
|
86
65
|
|
|
@@ -90,11 +69,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
90
69
|
});
|
|
91
70
|
|
|
92
71
|
it('should be an integer', async () => {
|
|
72
|
+
const rawDataContract = dataContract.toObject();
|
|
73
|
+
|
|
93
74
|
rawDataContract.protocolVersion = '1';
|
|
94
75
|
|
|
95
76
|
const result = await validateDataContract(rawDataContract);
|
|
96
77
|
|
|
97
|
-
expectJsonSchemaError(result);
|
|
78
|
+
await expectJsonSchemaError(result);
|
|
98
79
|
|
|
99
80
|
const [error] = result.getErrors();
|
|
100
81
|
|
|
@@ -102,37 +83,28 @@ describe('validateDataContractFactory', function main() {
|
|
|
102
83
|
expect(error.getKeyword()).to.equal('type');
|
|
103
84
|
});
|
|
104
85
|
|
|
105
|
-
it('should be
|
|
86
|
+
it('should be an unsigned integer', async () => {
|
|
87
|
+
const rawDataContract = dataContract.toObject();
|
|
106
88
|
rawDataContract.protocolVersion = -1;
|
|
107
89
|
|
|
108
|
-
const protocolVersionError = new SomeConsensusError('test');
|
|
109
|
-
const protocolVersionResult = new ValidationResult([
|
|
110
|
-
protocolVersionError,
|
|
111
|
-
]);
|
|
112
|
-
|
|
113
|
-
validateProtocolVersionMock.returns(protocolVersionResult);
|
|
114
|
-
|
|
115
90
|
const result = await validateDataContract(rawDataContract);
|
|
116
|
-
|
|
117
|
-
expectValidationError(result, SomeConsensusError);
|
|
91
|
+
await expectJsonSchemaError(result);
|
|
118
92
|
|
|
119
93
|
const [error] = result.getErrors();
|
|
120
94
|
|
|
121
|
-
expect(error).to.equal(
|
|
122
|
-
|
|
123
|
-
expect(validateProtocolVersionMock).to.be.calledOnceWith(
|
|
124
|
-
rawDataContract.protocolVersion,
|
|
125
|
-
);
|
|
95
|
+
expect(error.getInstancePath()).to.equal('/protocolVersion');
|
|
96
|
+
expect(error.getKeyword()).to.equal('minimum');
|
|
126
97
|
});
|
|
127
98
|
});
|
|
128
99
|
|
|
129
100
|
describe('$schema', () => {
|
|
130
101
|
it('should be present', async () => {
|
|
102
|
+
const rawDataContract = dataContract.toObject();
|
|
131
103
|
delete rawDataContract.$schema;
|
|
132
104
|
|
|
133
105
|
const result = await validateDataContract(rawDataContract);
|
|
134
106
|
|
|
135
|
-
expectJsonSchemaError(result);
|
|
107
|
+
await expectJsonSchemaError(result);
|
|
136
108
|
|
|
137
109
|
const [error] = result.getErrors();
|
|
138
110
|
|
|
@@ -142,24 +114,29 @@ describe('validateDataContractFactory', function main() {
|
|
|
142
114
|
});
|
|
143
115
|
|
|
144
116
|
it('should be a string', async () => {
|
|
117
|
+
const rawDataContract = dataContract.toObject();
|
|
145
118
|
rawDataContract.$schema = 1;
|
|
146
119
|
|
|
147
120
|
const result = await validateDataContract(rawDataContract);
|
|
148
121
|
|
|
149
|
-
expectJsonSchemaError(result);
|
|
122
|
+
await expectJsonSchemaError(result, 2);
|
|
150
123
|
|
|
151
|
-
const [
|
|
124
|
+
const [typeError, constError] = result.getErrors();
|
|
152
125
|
|
|
153
|
-
expect(
|
|
154
|
-
expect(
|
|
126
|
+
expect(typeError.getInstancePath()).to.equal('/$schema');
|
|
127
|
+
expect(typeError.getKeyword()).to.equal('type');
|
|
128
|
+
|
|
129
|
+
expect(constError.getInstancePath()).to.equal('/$schema');
|
|
130
|
+
expect(constError.getKeyword()).to.equal('const');
|
|
155
131
|
});
|
|
156
132
|
|
|
157
133
|
it('should be a particular url', async () => {
|
|
134
|
+
const rawDataContract = dataContract.toObject();
|
|
158
135
|
rawDataContract.$schema = 'wrong';
|
|
159
136
|
|
|
160
137
|
const result = await validateDataContract(rawDataContract);
|
|
161
138
|
|
|
162
|
-
expectJsonSchemaError(result);
|
|
139
|
+
await expectJsonSchemaError(result);
|
|
163
140
|
|
|
164
141
|
const [error] = result.getErrors();
|
|
165
142
|
|
|
@@ -170,11 +147,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
170
147
|
|
|
171
148
|
describe('ownerId', () => {
|
|
172
149
|
it('should be present', async () => {
|
|
150
|
+
const rawDataContract = dataContract.toObject();
|
|
173
151
|
delete rawDataContract.ownerId;
|
|
174
152
|
|
|
175
153
|
const result = await validateDataContract(rawDataContract);
|
|
176
154
|
|
|
177
|
-
expectJsonSchemaError(result);
|
|
155
|
+
await expectJsonSchemaError(result);
|
|
178
156
|
|
|
179
157
|
const [error] = result.getErrors();
|
|
180
158
|
|
|
@@ -184,26 +162,26 @@ describe('validateDataContractFactory', function main() {
|
|
|
184
162
|
});
|
|
185
163
|
|
|
186
164
|
it('should be a byte array', async () => {
|
|
165
|
+
const rawDataContract = dataContract.toObject();
|
|
187
166
|
rawDataContract.ownerId = new Array(32).fill('string');
|
|
188
167
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
168
|
+
// We decided to keep protocol error because of failed parse rather than doing hacks
|
|
169
|
+
// too keep it until validator will refuse it
|
|
170
|
+
try {
|
|
171
|
+
await validateDataContract(rawDataContract);
|
|
172
|
+
expect.fail('Should throw an error');
|
|
173
|
+
} catch (e) {
|
|
174
|
+
expect(e).to.have.string('invalid type: string');
|
|
175
|
+
}
|
|
199
176
|
});
|
|
200
177
|
|
|
201
178
|
it('should be no less than 32 bytes', async () => {
|
|
179
|
+
const rawDataContract = dataContract.toObject();
|
|
202
180
|
rawDataContract.ownerId = Buffer.alloc(31);
|
|
203
181
|
|
|
204
182
|
const result = await validateDataContract(rawDataContract);
|
|
205
183
|
|
|
206
|
-
expectJsonSchemaError(result);
|
|
184
|
+
await expectJsonSchemaError(result);
|
|
207
185
|
|
|
208
186
|
const [error] = result.getErrors();
|
|
209
187
|
|
|
@@ -212,11 +190,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
212
190
|
});
|
|
213
191
|
|
|
214
192
|
it('should be no longer than 32 bytes', async () => {
|
|
193
|
+
const rawDataContract = dataContract.toObject();
|
|
215
194
|
rawDataContract.ownerId = Buffer.alloc(33);
|
|
216
195
|
|
|
217
196
|
const result = await validateDataContract(rawDataContract);
|
|
218
197
|
|
|
219
|
-
expectJsonSchemaError(result);
|
|
198
|
+
await expectJsonSchemaError(result);
|
|
220
199
|
|
|
221
200
|
const [error] = result.getErrors();
|
|
222
201
|
|
|
@@ -227,11 +206,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
227
206
|
|
|
228
207
|
describe('$id', () => {
|
|
229
208
|
it('should be present', async () => {
|
|
209
|
+
const rawDataContract = dataContract.toObject();
|
|
230
210
|
delete rawDataContract.$id;
|
|
231
211
|
|
|
232
212
|
const result = await validateDataContract(rawDataContract);
|
|
233
213
|
|
|
234
|
-
expectJsonSchemaError(result);
|
|
214
|
+
await expectJsonSchemaError(result);
|
|
235
215
|
|
|
236
216
|
const [error] = result.getErrors();
|
|
237
217
|
|
|
@@ -241,26 +221,26 @@ describe('validateDataContractFactory', function main() {
|
|
|
241
221
|
});
|
|
242
222
|
|
|
243
223
|
it('should be a byte array', async () => {
|
|
224
|
+
const rawDataContract = dataContract.toObject();
|
|
244
225
|
rawDataContract.$id = new Array(32).fill('string');
|
|
245
226
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
227
|
+
// We decided to keep protocol error because of failed parse rather than doing hacks
|
|
228
|
+
// too keep it until validator will refuse it
|
|
229
|
+
try {
|
|
230
|
+
await validateDataContract(rawDataContract);
|
|
231
|
+
expect.fail('Should throw an error');
|
|
232
|
+
} catch (e) {
|
|
233
|
+
expect(e).to.have.string('invalid type: string');
|
|
234
|
+
}
|
|
256
235
|
});
|
|
257
236
|
|
|
258
237
|
it('should be no less than 32 bytes', async () => {
|
|
238
|
+
const rawDataContract = dataContract.toObject();
|
|
259
239
|
rawDataContract.$id = Buffer.alloc(31);
|
|
260
240
|
|
|
261
241
|
const result = await validateDataContract(rawDataContract);
|
|
262
242
|
|
|
263
|
-
expectJsonSchemaError(result);
|
|
243
|
+
await expectJsonSchemaError(result);
|
|
264
244
|
|
|
265
245
|
const [error] = result.getErrors();
|
|
266
246
|
|
|
@@ -269,11 +249,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
269
249
|
});
|
|
270
250
|
|
|
271
251
|
it('should be no longer than 32 bytes', async () => {
|
|
252
|
+
const rawDataContract = dataContract.toObject();
|
|
272
253
|
rawDataContract.$id = Buffer.alloc(33);
|
|
273
254
|
|
|
274
255
|
const result = await validateDataContract(rawDataContract);
|
|
275
256
|
|
|
276
|
-
expectJsonSchemaError(result);
|
|
257
|
+
await expectJsonSchemaError(result);
|
|
277
258
|
|
|
278
259
|
const [error] = result.getErrors();
|
|
279
260
|
|
|
@@ -284,6 +265,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
284
265
|
|
|
285
266
|
describe('$defs', () => {
|
|
286
267
|
it('may not be present', async () => {
|
|
268
|
+
const rawDataContract = dataContract.toObject();
|
|
287
269
|
delete rawDataContract.$defs;
|
|
288
270
|
delete rawDataContract.documents.prettyDocument;
|
|
289
271
|
|
|
@@ -294,11 +276,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
294
276
|
});
|
|
295
277
|
|
|
296
278
|
it('should be an object', async () => {
|
|
279
|
+
const rawDataContract = dataContract.toObject();
|
|
297
280
|
rawDataContract.$defs = 1;
|
|
298
281
|
|
|
299
282
|
const result = await validateDataContract(rawDataContract);
|
|
300
283
|
|
|
301
|
-
expectJsonSchemaError(result);
|
|
284
|
+
await expectJsonSchemaError(result);
|
|
302
285
|
|
|
303
286
|
const [error] = result.getErrors();
|
|
304
287
|
|
|
@@ -307,11 +290,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
307
290
|
});
|
|
308
291
|
|
|
309
292
|
it('should not be empty', async () => {
|
|
293
|
+
const rawDataContract = dataContract.toObject();
|
|
310
294
|
rawDataContract.$defs = {};
|
|
311
295
|
|
|
312
296
|
const result = await validateDataContract(rawDataContract);
|
|
313
297
|
|
|
314
|
-
expectJsonSchemaError(result);
|
|
298
|
+
await expectJsonSchemaError(result);
|
|
315
299
|
|
|
316
300
|
const [error] = result.getErrors();
|
|
317
301
|
|
|
@@ -320,24 +304,39 @@ describe('validateDataContractFactory', function main() {
|
|
|
320
304
|
});
|
|
321
305
|
|
|
322
306
|
it('should have no non-alphanumeric properties', async () => {
|
|
307
|
+
const rawDataContract = dataContract.toObject();
|
|
323
308
|
rawDataContract.$defs = {
|
|
324
309
|
$subSchema: {},
|
|
325
310
|
};
|
|
326
311
|
|
|
327
312
|
const result = await validateDataContract(rawDataContract);
|
|
328
313
|
|
|
329
|
-
expectJsonSchemaError(result
|
|
330
|
-
|
|
331
|
-
const [patternError, propertyNamesError] = result.getErrors();
|
|
314
|
+
await expectJsonSchemaError(result);
|
|
332
315
|
|
|
333
|
-
|
|
334
|
-
expect(patternError.getKeyword()).to.equal('pattern');
|
|
316
|
+
const [propertyNamesError] = result.getErrors();
|
|
335
317
|
|
|
336
318
|
expect(propertyNamesError.getInstancePath()).to.equal('/$defs');
|
|
337
319
|
expect(propertyNamesError.getKeyword()).to.equal('propertyNames');
|
|
338
320
|
});
|
|
339
321
|
|
|
322
|
+
it('should have valid properties\' values', async () => {
|
|
323
|
+
const rawDataContract = dataContract.toObject();
|
|
324
|
+
rawDataContract.$defs = {
|
|
325
|
+
yeet: '3a1u9a',
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const result = await validateDataContract(rawDataContract);
|
|
329
|
+
|
|
330
|
+
await expectJsonSchemaError(result, 2);
|
|
331
|
+
|
|
332
|
+
const [valueTypeError] = result.getErrors();
|
|
333
|
+
|
|
334
|
+
expect(valueTypeError.getInstancePath()).to.equal('/$defs/yeet');
|
|
335
|
+
expect(valueTypeError.getKeyword()).to.equal('type');
|
|
336
|
+
});
|
|
337
|
+
|
|
340
338
|
it('should have no more than 100 properties', async () => {
|
|
339
|
+
const rawDataContract = dataContract.toObject();
|
|
341
340
|
rawDataContract.$defs = {};
|
|
342
341
|
|
|
343
342
|
Array(101).fill({ type: 'string' }).forEach((item, i) => {
|
|
@@ -346,7 +345,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
346
345
|
|
|
347
346
|
const result = await validateDataContract(rawDataContract);
|
|
348
347
|
|
|
349
|
-
expectJsonSchemaError(result);
|
|
348
|
+
await expectJsonSchemaError(result);
|
|
350
349
|
|
|
351
350
|
const [error] = result.getErrors();
|
|
352
351
|
|
|
@@ -361,20 +360,20 @@ describe('validateDataContractFactory', function main() {
|
|
|
361
360
|
|
|
362
361
|
await Promise.all(
|
|
363
362
|
validNames.map(async (name) => {
|
|
364
|
-
const
|
|
363
|
+
const rawDataContract = dataContract.toObject();
|
|
365
364
|
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
rawDataContract.$defs = {};
|
|
366
|
+
rawDataContract.$defs[name] = {
|
|
368
367
|
type: 'string',
|
|
369
368
|
};
|
|
370
369
|
|
|
371
|
-
|
|
370
|
+
rawDataContract.$defs[name] = {
|
|
372
371
|
type: 'string',
|
|
373
372
|
};
|
|
374
373
|
|
|
375
|
-
const result = await validateDataContract(
|
|
374
|
+
const result = await validateDataContract(rawDataContract);
|
|
376
375
|
|
|
377
|
-
expectJsonSchemaError(result, 0);
|
|
376
|
+
await expectJsonSchemaError(result, 0);
|
|
378
377
|
}),
|
|
379
378
|
);
|
|
380
379
|
});
|
|
@@ -384,21 +383,21 @@ describe('validateDataContractFactory', function main() {
|
|
|
384
383
|
|
|
385
384
|
await Promise.all(
|
|
386
385
|
invalidNames.map(async (name) => {
|
|
387
|
-
const
|
|
386
|
+
const rawDataContract = dataContract.toObject();
|
|
388
387
|
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
rawDataContract.$defs = {};
|
|
389
|
+
rawDataContract.$defs[name] = {
|
|
391
390
|
type: 'string',
|
|
392
391
|
};
|
|
393
392
|
|
|
394
|
-
const result = await validateDataContract(
|
|
393
|
+
const result = await validateDataContract(rawDataContract);
|
|
395
394
|
|
|
396
|
-
expectJsonSchemaError(result
|
|
395
|
+
await expectJsonSchemaError(result);
|
|
397
396
|
|
|
398
397
|
const [error] = result.getErrors();
|
|
399
398
|
|
|
400
399
|
expect(error.getInstancePath()).to.equal('/$defs');
|
|
401
|
-
expect(error.getKeyword()).to.equal('
|
|
400
|
+
expect(error.getKeyword()).to.equal('propertyNames');
|
|
402
401
|
}),
|
|
403
402
|
);
|
|
404
403
|
});
|
|
@@ -406,11 +405,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
406
405
|
|
|
407
406
|
describe('documents', () => {
|
|
408
407
|
it('should be present', async () => {
|
|
408
|
+
const rawDataContract = dataContract.toObject();
|
|
409
409
|
delete rawDataContract.documents;
|
|
410
410
|
|
|
411
411
|
const result = await validateDataContract(rawDataContract);
|
|
412
412
|
|
|
413
|
-
expectJsonSchemaError(result);
|
|
413
|
+
await expectJsonSchemaError(result);
|
|
414
414
|
|
|
415
415
|
const [error] = result.getErrors();
|
|
416
416
|
|
|
@@ -420,11 +420,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
420
420
|
});
|
|
421
421
|
|
|
422
422
|
it('should be an object', async () => {
|
|
423
|
+
const rawDataContract = dataContract.toObject();
|
|
423
424
|
rawDataContract.documents = 1;
|
|
424
425
|
|
|
425
426
|
const result = await validateDataContract(rawDataContract);
|
|
426
427
|
|
|
427
|
-
expectJsonSchemaError(result);
|
|
428
|
+
await expectJsonSchemaError(result);
|
|
428
429
|
|
|
429
430
|
const [error] = result.getErrors();
|
|
430
431
|
|
|
@@ -433,11 +434,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
433
434
|
});
|
|
434
435
|
|
|
435
436
|
it('should not be empty', async () => {
|
|
437
|
+
const rawDataContract = dataContract.toObject();
|
|
436
438
|
rawDataContract.documents = {};
|
|
437
439
|
|
|
438
440
|
const result = await validateDataContract(rawDataContract);
|
|
439
441
|
|
|
440
|
-
expectJsonSchemaError(result);
|
|
442
|
+
await expectJsonSchemaError(result);
|
|
441
443
|
|
|
442
444
|
const [error] = result.getErrors();
|
|
443
445
|
|
|
@@ -446,6 +448,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
446
448
|
});
|
|
447
449
|
|
|
448
450
|
it('should have valid property names (document types)', async () => {
|
|
451
|
+
const rawDataContract = dataContract.toObject();
|
|
449
452
|
const validNames = ['validName', 'valid_name', 'valid-name', 'abc', 'a123123bc', 'ab123c', 'ValidName', 'validName',
|
|
450
453
|
'abcdefghigklmnopqrstuvwxyz01234567890abcdefghigklmnopqrstuvwxyz', 'abc_gbf_gdb', 'abc-gbf-gdb'];
|
|
451
454
|
|
|
@@ -457,12 +460,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
457
460
|
|
|
458
461
|
const result = await validateDataContract(clonedDataContract);
|
|
459
462
|
|
|
460
|
-
expectJsonSchemaError(result, 0);
|
|
463
|
+
await expectJsonSchemaError(result, 0);
|
|
461
464
|
}),
|
|
462
465
|
);
|
|
463
466
|
});
|
|
464
467
|
|
|
465
468
|
it('should return an invalid result if a property (document type) has invalid format', async () => {
|
|
469
|
+
const rawDataContract = dataContract.toObject();
|
|
466
470
|
const invalidNames = ['*(*&^', '$test', '.', '.a'];
|
|
467
471
|
|
|
468
472
|
await Promise.all(
|
|
@@ -473,17 +477,18 @@ describe('validateDataContractFactory', function main() {
|
|
|
473
477
|
|
|
474
478
|
const result = await validateDataContract(clonedDataContract);
|
|
475
479
|
|
|
476
|
-
expectJsonSchemaError(result
|
|
480
|
+
await expectJsonSchemaError(result);
|
|
477
481
|
|
|
478
482
|
const [error] = result.getErrors();
|
|
479
483
|
|
|
480
484
|
expect(error.getInstancePath()).to.equal('/documents');
|
|
481
|
-
expect(error.getKeyword()).to.equal('
|
|
485
|
+
expect(error.getKeyword()).to.equal('propertyNames');
|
|
482
486
|
}),
|
|
483
487
|
);
|
|
484
488
|
});
|
|
485
489
|
|
|
486
490
|
it('should have no more than 100 properties', async () => {
|
|
491
|
+
const rawDataContract = dataContract.toObject();
|
|
487
492
|
const niceDocumentDefinition = rawDataContract.documents.niceDocument;
|
|
488
493
|
|
|
489
494
|
rawDataContract.documents = {};
|
|
@@ -494,7 +499,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
494
499
|
|
|
495
500
|
const result = await validateDataContract(rawDataContract);
|
|
496
501
|
|
|
497
|
-
expectJsonSchemaError(result);
|
|
502
|
+
await expectJsonSchemaError(result);
|
|
498
503
|
|
|
499
504
|
const [error] = result.getErrors();
|
|
500
505
|
|
|
@@ -504,46 +509,50 @@ describe('validateDataContractFactory', function main() {
|
|
|
504
509
|
|
|
505
510
|
describe('Document schema', () => {
|
|
506
511
|
it('should not be empty', async () => {
|
|
512
|
+
const rawDataContract = dataContract.toObject();
|
|
507
513
|
rawDataContract.documents.niceDocument.properties = {};
|
|
508
514
|
|
|
509
515
|
const result = await validateDataContract(rawDataContract);
|
|
510
516
|
|
|
511
|
-
expectJsonSchemaError(result, 2);
|
|
517
|
+
await expectJsonSchemaError(result, 2);
|
|
512
518
|
|
|
513
519
|
const [error] = result.getErrors();
|
|
514
520
|
|
|
515
|
-
expect(error.
|
|
521
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/properties');
|
|
516
522
|
expect(error.getKeyword()).to.equal('minProperties');
|
|
517
523
|
});
|
|
518
524
|
|
|
519
525
|
it('should have type "object"', async () => {
|
|
526
|
+
const rawDataContract = dataContract.toObject();
|
|
520
527
|
rawDataContract.documents.niceDocument.type = 'string';
|
|
521
528
|
|
|
522
529
|
const result = await validateDataContract(rawDataContract);
|
|
523
530
|
|
|
524
|
-
expectJsonSchemaError(result);
|
|
531
|
+
await expectJsonSchemaError(result);
|
|
525
532
|
|
|
526
533
|
const [error] = result.getErrors();
|
|
527
534
|
|
|
528
|
-
expect(error.
|
|
535
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/type');
|
|
529
536
|
expect(error.getKeyword()).to.equal('const');
|
|
530
537
|
});
|
|
531
538
|
|
|
532
539
|
it('should have "properties"', async () => {
|
|
540
|
+
const rawDataContract = dataContract.toObject();
|
|
533
541
|
delete rawDataContract.documents.niceDocument.properties;
|
|
534
542
|
|
|
535
543
|
const result = await validateDataContract(rawDataContract);
|
|
536
544
|
|
|
537
|
-
expectJsonSchemaError(result);
|
|
545
|
+
await expectJsonSchemaError(result);
|
|
538
546
|
|
|
539
547
|
const [error] = result.getErrors();
|
|
540
548
|
|
|
541
|
-
expect(error.
|
|
549
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument');
|
|
542
550
|
expect(error.getKeyword()).to.equal('required');
|
|
543
551
|
expect(error.getParams().missingProperty).to.equal('properties');
|
|
544
552
|
});
|
|
545
553
|
|
|
546
554
|
it('should have nested "properties"', async () => {
|
|
555
|
+
const rawDataContract = dataContract.toObject();
|
|
547
556
|
rawDataContract.documents.niceDocument.properties.object = {
|
|
548
557
|
type: 'array',
|
|
549
558
|
prefixItems: [
|
|
@@ -562,16 +571,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
562
571
|
|
|
563
572
|
const result = await validateDataContract(rawDataContract);
|
|
564
573
|
|
|
565
|
-
expectJsonSchemaError(result,
|
|
574
|
+
await expectJsonSchemaError(result, 8);
|
|
566
575
|
|
|
567
576
|
const [error] = result.getErrors();
|
|
568
577
|
|
|
569
|
-
expect(error.
|
|
578
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/properties/object/prefixItems/0/properties/something');
|
|
570
579
|
expect(error.getKeyword()).to.equal('required');
|
|
571
580
|
expect(error.getParams().missingProperty).to.equal('properties');
|
|
572
581
|
});
|
|
573
582
|
|
|
574
583
|
it('should have valid property names', async () => {
|
|
584
|
+
const rawDataContract = dataContract.toObject();
|
|
575
585
|
const validNames = ['validName', 'valid_name', 'valid-name', 'abc', 'a123bc', 'abc123', 'ValidName', 'validName',
|
|
576
586
|
'abcdefghigklmnopqrstuvwxyz01234567890abcdefghigklmnopqrstuvwxyz', 'abc_gbf_gdb', 'abc-gbf-gdb'];
|
|
577
587
|
|
|
@@ -585,12 +595,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
585
595
|
|
|
586
596
|
const result = await validateDataContract(clonedDataContract);
|
|
587
597
|
|
|
588
|
-
expectJsonSchemaError(result, 0);
|
|
598
|
+
await expectJsonSchemaError(result, 0);
|
|
589
599
|
}),
|
|
590
600
|
);
|
|
591
601
|
});
|
|
592
602
|
|
|
593
603
|
it('should have valid nested property names', async () => {
|
|
604
|
+
const rawDataContract = dataContract.toObject();
|
|
594
605
|
const validNames = ['validName', 'valid_name', 'valid-name', 'abc', 'a123bc', 'abc123', 'ValidName', 'validName',
|
|
595
606
|
'abcdefghigklmnopqrstuvwxyz01234567890abcdefghigklmnopqrstuvwxyz', 'abc_gbf_gdb', 'abc-gbf-gdb'];
|
|
596
607
|
|
|
@@ -610,12 +621,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
610
621
|
|
|
611
622
|
const result = await validateDataContract(clonedDataContract);
|
|
612
623
|
|
|
613
|
-
expectJsonSchemaError(result, 0);
|
|
624
|
+
await expectJsonSchemaError(result, 0);
|
|
614
625
|
}),
|
|
615
626
|
);
|
|
616
627
|
});
|
|
617
628
|
|
|
618
629
|
it('should return an invalid result if a property has invalid format', async () => {
|
|
630
|
+
const rawDataContract = dataContract.toObject();
|
|
619
631
|
const invalidNames = ['*(*&^', '$test', '.', '.a'];
|
|
620
632
|
|
|
621
633
|
await Promise.all(
|
|
@@ -626,19 +638,18 @@ describe('validateDataContractFactory', function main() {
|
|
|
626
638
|
|
|
627
639
|
const result = await validateDataContract(clonedDataContract);
|
|
628
640
|
|
|
629
|
-
expectJsonSchemaError(result,
|
|
641
|
+
await expectJsonSchemaError(result, 2);
|
|
630
642
|
|
|
631
|
-
const
|
|
643
|
+
const [error] = result.getErrors();
|
|
632
644
|
|
|
633
|
-
expect(
|
|
634
|
-
expect(
|
|
635
|
-
expect(errors[1].instancePath).to.equal('/documents/niceDocument/properties');
|
|
636
|
-
expect(errors[1].keyword).to.equal('propertyNames');
|
|
645
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/properties');
|
|
646
|
+
expect(error.getKeyword()).to.equal('propertyNames');
|
|
637
647
|
}),
|
|
638
648
|
);
|
|
639
649
|
});
|
|
640
650
|
|
|
641
651
|
it('should return an invalid result if a nested property has invalid format', async () => {
|
|
652
|
+
const rawDataContract = dataContract.toObject();
|
|
642
653
|
const invalidNames = ['*(*&^', '$test', '.', '.a'];
|
|
643
654
|
|
|
644
655
|
rawDataContract.documents.niceDocument.properties.something = {
|
|
@@ -654,50 +665,49 @@ describe('validateDataContractFactory', function main() {
|
|
|
654
665
|
|
|
655
666
|
const result = await validateDataContract(clonedDataContract);
|
|
656
667
|
|
|
657
|
-
expectJsonSchemaError(result, 4);
|
|
668
|
+
await expectJsonSchemaError(result, 4);
|
|
658
669
|
|
|
659
|
-
const errors = result.getErrors();
|
|
670
|
+
const [errors] = result.getErrors();
|
|
660
671
|
|
|
661
|
-
expect(errors
|
|
662
|
-
'/documents/niceDocument/properties/something/properties',
|
|
663
|
-
);
|
|
664
|
-
expect(errors[0].keyword).to.equal('pattern');
|
|
665
|
-
expect(errors[1].instancePath).to.equal(
|
|
672
|
+
expect(errors.getInstancePath()).to.equal(
|
|
666
673
|
'/documents/niceDocument/properties/something/properties',
|
|
667
674
|
);
|
|
668
|
-
expect(errors
|
|
675
|
+
expect(errors.getKeyword()).to.equal('propertyNames');
|
|
669
676
|
}),
|
|
670
677
|
);
|
|
671
678
|
});
|
|
672
679
|
|
|
673
680
|
it('should have "additionalProperties" defined', async () => {
|
|
681
|
+
const rawDataContract = dataContract.toObject();
|
|
674
682
|
delete rawDataContract.documents.niceDocument.additionalProperties;
|
|
675
683
|
|
|
676
684
|
const result = await validateDataContract(rawDataContract);
|
|
677
685
|
|
|
678
|
-
expectJsonSchemaError(result);
|
|
686
|
+
await expectJsonSchemaError(result);
|
|
679
687
|
|
|
680
688
|
const [error] = result.getErrors();
|
|
681
689
|
|
|
682
|
-
expect(error.
|
|
690
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument');
|
|
683
691
|
expect(error.getKeyword()).to.equal('required');
|
|
684
692
|
expect(error.getParams().missingProperty).to.equal('additionalProperties');
|
|
685
693
|
});
|
|
686
694
|
|
|
687
695
|
it('should have "additionalProperties" defined to false', async () => {
|
|
696
|
+
const rawDataContract = dataContract.toObject();
|
|
688
697
|
rawDataContract.documents.niceDocument.additionalProperties = true;
|
|
689
698
|
|
|
690
699
|
const result = await validateDataContract(rawDataContract);
|
|
691
700
|
|
|
692
|
-
expectJsonSchemaError(result);
|
|
701
|
+
await expectJsonSchemaError(result, 2);
|
|
693
702
|
|
|
694
703
|
const [error] = result.getErrors();
|
|
695
704
|
|
|
696
|
-
expect(error.
|
|
705
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/additionalProperties');
|
|
697
706
|
expect(error.getKeyword()).to.equal('const');
|
|
698
707
|
});
|
|
699
708
|
|
|
700
709
|
it('should have nested "additionalProperties" defined', async () => {
|
|
710
|
+
const rawDataContract = dataContract.toObject();
|
|
701
711
|
rawDataContract.documents.niceDocument.properties.object = {
|
|
702
712
|
type: 'array',
|
|
703
713
|
prefixItems: [
|
|
@@ -715,30 +725,32 @@ describe('validateDataContractFactory', function main() {
|
|
|
715
725
|
|
|
716
726
|
const result = await validateDataContract(rawDataContract);
|
|
717
727
|
|
|
718
|
-
expectJsonSchemaError(result, 2);
|
|
728
|
+
await expectJsonSchemaError(result, 2);
|
|
719
729
|
|
|
720
730
|
const [error] = result.getErrors();
|
|
721
731
|
|
|
722
|
-
expect(error.
|
|
732
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/properties/object/prefixItems/0');
|
|
723
733
|
expect(error.getKeyword()).to.equal('required');
|
|
724
734
|
expect(error.getParams().missingProperty).to.equal('additionalProperties');
|
|
725
735
|
});
|
|
726
736
|
|
|
727
737
|
it('should return invalid result if there are additional properties', async () => {
|
|
728
|
-
rawDataContract
|
|
738
|
+
const rawDataContract = dataContract.toObject();
|
|
739
|
+
rawDataContract.additionalProperty = {};
|
|
729
740
|
|
|
730
741
|
const result = await validateDataContract(rawDataContract);
|
|
731
742
|
|
|
732
|
-
expectJsonSchemaError(result);
|
|
743
|
+
await expectJsonSchemaError(result);
|
|
733
744
|
|
|
734
745
|
const [error] = result.getErrors();
|
|
735
746
|
|
|
736
|
-
expect(error.
|
|
747
|
+
expect(error.getInstancePath()).to.equal('');
|
|
737
748
|
expect(error.getKeyword()).to.equal('additionalProperties');
|
|
738
749
|
});
|
|
739
750
|
|
|
740
751
|
it('should have no more than 100 properties', async () => {
|
|
741
|
-
const
|
|
752
|
+
const rawDataContract = dataContract.toObject();
|
|
753
|
+
const propertyDefinition = {};
|
|
742
754
|
|
|
743
755
|
rawDataContract.documents.niceDocument.properties = {};
|
|
744
756
|
|
|
@@ -748,15 +760,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
748
760
|
|
|
749
761
|
const result = await validateDataContract(rawDataContract);
|
|
750
762
|
|
|
751
|
-
expectJsonSchemaError(result,
|
|
763
|
+
await expectJsonSchemaError(result, 406);
|
|
752
764
|
|
|
753
|
-
const
|
|
765
|
+
const errors = result.getErrors();
|
|
754
766
|
|
|
755
|
-
expect(
|
|
756
|
-
expect(
|
|
767
|
+
expect(errors[405].getInstancePath()).to.equal('/documents/niceDocument/properties');
|
|
768
|
+
expect(errors[405].getKeyword()).to.equal('maxProperties');
|
|
757
769
|
});
|
|
758
770
|
|
|
759
771
|
it('should have defined items for arrays', async () => {
|
|
772
|
+
const rawDataContract = dataContract.toObject();
|
|
760
773
|
rawDataContract.documents.new = {
|
|
761
774
|
properties: {
|
|
762
775
|
something: {
|
|
@@ -768,16 +781,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
768
781
|
|
|
769
782
|
const result = await validateDataContract(rawDataContract);
|
|
770
783
|
|
|
771
|
-
expectJsonSchemaError(result, 2);
|
|
784
|
+
await expectJsonSchemaError(result, 2);
|
|
772
785
|
|
|
773
786
|
const [error] = result.getErrors();
|
|
774
787
|
|
|
775
|
-
expect(error.
|
|
788
|
+
expect(error.getInstancePath()).to.equal('/documents/new/properties/something');
|
|
776
789
|
expect(error.getKeyword()).to.equal('required');
|
|
777
790
|
expect(error.getParams().missingProperty).to.equal('items');
|
|
778
791
|
});
|
|
779
792
|
|
|
780
793
|
it('should have sub schema in items for arrays', async () => {
|
|
794
|
+
const rawDataContract = dataContract.toObject();
|
|
781
795
|
rawDataContract.documents.new = {
|
|
782
796
|
properties: {
|
|
783
797
|
something: {
|
|
@@ -797,16 +811,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
797
811
|
|
|
798
812
|
const result = await validateDataContract(rawDataContract);
|
|
799
813
|
|
|
800
|
-
expectJsonSchemaError(result,
|
|
814
|
+
await expectJsonSchemaError(result, 2);
|
|
801
815
|
|
|
802
816
|
const [error] = result.getErrors();
|
|
803
817
|
|
|
804
|
-
expect(error.
|
|
818
|
+
expect(error.getInstancePath()).to.equal('/documents/new/properties/something/items');
|
|
805
819
|
expect(error.getKeyword()).to.equal('type');
|
|
806
820
|
expect(error.getParams().type).to.equal('object');
|
|
807
821
|
});
|
|
808
822
|
|
|
809
823
|
it('should have items if prefixItems is used for arrays', async () => {
|
|
824
|
+
const rawDataContract = dataContract.toObject();
|
|
810
825
|
rawDataContract.documents.new = {
|
|
811
826
|
type: 'object',
|
|
812
827
|
properties: {
|
|
@@ -828,16 +843,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
828
843
|
|
|
829
844
|
const result = await validateDataContract(rawDataContract);
|
|
830
845
|
|
|
831
|
-
expectJsonSchemaError(result,
|
|
846
|
+
await expectJsonSchemaError(result, 4);
|
|
832
847
|
|
|
833
848
|
const [error] = result.getErrors();
|
|
834
849
|
|
|
835
|
-
expect(error.
|
|
850
|
+
expect(error.getInstancePath()).to.equal('/documents/new/properties/something');
|
|
836
851
|
expect(error.getKeyword()).to.equal('required');
|
|
837
852
|
expect(error.getParams().missingProperty).to.equal('items');
|
|
838
853
|
});
|
|
839
854
|
|
|
840
855
|
it('should not have items disabled if prefixItems is used for arrays', async () => {
|
|
856
|
+
const rawDataContract = dataContract.toObject();
|
|
841
857
|
rawDataContract.documents.new = {
|
|
842
858
|
properties: {
|
|
843
859
|
something: {
|
|
@@ -858,44 +874,47 @@ describe('validateDataContractFactory', function main() {
|
|
|
858
874
|
|
|
859
875
|
const result = await validateDataContract(rawDataContract);
|
|
860
876
|
|
|
861
|
-
expectJsonSchemaError(result, 2);
|
|
877
|
+
await expectJsonSchemaError(result, 2);
|
|
862
878
|
|
|
863
879
|
const [error] = result.getErrors();
|
|
864
880
|
|
|
865
|
-
expect(error.
|
|
881
|
+
expect(error.getInstancePath()).to.equal('/documents/new/properties/something/items');
|
|
866
882
|
expect(error.getKeyword()).to.equal('const');
|
|
867
883
|
expect(error.getParams().allowedValue).to.equal(false);
|
|
868
884
|
});
|
|
869
885
|
|
|
870
886
|
it('should return invalid result if "default" keyword is used', async () => {
|
|
887
|
+
const rawDataContract = dataContract.toObject();
|
|
871
888
|
rawDataContract.documents.indexedDocument.properties.firstName.default = '1';
|
|
872
889
|
|
|
873
890
|
const result = await validateDataContract(rawDataContract);
|
|
874
891
|
|
|
875
|
-
expectJsonSchemaError(result, 2);
|
|
892
|
+
await expectJsonSchemaError(result, 2);
|
|
876
893
|
|
|
877
894
|
const [error] = result.getErrors();
|
|
878
895
|
|
|
879
|
-
expect(error.
|
|
880
|
-
expect(error.getKeyword()).to.equal('
|
|
896
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/firstName/default');
|
|
897
|
+
expect(error.getKeyword()).to.equal('falseSchema');
|
|
881
898
|
});
|
|
882
899
|
|
|
883
|
-
it
|
|
900
|
+
it('should return invalid result if remote `$ref` is used', async () => {
|
|
901
|
+
const rawDataContract = dataContract.toObject();
|
|
884
902
|
rawDataContract.documents.indexedDocument = {
|
|
885
903
|
$ref: 'http://remote.com/schema#',
|
|
886
904
|
};
|
|
887
905
|
|
|
888
906
|
const result = await validateDataContract(rawDataContract);
|
|
889
907
|
|
|
890
|
-
expectJsonSchemaError(result);
|
|
908
|
+
await expectJsonSchemaError(result);
|
|
891
909
|
|
|
892
910
|
const [error] = result.getErrors();
|
|
893
911
|
|
|
894
|
-
expect(error.
|
|
912
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/$ref');
|
|
895
913
|
expect(error.getKeyword()).to.equal('pattern');
|
|
896
914
|
});
|
|
897
915
|
|
|
898
916
|
it('should not have `propertyNames`', async () => {
|
|
917
|
+
const rawDataContract = dataContract.toObject();
|
|
899
918
|
rawDataContract.documents.indexedDocument = {
|
|
900
919
|
type: 'object',
|
|
901
920
|
properties: {
|
|
@@ -911,16 +930,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
911
930
|
|
|
912
931
|
const result = await validateDataContract(rawDataContract);
|
|
913
932
|
|
|
914
|
-
expectJsonSchemaError(result);
|
|
933
|
+
await expectJsonSchemaError(result);
|
|
915
934
|
|
|
916
935
|
const [error] = result.getErrors();
|
|
917
936
|
|
|
918
|
-
expect(error.
|
|
919
|
-
expect(error.getKeyword()).to.equal('
|
|
920
|
-
expect(error.getParams().unevaluatedProperty).to.equal('propertyNames');
|
|
937
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/propertyNames');
|
|
938
|
+
expect(error.getKeyword()).to.equal('falseSchema');
|
|
921
939
|
});
|
|
922
940
|
|
|
923
941
|
it('should have `maxItems` if `uniqueItems` is used', async () => {
|
|
942
|
+
const rawDataContract = dataContract.toObject();
|
|
924
943
|
rawDataContract.documents.indexedDocument = {
|
|
925
944
|
type: 'object',
|
|
926
945
|
properties: {
|
|
@@ -934,16 +953,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
934
953
|
|
|
935
954
|
const result = await validateDataContract(rawDataContract);
|
|
936
955
|
|
|
937
|
-
expectJsonSchemaError(result,
|
|
956
|
+
await expectJsonSchemaError(result, 4);
|
|
938
957
|
|
|
939
958
|
const [error] = result.getErrors();
|
|
940
959
|
|
|
941
|
-
expect(error.
|
|
960
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something');
|
|
942
961
|
expect(error.getKeyword()).to.equal('required');
|
|
943
|
-
expect(error.getParams().missingProperty).to.equal('
|
|
962
|
+
expect(error.getParams().missingProperty).to.equal('maxItems');
|
|
944
963
|
});
|
|
945
964
|
|
|
946
965
|
it('should have `maxItems` no bigger than 100000 if `uniqueItems` is used', async () => {
|
|
966
|
+
const rawDataContract = dataContract.toObject();
|
|
947
967
|
rawDataContract.documents.indexedDocument = {
|
|
948
968
|
type: 'object',
|
|
949
969
|
properties: {
|
|
@@ -967,15 +987,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
967
987
|
|
|
968
988
|
const result = await validateDataContract(rawDataContract);
|
|
969
989
|
|
|
970
|
-
expectJsonSchemaError(result, 2);
|
|
990
|
+
await expectJsonSchemaError(result, 2);
|
|
971
991
|
|
|
972
992
|
const [error] = result.getErrors();
|
|
973
993
|
|
|
974
|
-
expect(error.
|
|
994
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something/maxItems');
|
|
975
995
|
expect(error.getKeyword()).to.equal('maximum');
|
|
976
996
|
});
|
|
977
997
|
|
|
978
998
|
it('should return invalid result if document JSON Schema is not valid', async () => {
|
|
999
|
+
const rawDataContract = dataContract.toObject();
|
|
979
1000
|
rawDataContract.documents.indexedDocument = {
|
|
980
1001
|
type: 'object',
|
|
981
1002
|
properties: {
|
|
@@ -993,15 +1014,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
993
1014
|
expectValidationError(result, JsonSchemaCompilationError);
|
|
994
1015
|
|
|
995
1016
|
const [error] = result.getErrors();
|
|
996
|
-
|
|
997
|
-
expect(error.getCode()).to.equal(
|
|
998
|
-
|
|
999
|
-
expect(error.message).to.be.a('string').and.satisfy((msg) => (
|
|
1000
|
-
msg.startsWith('unknown format "lalala" ignored in schema')
|
|
1001
|
-
));
|
|
1017
|
+
// TODO: should be a JsonSchemaCompilationerror instead of JsonSchemaError
|
|
1018
|
+
expect(error.getCode()).to.equal(1005);
|
|
1019
|
+
expect(error.getKeyword()).to.equal('format');
|
|
1002
1020
|
});
|
|
1003
1021
|
|
|
1004
1022
|
it('should have `maxLength` if `pattern` is used', async () => {
|
|
1023
|
+
const rawDataContract = dataContract.toObject();
|
|
1005
1024
|
rawDataContract.documents.indexedDocument = {
|
|
1006
1025
|
type: 'object',
|
|
1007
1026
|
properties: {
|
|
@@ -1015,16 +1034,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
1015
1034
|
|
|
1016
1035
|
const result = await validateDataContract(rawDataContract);
|
|
1017
1036
|
|
|
1018
|
-
expectJsonSchemaError(result, 2);
|
|
1037
|
+
await expectJsonSchemaError(result, 2);
|
|
1019
1038
|
|
|
1020
1039
|
const [error] = result.getErrors();
|
|
1021
1040
|
|
|
1022
|
-
expect(error.
|
|
1041
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something');
|
|
1023
1042
|
expect(error.getKeyword()).to.equal('required');
|
|
1024
1043
|
expect(error.getParams().missingProperty).to.equal('maxLength');
|
|
1025
1044
|
});
|
|
1026
1045
|
|
|
1027
1046
|
it('should have `maxLength` no bigger than 50000 if `pattern` is used', async () => {
|
|
1047
|
+
const rawDataContract = dataContract.toObject();
|
|
1028
1048
|
rawDataContract.documents.indexedDocument = {
|
|
1029
1049
|
type: 'object',
|
|
1030
1050
|
properties: {
|
|
@@ -1039,15 +1059,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
1039
1059
|
|
|
1040
1060
|
const result = await validateDataContract(rawDataContract);
|
|
1041
1061
|
|
|
1042
|
-
expectJsonSchemaError(result, 2);
|
|
1062
|
+
await expectJsonSchemaError(result, 2);
|
|
1043
1063
|
|
|
1044
1064
|
const [error] = result.getErrors();
|
|
1045
1065
|
|
|
1046
|
-
expect(error.
|
|
1066
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something/maxLength');
|
|
1047
1067
|
expect(error.getKeyword()).to.equal('maximum');
|
|
1048
1068
|
});
|
|
1049
1069
|
|
|
1050
1070
|
it('should have `maxLength` if `format` is used', async () => {
|
|
1071
|
+
const rawDataContract = dataContract.toObject();
|
|
1051
1072
|
rawDataContract.documents.indexedDocument = {
|
|
1052
1073
|
type: 'object',
|
|
1053
1074
|
properties: {
|
|
@@ -1061,16 +1082,17 @@ describe('validateDataContractFactory', function main() {
|
|
|
1061
1082
|
|
|
1062
1083
|
const result = await validateDataContract(rawDataContract);
|
|
1063
1084
|
|
|
1064
|
-
expectJsonSchemaError(result, 2);
|
|
1085
|
+
await expectJsonSchemaError(result, 2);
|
|
1065
1086
|
|
|
1066
1087
|
const [error] = result.getErrors();
|
|
1067
1088
|
|
|
1068
|
-
expect(error.
|
|
1089
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something');
|
|
1069
1090
|
expect(error.getKeyword()).to.equal('required');
|
|
1070
1091
|
expect(error.getParams().missingProperty).to.equal('maxLength');
|
|
1071
1092
|
});
|
|
1072
1093
|
|
|
1073
1094
|
it('should have `maxLength` no bigger than 50000 if `format` is used', async () => {
|
|
1095
|
+
const rawDataContract = dataContract.toObject();
|
|
1074
1096
|
rawDataContract.documents.indexedDocument = {
|
|
1075
1097
|
type: 'object',
|
|
1076
1098
|
properties: {
|
|
@@ -1085,15 +1107,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
1085
1107
|
|
|
1086
1108
|
const result = await validateDataContract(rawDataContract);
|
|
1087
1109
|
|
|
1088
|
-
expectJsonSchemaError(result, 2);
|
|
1110
|
+
await expectJsonSchemaError(result, 2);
|
|
1089
1111
|
|
|
1090
1112
|
const [error] = result.getErrors();
|
|
1091
1113
|
|
|
1092
|
-
expect(error.
|
|
1114
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/properties/something/maxLength');
|
|
1093
1115
|
expect(error.getKeyword()).to.equal('maximum');
|
|
1094
1116
|
});
|
|
1095
1117
|
|
|
1096
1118
|
it('should not have incompatible patterns', async () => {
|
|
1119
|
+
const rawDataContract = dataContract.toObject();
|
|
1097
1120
|
rawDataContract.documents.indexedDocument = {
|
|
1098
1121
|
type: 'object',
|
|
1099
1122
|
properties: {
|
|
@@ -1115,52 +1138,55 @@ describe('validateDataContractFactory', function main() {
|
|
|
1115
1138
|
expect(error.getCode()).to.equal(1009);
|
|
1116
1139
|
expect(error.getPattern()).to.equal('^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$');
|
|
1117
1140
|
expect(error.getPath()).to.equal('/documents/indexedDocument/properties/something');
|
|
1118
|
-
expect(error.getPatternError()).to.be.instanceOf(Error);
|
|
1119
1141
|
});
|
|
1120
1142
|
|
|
1121
1143
|
describe('byteArray', () => {
|
|
1122
1144
|
it('should be a boolean', async () => {
|
|
1145
|
+
const rawDataContract = dataContract.toObject();
|
|
1123
1146
|
rawDataContract.documents.withByteArrays.properties.byteArrayField.byteArray = 1;
|
|
1124
1147
|
|
|
1125
1148
|
const result = await validateDataContract(rawDataContract);
|
|
1126
1149
|
|
|
1127
|
-
expectJsonSchemaError(result,
|
|
1150
|
+
await expectJsonSchemaError(result, 4);
|
|
1128
1151
|
|
|
1129
1152
|
const [error] = result.getErrors();
|
|
1130
1153
|
|
|
1131
|
-
expect(error.
|
|
1154
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/byteArrayField/byteArray');
|
|
1132
1155
|
expect(error.getKeyword()).to.equal('type');
|
|
1133
1156
|
expect(error.getParams().type).to.equal('boolean');
|
|
1134
1157
|
});
|
|
1135
1158
|
|
|
1136
1159
|
it('should equal to true', async () => {
|
|
1160
|
+
const rawDataContract = dataContract.toObject();
|
|
1137
1161
|
rawDataContract.documents.withByteArrays.properties.byteArrayField.byteArray = false;
|
|
1138
1162
|
|
|
1139
1163
|
const result = await validateDataContract(rawDataContract);
|
|
1140
1164
|
|
|
1141
|
-
expectJsonSchemaError(result, 2);
|
|
1165
|
+
await expectJsonSchemaError(result, 2);
|
|
1142
1166
|
|
|
1143
1167
|
const [error] = result.getErrors();
|
|
1144
1168
|
|
|
1145
|
-
expect(error.
|
|
1169
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/byteArrayField/byteArray');
|
|
1146
1170
|
expect(error.getKeyword()).to.equal('const');
|
|
1147
1171
|
expect(error.getParams().allowedValue).to.equal(true);
|
|
1148
1172
|
});
|
|
1149
1173
|
|
|
1150
1174
|
it('should be used with type `array`', async () => {
|
|
1175
|
+
const rawDataContract = dataContract.toObject();
|
|
1151
1176
|
rawDataContract.documents.withByteArrays.properties.byteArrayField.type = 'string';
|
|
1152
1177
|
|
|
1153
1178
|
const result = await validateDataContract(rawDataContract);
|
|
1154
1179
|
|
|
1155
|
-
expectJsonSchemaError(result, 2);
|
|
1180
|
+
await expectJsonSchemaError(result, 2);
|
|
1156
1181
|
|
|
1157
1182
|
const [error] = result.getErrors();
|
|
1158
1183
|
|
|
1159
|
-
expect(error.
|
|
1184
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/byteArrayField/type');
|
|
1160
1185
|
expect(error.getKeyword()).to.equal('const');
|
|
1161
1186
|
});
|
|
1162
1187
|
|
|
1163
1188
|
it('should not be used with `items`', async () => {
|
|
1189
|
+
const rawDataContract = dataContract.toObject();
|
|
1164
1190
|
rawDataContract.documents.withByteArrays.properties.byteArrayField.items = {
|
|
1165
1191
|
type: 'string',
|
|
1166
1192
|
};
|
|
@@ -1172,48 +1198,50 @@ describe('validateDataContractFactory', function main() {
|
|
|
1172
1198
|
const [error] = result.getErrors();
|
|
1173
1199
|
|
|
1174
1200
|
expect(error.getCode()).to.equal(1004);
|
|
1175
|
-
expect(error.message).to.equal("'byteArray' should not be used with 'items'");
|
|
1176
1201
|
});
|
|
1177
1202
|
});
|
|
1178
1203
|
|
|
1179
1204
|
describe('contentMediaType', () => {
|
|
1180
1205
|
describe('application/x.dash.dpp.identifier', () => {
|
|
1181
1206
|
it('should be used with byte array only', async () => {
|
|
1207
|
+
const rawDataContract = dataContract.toObject();
|
|
1182
1208
|
delete rawDataContract.documents.withByteArrays.properties.identifierField.byteArray;
|
|
1183
1209
|
|
|
1184
1210
|
const result = await validateDataContract(rawDataContract);
|
|
1185
1211
|
|
|
1186
|
-
expectJsonSchemaError(result,
|
|
1212
|
+
await expectJsonSchemaError(result, 4);
|
|
1187
1213
|
|
|
1188
1214
|
const [error] = result.getErrors();
|
|
1189
1215
|
|
|
1190
|
-
expect(error.
|
|
1216
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/identifierField');
|
|
1191
1217
|
expect(error.getKeyword()).to.equal('required');
|
|
1192
1218
|
});
|
|
1193
1219
|
|
|
1194
1220
|
it('should be used with byte array not shorter than 32 bytes', async () => {
|
|
1221
|
+
const rawDataContract = dataContract.toObject();
|
|
1195
1222
|
rawDataContract.documents.withByteArrays.properties.identifierField.minItems = 31;
|
|
1196
1223
|
|
|
1197
1224
|
const result = await validateDataContract(rawDataContract);
|
|
1198
1225
|
|
|
1199
|
-
expectJsonSchemaError(result, 2);
|
|
1226
|
+
await expectJsonSchemaError(result, 2);
|
|
1200
1227
|
|
|
1201
1228
|
const [error] = result.getErrors();
|
|
1202
1229
|
|
|
1203
|
-
expect(error.
|
|
1230
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/identifierField/minItems');
|
|
1204
1231
|
expect(error.getKeyword()).to.equal('const');
|
|
1205
1232
|
});
|
|
1206
1233
|
|
|
1207
1234
|
it('should be used with byte array not longer than 32 bytes', async () => {
|
|
1235
|
+
const rawDataContract = dataContract.toObject();
|
|
1208
1236
|
rawDataContract.documents.withByteArrays.properties.identifierField.maxItems = 31;
|
|
1209
1237
|
|
|
1210
1238
|
const result = await validateDataContract(rawDataContract);
|
|
1211
1239
|
|
|
1212
|
-
expectJsonSchemaError(result, 2);
|
|
1240
|
+
await expectJsonSchemaError(result, 2);
|
|
1213
1241
|
|
|
1214
1242
|
const [error] = result.getErrors();
|
|
1215
1243
|
|
|
1216
|
-
expect(error.
|
|
1244
|
+
expect(error.getInstancePath()).to.equal('/documents/withByteArrays/properties/identifierField/maxItems');
|
|
1217
1245
|
expect(error.getKeyword()).to.equal('const');
|
|
1218
1246
|
});
|
|
1219
1247
|
});
|
|
@@ -1223,32 +1251,35 @@ describe('validateDataContractFactory', function main() {
|
|
|
1223
1251
|
|
|
1224
1252
|
describe('indices', () => {
|
|
1225
1253
|
it('should be an array', async () => {
|
|
1254
|
+
const rawDataContract = dataContract.toObject();
|
|
1226
1255
|
rawDataContract.documents.indexedDocument.indices = 'definitely not an array';
|
|
1227
1256
|
|
|
1228
1257
|
const result = await validateDataContract(rawDataContract);
|
|
1229
1258
|
|
|
1230
|
-
expectJsonSchemaError(result);
|
|
1259
|
+
await expectJsonSchemaError(result);
|
|
1231
1260
|
|
|
1232
1261
|
const [error] = result.getErrors();
|
|
1233
1262
|
|
|
1234
|
-
expect(error.
|
|
1263
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/indices');
|
|
1235
1264
|
expect(error.getKeyword()).to.equal('type');
|
|
1236
1265
|
});
|
|
1237
1266
|
|
|
1238
1267
|
it('should have at least one item', async () => {
|
|
1268
|
+
const rawDataContract = dataContract.toObject();
|
|
1239
1269
|
rawDataContract.documents.indexedDocument.indices = [];
|
|
1240
1270
|
|
|
1241
1271
|
const result = await validateDataContract(rawDataContract);
|
|
1242
1272
|
|
|
1243
|
-
expectJsonSchemaError(result);
|
|
1273
|
+
await expectJsonSchemaError(result);
|
|
1244
1274
|
|
|
1245
1275
|
const [error] = result.getErrors();
|
|
1246
1276
|
|
|
1247
|
-
expect(error.
|
|
1277
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/indices');
|
|
1248
1278
|
expect(error.getKeyword()).to.equal('minItems');
|
|
1249
1279
|
});
|
|
1250
1280
|
|
|
1251
1281
|
it('should return invalid result if there are duplicated indices', async () => {
|
|
1282
|
+
const rawDataContract = dataContract.toObject();
|
|
1252
1283
|
const indexDefinition = {
|
|
1253
1284
|
...rawDataContract.documents.indexedDocument.indices[0],
|
|
1254
1285
|
name: 'otherIndexName',
|
|
@@ -1263,11 +1294,12 @@ describe('validateDataContractFactory', function main() {
|
|
|
1263
1294
|
const [error] = result.getErrors();
|
|
1264
1295
|
|
|
1265
1296
|
expect(error.getCode()).to.equal(1008);
|
|
1266
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1297
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1267
1298
|
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1268
1299
|
});
|
|
1269
1300
|
|
|
1270
1301
|
it('should return invalid result if there are duplicated index names', async () => {
|
|
1302
|
+
const rawDataContract = dataContract.toObject();
|
|
1271
1303
|
const indexDefinition = {
|
|
1272
1304
|
...rawDataContract.documents.indexedDocument.indices[0],
|
|
1273
1305
|
};
|
|
@@ -1287,66 +1319,71 @@ describe('validateDataContractFactory', function main() {
|
|
|
1287
1319
|
|
|
1288
1320
|
describe('index', () => {
|
|
1289
1321
|
it('should be an object', async () => {
|
|
1322
|
+
const rawDataContract = dataContract.toObject();
|
|
1290
1323
|
rawDataContract.documents.indexedDocument.indices = ['something else'];
|
|
1291
1324
|
|
|
1292
1325
|
const result = await validateDataContract(rawDataContract);
|
|
1293
1326
|
|
|
1294
|
-
expectJsonSchemaError(result);
|
|
1327
|
+
await expectJsonSchemaError(result);
|
|
1295
1328
|
|
|
1296
1329
|
const [error] = result.getErrors();
|
|
1297
1330
|
|
|
1298
|
-
expect(error.
|
|
1331
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/indices/0');
|
|
1299
1332
|
expect(error.getKeyword()).to.equal('type');
|
|
1300
1333
|
});
|
|
1301
1334
|
|
|
1302
1335
|
it('should have properties definition', async () => {
|
|
1336
|
+
const rawDataContract = dataContract.toObject();
|
|
1303
1337
|
rawDataContract.documents.indexedDocument.indices = [{}];
|
|
1304
1338
|
|
|
1305
1339
|
const result = await validateDataContract(rawDataContract);
|
|
1306
1340
|
|
|
1307
|
-
expectJsonSchemaError(result);
|
|
1341
|
+
await expectJsonSchemaError(result, 2);
|
|
1308
1342
|
|
|
1309
1343
|
const [error] = result.getErrors();
|
|
1310
1344
|
|
|
1311
|
-
expect(error.
|
|
1345
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/indices/0');
|
|
1312
1346
|
expect(error.getParams().missingProperty).to.equal('properties');
|
|
1313
1347
|
expect(error.getKeyword()).to.equal('required');
|
|
1314
1348
|
});
|
|
1315
1349
|
|
|
1316
1350
|
describe('properties definition', () => {
|
|
1317
1351
|
it('should be an array', async () => {
|
|
1352
|
+
const rawDataContract = dataContract.toObject();
|
|
1318
1353
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1319
1354
|
.properties = 'something else';
|
|
1320
1355
|
|
|
1321
1356
|
const result = await validateDataContract(rawDataContract);
|
|
1322
1357
|
|
|
1323
|
-
expectJsonSchemaError(result);
|
|
1358
|
+
await expectJsonSchemaError(result);
|
|
1324
1359
|
|
|
1325
1360
|
const [error] = result.getErrors();
|
|
1326
1361
|
|
|
1327
|
-
expect(error.
|
|
1362
|
+
expect(error.getInstancePath()).to.equal(
|
|
1328
1363
|
'/documents/indexedDocument/indices/0/properties',
|
|
1329
1364
|
);
|
|
1330
1365
|
expect(error.getKeyword()).to.equal('type');
|
|
1331
1366
|
});
|
|
1332
1367
|
|
|
1333
1368
|
it('should have at least one property defined', async () => {
|
|
1369
|
+
const rawDataContract = dataContract.toObject();
|
|
1334
1370
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1335
1371
|
.properties = [];
|
|
1336
1372
|
|
|
1337
1373
|
const result = await validateDataContract(rawDataContract);
|
|
1338
1374
|
|
|
1339
|
-
expectJsonSchemaError(result);
|
|
1375
|
+
await expectJsonSchemaError(result);
|
|
1340
1376
|
|
|
1341
1377
|
const [error] = result.getErrors();
|
|
1342
1378
|
|
|
1343
|
-
expect(error.
|
|
1379
|
+
expect(error.getInstancePath()).to.equal(
|
|
1344
1380
|
'/documents/indexedDocument/indices/0/properties',
|
|
1345
1381
|
);
|
|
1346
1382
|
expect(error.getKeyword()).to.equal('minItems');
|
|
1347
1383
|
});
|
|
1348
1384
|
|
|
1349
1385
|
it('should have no more than 10 property $defs', async () => {
|
|
1386
|
+
const rawDataContract = dataContract.toObject();
|
|
1350
1387
|
for (let i = 0; i < 10; i++) {
|
|
1351
1388
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1352
1389
|
.properties.push({ [`field${i}`]: 'asc' });
|
|
@@ -1354,11 +1391,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
1354
1391
|
|
|
1355
1392
|
const result = await validateDataContract(rawDataContract);
|
|
1356
1393
|
|
|
1357
|
-
expectJsonSchemaError(result);
|
|
1394
|
+
await expectJsonSchemaError(result);
|
|
1358
1395
|
|
|
1359
1396
|
const [error] = result.getErrors();
|
|
1360
1397
|
|
|
1361
|
-
expect(error.
|
|
1398
|
+
expect(error.getInstancePath()).to.equal(
|
|
1362
1399
|
'/documents/indexedDocument/indices/0/properties',
|
|
1363
1400
|
);
|
|
1364
1401
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
@@ -1366,38 +1403,41 @@ describe('validateDataContractFactory', function main() {
|
|
|
1366
1403
|
|
|
1367
1404
|
describe('property definition', () => {
|
|
1368
1405
|
it('should be an object', async () => {
|
|
1406
|
+
const rawDataContract = dataContract.toObject();
|
|
1369
1407
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1370
1408
|
.properties[0] = 'something else';
|
|
1371
1409
|
|
|
1372
1410
|
const result = await validateDataContract(rawDataContract);
|
|
1373
1411
|
|
|
1374
|
-
expectJsonSchemaError(result);
|
|
1412
|
+
await expectJsonSchemaError(result);
|
|
1375
1413
|
|
|
1376
1414
|
const [error] = result.getErrors();
|
|
1377
1415
|
|
|
1378
|
-
expect(error.
|
|
1416
|
+
expect(error.getInstancePath()).to.equal(
|
|
1379
1417
|
'/documents/indexedDocument/indices/0/properties/0',
|
|
1380
1418
|
);
|
|
1381
1419
|
expect(error.getKeyword()).to.equal('type');
|
|
1382
1420
|
});
|
|
1383
1421
|
|
|
1384
1422
|
it('should have at least one property', async () => {
|
|
1423
|
+
const rawDataContract = dataContract.toObject();
|
|
1385
1424
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1386
1425
|
.properties = [];
|
|
1387
1426
|
|
|
1388
1427
|
const result = await validateDataContract(rawDataContract);
|
|
1389
1428
|
|
|
1390
|
-
expectJsonSchemaError(result);
|
|
1429
|
+
await expectJsonSchemaError(result);
|
|
1391
1430
|
|
|
1392
1431
|
const [error] = result.getErrors();
|
|
1393
1432
|
|
|
1394
|
-
expect(error.
|
|
1433
|
+
expect(error.getInstancePath()).to.equal(
|
|
1395
1434
|
'/documents/indexedDocument/indices/0/properties',
|
|
1396
1435
|
);
|
|
1397
1436
|
expect(error.getKeyword()).to.equal('minItems');
|
|
1398
1437
|
});
|
|
1399
1438
|
|
|
1400
1439
|
it('should have no more than one property', async () => {
|
|
1440
|
+
const rawDataContract = dataContract.toObject();
|
|
1401
1441
|
const property = rawDataContract.documents.indexedDocument.indices[0]
|
|
1402
1442
|
.properties[0];
|
|
1403
1443
|
|
|
@@ -1405,27 +1445,28 @@ describe('validateDataContractFactory', function main() {
|
|
|
1405
1445
|
|
|
1406
1446
|
const result = await validateDataContract(rawDataContract);
|
|
1407
1447
|
|
|
1408
|
-
expectJsonSchemaError(result);
|
|
1448
|
+
await expectJsonSchemaError(result, 2);
|
|
1409
1449
|
|
|
1410
|
-
const
|
|
1450
|
+
const error = result.getErrors()[1];
|
|
1411
1451
|
|
|
1412
|
-
expect(error.
|
|
1452
|
+
expect(error.getInstancePath()).to.equal(
|
|
1413
1453
|
'/documents/indexedDocument/indices/0/properties/0',
|
|
1414
1454
|
);
|
|
1415
1455
|
expect(error.getKeyword()).to.equal('maxProperties');
|
|
1416
1456
|
});
|
|
1417
1457
|
|
|
1418
1458
|
it('should have property values only "asc" or "desc"', async () => {
|
|
1459
|
+
const rawDataContract = dataContract.toObject();
|
|
1419
1460
|
rawDataContract.documents.indexedDocument.indices[0]
|
|
1420
1461
|
.properties[0].$ownerId = 'wrong';
|
|
1421
1462
|
|
|
1422
1463
|
const result = await validateDataContract(rawDataContract);
|
|
1423
1464
|
|
|
1424
|
-
expectJsonSchemaError(result);
|
|
1465
|
+
await expectJsonSchemaError(result);
|
|
1425
1466
|
|
|
1426
1467
|
const [error] = result.getErrors();
|
|
1427
1468
|
|
|
1428
|
-
expect(error.
|
|
1469
|
+
expect(error.getInstancePath()).to.equal(
|
|
1429
1470
|
'/documents/indexedDocument/indices/0/properties/0/$ownerId',
|
|
1430
1471
|
);
|
|
1431
1472
|
expect(error.getKeyword()).to.equal('enum');
|
|
@@ -1435,6 +1476,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
1435
1476
|
|
|
1436
1477
|
describe('property names', () => {
|
|
1437
1478
|
it('should have valid property names (indices)', async () => {
|
|
1479
|
+
const rawDataContract = dataContract.toObject();
|
|
1438
1480
|
const validNames = ['validName', 'valid_name', 'valid-name', 'abc', 'a123123bc', 'ab123c', 'ValidName', 'validName',
|
|
1439
1481
|
'abcdefghigklmnopqrstuvwxyz01234567890abcdefghigklmnopqrstuvwxyz', 'abc_gbf_gdb', 'abc-gbf-gdb'];
|
|
1440
1482
|
|
|
@@ -1448,12 +1490,13 @@ describe('validateDataContractFactory', function main() {
|
|
|
1448
1490
|
|
|
1449
1491
|
const result = await validateDataContract(clonedDataContract);
|
|
1450
1492
|
|
|
1451
|
-
expectJsonSchemaError(result, 0);
|
|
1493
|
+
await expectJsonSchemaError(result, 0);
|
|
1452
1494
|
}),
|
|
1453
1495
|
);
|
|
1454
1496
|
});
|
|
1455
1497
|
|
|
1456
1498
|
it('should return an invalid result if a property (indices) has invalid format', async () => {
|
|
1499
|
+
const rawDataContract = dataContract.toObject();
|
|
1457
1500
|
const invalidNames = ['a.', '.a'];
|
|
1458
1501
|
|
|
1459
1502
|
rawDataContract.documents.indexedDocument = {
|
|
@@ -1495,19 +1538,21 @@ describe('validateDataContractFactory', function main() {
|
|
|
1495
1538
|
});
|
|
1496
1539
|
|
|
1497
1540
|
it('should have "unique" flag to be of a boolean type', async () => {
|
|
1541
|
+
const rawDataContract = dataContract.toObject();
|
|
1498
1542
|
rawDataContract.documents.indexedDocument.indices[0].unique = 12;
|
|
1499
1543
|
|
|
1500
1544
|
const result = await validateDataContract(rawDataContract);
|
|
1501
1545
|
|
|
1502
|
-
expectJsonSchemaError(result);
|
|
1546
|
+
await expectJsonSchemaError(result);
|
|
1503
1547
|
|
|
1504
1548
|
const [error] = result.getErrors();
|
|
1505
1549
|
|
|
1506
|
-
expect(error.
|
|
1550
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/indices/0/unique');
|
|
1507
1551
|
expect(error.getKeyword()).to.equal('type');
|
|
1508
1552
|
});
|
|
1509
1553
|
|
|
1510
1554
|
it('should have no more than 10 indices', async () => {
|
|
1555
|
+
const rawDataContract = dataContract.toObject();
|
|
1511
1556
|
for (let i = 0; i < 10; i++) {
|
|
1512
1557
|
const propertyName = `field${i}`;
|
|
1513
1558
|
|
|
@@ -1520,17 +1565,18 @@ describe('validateDataContractFactory', function main() {
|
|
|
1520
1565
|
|
|
1521
1566
|
const result = await validateDataContract(rawDataContract);
|
|
1522
1567
|
|
|
1523
|
-
expectJsonSchemaError(result);
|
|
1568
|
+
await expectJsonSchemaError(result, 11);
|
|
1524
1569
|
|
|
1525
|
-
const
|
|
1570
|
+
const error = result.getErrors()[10];
|
|
1526
1571
|
|
|
1527
|
-
expect(error.
|
|
1572
|
+
expect(error.getInstancePath()).to.equal(
|
|
1528
1573
|
'/documents/indexedDocument/indices',
|
|
1529
1574
|
);
|
|
1530
1575
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
1531
1576
|
});
|
|
1532
1577
|
|
|
1533
1578
|
it('should have no more than 3 unique indices', async () => {
|
|
1579
|
+
const rawDataContract = dataContract.toObject();
|
|
1534
1580
|
for (let i = 0; i < 4; i++) {
|
|
1535
1581
|
const propertyName = `field${i}`;
|
|
1536
1582
|
|
|
@@ -1557,6 +1603,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
1557
1603
|
});
|
|
1558
1604
|
|
|
1559
1605
|
it('should return invalid result if $id is specified as an indexed property', async () => {
|
|
1606
|
+
const rawDataContract = dataContract.toObject();
|
|
1560
1607
|
const indexDefinition = {
|
|
1561
1608
|
name: 'index_1',
|
|
1562
1609
|
properties: [
|
|
@@ -1578,10 +1625,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
1578
1625
|
expect(error.getCode()).to.equal(1015);
|
|
1579
1626
|
expect(error.getPropertyName()).to.equal('$id');
|
|
1580
1627
|
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1581
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1628
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1582
1629
|
});
|
|
1583
1630
|
|
|
1584
1631
|
it('should return invalid result if indices has undefined property', async () => {
|
|
1632
|
+
const rawDataContract = dataContract.toObject();
|
|
1585
1633
|
const indexDefinition = rawDataContract.documents.indexedDocument.indices[0];
|
|
1586
1634
|
|
|
1587
1635
|
indexDefinition.properties.push({
|
|
@@ -1597,10 +1645,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
1597
1645
|
expect(error.getCode()).to.equal(1016);
|
|
1598
1646
|
expect(error.getPropertyName()).to.equal('missingProperty');
|
|
1599
1647
|
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1600
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1648
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1601
1649
|
});
|
|
1602
1650
|
|
|
1603
1651
|
it('should return invalid result if index property is object', async () => {
|
|
1652
|
+
const rawDataContract = dataContract.toObject();
|
|
1604
1653
|
const indexedDocumentDefinition = rawDataContract.documents.indexedDocument;
|
|
1605
1654
|
|
|
1606
1655
|
indexedDocumentDefinition.properties.objectProperty = {
|
|
@@ -1631,10 +1680,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
1631
1680
|
expect(error.getPropertyName()).to.equal('objectProperty');
|
|
1632
1681
|
expect(error.getPropertyType()).to.equal('object');
|
|
1633
1682
|
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1634
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1683
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1635
1684
|
});
|
|
1636
1685
|
|
|
1637
1686
|
it('should return invalid result if index property is an array', async () => {
|
|
1687
|
+
const rawDataContract = dataContract.toObject();
|
|
1638
1688
|
rawDataContract.documents.indexedArray = {
|
|
1639
1689
|
type: 'object',
|
|
1640
1690
|
indices: [
|
|
@@ -1674,167 +1724,177 @@ describe('validateDataContractFactory', function main() {
|
|
|
1674
1724
|
expect(error.getPropertyName()).to.equal('mentions');
|
|
1675
1725
|
expect(error.getPropertyType()).to.equal('array');
|
|
1676
1726
|
expect(error.getDocumentType()).to.deep.equal('indexedArray');
|
|
1677
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1727
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1728
|
+
});
|
|
1729
|
+
|
|
1730
|
+
it('should return invalid result if index property is array of objects', async () => {
|
|
1731
|
+
const rawDataContract = dataContract.toObject();
|
|
1732
|
+
const indexedDocumentDefinition = rawDataContract.documents.indexedDocument;
|
|
1733
|
+
|
|
1734
|
+
indexedDocumentDefinition.properties.arrayProperty = {
|
|
1735
|
+
type: 'array',
|
|
1736
|
+
items: {
|
|
1737
|
+
type: 'object',
|
|
1738
|
+
properties: {
|
|
1739
|
+
something: {
|
|
1740
|
+
type: 'string',
|
|
1741
|
+
},
|
|
1742
|
+
},
|
|
1743
|
+
additionalProperties: false,
|
|
1744
|
+
},
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
indexedDocumentDefinition.required.push('arrayProperty');
|
|
1748
|
+
|
|
1749
|
+
const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1750
|
+
|
|
1751
|
+
indexDefinition.properties.push({
|
|
1752
|
+
arrayProperty: 'asc',
|
|
1753
|
+
});
|
|
1754
|
+
|
|
1755
|
+
const result = await validateDataContract(rawDataContract);
|
|
1756
|
+
|
|
1757
|
+
expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1758
|
+
|
|
1759
|
+
const [error] = result.getErrors();
|
|
1760
|
+
|
|
1761
|
+
expect(error.getCode()).to.equal(1013);
|
|
1762
|
+
expect(error.getPropertyName()).to.equal('arrayProperty');
|
|
1763
|
+
expect(error.getPropertyType()).to.equal('array');
|
|
1764
|
+
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1765
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1678
1766
|
});
|
|
1679
1767
|
|
|
1680
|
-
//
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
//
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
//
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
// type: 'array',
|
|
1808
|
-
// items: {
|
|
1809
|
-
// type: 'array',
|
|
1810
|
-
// items: {
|
|
1811
|
-
// type: 'string',
|
|
1812
|
-
// },
|
|
1813
|
-
// },
|
|
1814
|
-
// };
|
|
1815
|
-
//
|
|
1816
|
-
// indexedDocumentDefinition.required.push('arrayProperty');
|
|
1817
|
-
//
|
|
1818
|
-
// const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1819
|
-
//
|
|
1820
|
-
// indexDefinition.properties.push({
|
|
1821
|
-
// arrayProperty: 'asc',
|
|
1822
|
-
// });
|
|
1823
|
-
//
|
|
1824
|
-
// const result = await validateDataContract(rawDataContract);
|
|
1825
|
-
//
|
|
1826
|
-
// expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1827
|
-
//
|
|
1828
|
-
// const [error] = result.getErrors();
|
|
1829
|
-
//
|
|
1830
|
-
// expect(error.getCode()).to.equal(1013);
|
|
1831
|
-
// expect(error.getPropertyName()).to.equal('arrayProperty');
|
|
1832
|
-
// expect(error.getPropertyType()).to.equal('array');
|
|
1833
|
-
// expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1834
|
-
// expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1835
|
-
// });
|
|
1768
|
+
// TODO: support indexed arrays
|
|
1769
|
+
it.skip('should return invalid result if index property is an array of different types',
|
|
1770
|
+
async () => {
|
|
1771
|
+
const rawDataContract = dataContract.toObject();
|
|
1772
|
+
|
|
1773
|
+
const indexedDocumentDefinition = rawDataContract.documents.indexedArray;
|
|
1774
|
+
|
|
1775
|
+
const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1776
|
+
|
|
1777
|
+
rawDataContract.documents.indexedArray.properties.mentions.prefixItems = [
|
|
1778
|
+
{
|
|
1779
|
+
type: 'string',
|
|
1780
|
+
},
|
|
1781
|
+
{
|
|
1782
|
+
type: 'number',
|
|
1783
|
+
},
|
|
1784
|
+
];
|
|
1785
|
+
|
|
1786
|
+
rawDataContract.documents.indexedArray.properties.mentions.minItems = 2;
|
|
1787
|
+
|
|
1788
|
+
const result = await validateDataContract(rawDataContract);
|
|
1789
|
+
expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1790
|
+
|
|
1791
|
+
const error = result.getFirstError();
|
|
1792
|
+
|
|
1793
|
+
expect(error.getCode()).to.equal(1013);
|
|
1794
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
1795
|
+
expect(error.getPropertyType()).to.equal('array');
|
|
1796
|
+
expect(error.getDocumentType()).to.deep.equal('indexedArray');
|
|
1797
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1798
|
+
});
|
|
1799
|
+
|
|
1800
|
+
// TODO: support indexed arrays
|
|
1801
|
+
it.skip('should return invalid result if index property contained prefixItems array of arrays', async () => {
|
|
1802
|
+
const rawDataContract = dataContract.toObject();
|
|
1803
|
+
|
|
1804
|
+
const indexedDocumentDefinition = rawDataContract.documents.indexedArray;
|
|
1805
|
+
|
|
1806
|
+
const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1807
|
+
|
|
1808
|
+
rawDataContract.documents.indexedArray.properties.mentions.prefixItems = [
|
|
1809
|
+
{
|
|
1810
|
+
type: 'array',
|
|
1811
|
+
items: {
|
|
1812
|
+
type: 'string',
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
];
|
|
1816
|
+
|
|
1817
|
+
const result = await validateDataContract(rawDataContract);
|
|
1818
|
+
expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1819
|
+
|
|
1820
|
+
const error = result.getFirstError();
|
|
1821
|
+
|
|
1822
|
+
expect(error.getCode()).to.equal(1013);
|
|
1823
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
1824
|
+
expect(error.getPropertyType()).to.equal('array');
|
|
1825
|
+
expect(error.getDocumentType()).to.deep.equal('indexedArray');
|
|
1826
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
// TODO: support indexed arrays
|
|
1830
|
+
it.skip('should return invalid result if index property contained prefixItems array of objects', async () => {
|
|
1831
|
+
const rawDataContract = dataContract.toObject();
|
|
1832
|
+
|
|
1833
|
+
const indexedDocumentDefinition = rawDataContract.documents.indexedArray;
|
|
1834
|
+
|
|
1835
|
+
const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1836
|
+
|
|
1837
|
+
rawDataContract.documents.indexedArray.properties.mentions.prefixItems = [
|
|
1838
|
+
{
|
|
1839
|
+
type: 'object',
|
|
1840
|
+
properties: {
|
|
1841
|
+
something: {
|
|
1842
|
+
type: 'string',
|
|
1843
|
+
},
|
|
1844
|
+
},
|
|
1845
|
+
additionalProperties: false,
|
|
1846
|
+
},
|
|
1847
|
+
];
|
|
1848
|
+
|
|
1849
|
+
const result = await validateDataContract(rawDataContract);
|
|
1850
|
+
expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1851
|
+
|
|
1852
|
+
const error = result.getFirstError();
|
|
1853
|
+
|
|
1854
|
+
expect(error.getCode()).to.equal(1013);
|
|
1855
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
1856
|
+
expect(error.getPropertyType()).to.equal('array');
|
|
1857
|
+
expect(error.getDocumentType()).to.deep.equal('indexedArray');
|
|
1858
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1859
|
+
});
|
|
1860
|
+
|
|
1861
|
+
it('should return invalid result if index property is array of arrays', async () => {
|
|
1862
|
+
const rawDataContract = dataContract.toObject();
|
|
1863
|
+
const indexedDocumentDefinition = rawDataContract.documents.indexedDocument;
|
|
1864
|
+
|
|
1865
|
+
indexedDocumentDefinition.properties.arrayProperty = {
|
|
1866
|
+
type: 'array',
|
|
1867
|
+
items: {
|
|
1868
|
+
type: 'array',
|
|
1869
|
+
items: {
|
|
1870
|
+
type: 'string',
|
|
1871
|
+
},
|
|
1872
|
+
},
|
|
1873
|
+
};
|
|
1874
|
+
|
|
1875
|
+
indexedDocumentDefinition.required.push('arrayProperty');
|
|
1876
|
+
|
|
1877
|
+
const indexDefinition = indexedDocumentDefinition.indices[0];
|
|
1878
|
+
|
|
1879
|
+
indexDefinition.properties.push({
|
|
1880
|
+
arrayProperty: 'asc',
|
|
1881
|
+
});
|
|
1882
|
+
|
|
1883
|
+
const result = await validateDataContract(rawDataContract);
|
|
1884
|
+
|
|
1885
|
+
expectValidationError(result, InvalidIndexPropertyTypeError);
|
|
1886
|
+
|
|
1887
|
+
const [error] = result.getErrors();
|
|
1888
|
+
|
|
1889
|
+
expect(error.getCode()).to.equal(1013);
|
|
1890
|
+
expect(error.getPropertyName()).to.equal('arrayProperty');
|
|
1891
|
+
expect(error.getPropertyType()).to.equal('array');
|
|
1892
|
+
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1893
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1894
|
+
});
|
|
1836
1895
|
|
|
1837
1896
|
it('should return invalid result if index property is array with different item definitions', async () => {
|
|
1897
|
+
const rawDataContract = dataContract.toObject();
|
|
1838
1898
|
const indexedDocumentDefinition = rawDataContract.documents.indexedDocument;
|
|
1839
1899
|
|
|
1840
1900
|
indexedDocumentDefinition.properties.arrayProperty = {
|
|
@@ -1869,10 +1929,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
1869
1929
|
expect(error.getPropertyName()).to.equal('arrayProperty');
|
|
1870
1930
|
expect(error.getPropertyType()).to.equal('array');
|
|
1871
1931
|
expect(error.getDocumentType()).to.deep.equal('indexedDocument');
|
|
1872
|
-
expect(error.getIndexDefinition()).to.deep.equal(indexDefinition);
|
|
1932
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(indexDefinition);
|
|
1873
1933
|
});
|
|
1874
1934
|
|
|
1875
1935
|
it('should return invalid result if unique compound index contains both required and optional properties', async () => {
|
|
1936
|
+
const rawDataContract = dataContract.toObject();
|
|
1876
1937
|
rawDataContract.documents.optionalUniqueIndexedDocument.required.splice(-1);
|
|
1877
1938
|
|
|
1878
1939
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -1882,7 +1943,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
1882
1943
|
const [error] = result.getErrors();
|
|
1883
1944
|
|
|
1884
1945
|
expect(error.getCode()).to.equal(1010);
|
|
1885
|
-
expect(error.getIndexDefinition()).to.deep.equal(
|
|
1946
|
+
expect(error.getIndexDefinition().toObject()).to.deep.equal(
|
|
1886
1947
|
rawDataContract.documents.optionalUniqueIndexedDocument.indices[1],
|
|
1887
1948
|
);
|
|
1888
1949
|
expect(error.getDocumentType()).to.equal('optionalUniqueIndexedDocument');
|
|
@@ -1892,34 +1953,37 @@ describe('validateDataContractFactory', function main() {
|
|
|
1892
1953
|
|
|
1893
1954
|
describe('signatureSecurityLevelRequirement', () => {
|
|
1894
1955
|
it('should be a number', async () => {
|
|
1956
|
+
const rawDataContract = dataContract.toObject();
|
|
1895
1957
|
rawDataContract.documents.indexedDocument.signatureSecurityLevelRequirement = 'definitely not a number';
|
|
1896
1958
|
|
|
1897
1959
|
const result = await validateDataContract(rawDataContract);
|
|
1898
1960
|
|
|
1899
|
-
expectJsonSchemaError(result);
|
|
1961
|
+
await expectJsonSchemaError(result, 2);
|
|
1900
1962
|
|
|
1901
1963
|
const [error] = result.getErrors();
|
|
1902
1964
|
|
|
1903
|
-
expect(error.
|
|
1965
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/signatureSecurityLevelRequirement');
|
|
1904
1966
|
expect(error.getKeyword()).to.equal('type');
|
|
1905
1967
|
});
|
|
1906
1968
|
|
|
1907
1969
|
it('should be one of the available values', async () => {
|
|
1970
|
+
const rawDataContract = dataContract.toObject();
|
|
1908
1971
|
rawDataContract.documents.indexedDocument.signatureSecurityLevelRequirement = 199;
|
|
1909
1972
|
|
|
1910
1973
|
const result = await validateDataContract(rawDataContract);
|
|
1911
1974
|
|
|
1912
|
-
expectJsonSchemaError(result);
|
|
1975
|
+
await expectJsonSchemaError(result);
|
|
1913
1976
|
|
|
1914
1977
|
const [error] = result.getErrors();
|
|
1915
1978
|
|
|
1916
|
-
expect(error.
|
|
1979
|
+
expect(error.getInstancePath()).to.equal('/documents/indexedDocument/signatureSecurityLevelRequirement');
|
|
1917
1980
|
expect(error.getKeyword()).to.equal('enum');
|
|
1918
1981
|
});
|
|
1919
1982
|
});
|
|
1920
1983
|
|
|
1921
1984
|
describe('dependentSchemas', () => {
|
|
1922
1985
|
it('should be an object', async () => {
|
|
1986
|
+
const rawDataContract = dataContract.toObject();
|
|
1923
1987
|
rawDataContract.documents.niceDocument = {
|
|
1924
1988
|
type: 'object',
|
|
1925
1989
|
properties: {
|
|
@@ -1933,18 +1997,18 @@ describe('validateDataContractFactory', function main() {
|
|
|
1933
1997
|
|
|
1934
1998
|
const result = await validateDataContract(rawDataContract);
|
|
1935
1999
|
|
|
1936
|
-
expectJsonSchemaError(result);
|
|
2000
|
+
await expectJsonSchemaError(result);
|
|
1937
2001
|
|
|
1938
2002
|
const [error] = result.getErrors();
|
|
1939
2003
|
|
|
1940
2004
|
expect(error.getKeyword()).to.equal('type');
|
|
1941
|
-
expect(error.
|
|
1942
|
-
expect(error.message).to.equal('must be object');
|
|
2005
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/dependentSchemas');
|
|
1943
2006
|
});
|
|
1944
2007
|
});
|
|
1945
2008
|
|
|
1946
2009
|
describe('dependentRequired', () => {
|
|
1947
2010
|
it('should be an object', async () => {
|
|
2011
|
+
const rawDataContract = dataContract.toObject();
|
|
1948
2012
|
rawDataContract.documents.niceDocument = {
|
|
1949
2013
|
type: 'object',
|
|
1950
2014
|
properties: {
|
|
@@ -1958,16 +2022,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
1958
2022
|
|
|
1959
2023
|
const result = await validateDataContract(rawDataContract);
|
|
1960
2024
|
|
|
1961
|
-
expectJsonSchemaError(result);
|
|
2025
|
+
await expectJsonSchemaError(result);
|
|
1962
2026
|
|
|
1963
2027
|
const [error] = result.getErrors();
|
|
1964
2028
|
|
|
1965
2029
|
expect(error.getKeyword()).to.equal('type');
|
|
1966
|
-
expect(error.
|
|
1967
|
-
expect(error.message).to.equal('must be object');
|
|
2030
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/dependentRequired');
|
|
1968
2031
|
});
|
|
1969
2032
|
|
|
1970
2033
|
it('should have an array value', async () => {
|
|
2034
|
+
const rawDataContract = dataContract.toObject();
|
|
1971
2035
|
rawDataContract.documents.niceDocument = {
|
|
1972
2036
|
type: 'object',
|
|
1973
2037
|
properties: {
|
|
@@ -1985,16 +2049,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
1985
2049
|
|
|
1986
2050
|
const result = await validateDataContract(rawDataContract);
|
|
1987
2051
|
|
|
1988
|
-
expectJsonSchemaError(result);
|
|
2052
|
+
await expectJsonSchemaError(result);
|
|
1989
2053
|
|
|
1990
2054
|
const [error] = result.getErrors();
|
|
1991
2055
|
|
|
1992
2056
|
expect(error.getKeyword()).to.equal('type');
|
|
1993
|
-
expect(error.
|
|
1994
|
-
expect(error.message).to.equal('must be array');
|
|
2057
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/dependentRequired/zxy');
|
|
1995
2058
|
});
|
|
1996
2059
|
|
|
1997
2060
|
it('should have an array of strings', async () => {
|
|
2061
|
+
const rawDataContract = dataContract.toObject();
|
|
1998
2062
|
rawDataContract.documents.niceDocument = {
|
|
1999
2063
|
type: 'object',
|
|
2000
2064
|
properties: {
|
|
@@ -2010,16 +2074,16 @@ describe('validateDataContractFactory', function main() {
|
|
|
2010
2074
|
|
|
2011
2075
|
const result = await validateDataContract(rawDataContract);
|
|
2012
2076
|
|
|
2013
|
-
expectJsonSchemaError(result);
|
|
2077
|
+
await expectJsonSchemaError(result);
|
|
2014
2078
|
|
|
2015
2079
|
const [error] = result.getErrors();
|
|
2016
2080
|
|
|
2017
2081
|
expect(error.getKeyword()).to.equal('type');
|
|
2018
|
-
expect(error.
|
|
2019
|
-
expect(error.message).to.equal('must be string');
|
|
2082
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/dependentRequired/zxy/0');
|
|
2020
2083
|
});
|
|
2021
2084
|
|
|
2022
2085
|
it('should have an array of unique strings', async () => {
|
|
2086
|
+
const rawDataContract = dataContract.toObject();
|
|
2023
2087
|
rawDataContract.documents.niceDocument = {
|
|
2024
2088
|
type: 'object',
|
|
2025
2089
|
properties: {
|
|
@@ -2035,17 +2099,18 @@ describe('validateDataContractFactory', function main() {
|
|
|
2035
2099
|
|
|
2036
2100
|
const result = await validateDataContract(rawDataContract);
|
|
2037
2101
|
|
|
2038
|
-
expectJsonSchemaError(result);
|
|
2102
|
+
await expectJsonSchemaError(result);
|
|
2039
2103
|
|
|
2040
2104
|
const [error] = result.getErrors();
|
|
2041
2105
|
|
|
2042
2106
|
expect(error.getKeyword()).to.equal('uniqueItems');
|
|
2043
|
-
expect(error.
|
|
2044
|
-
expect(error.message).to.equal('must NOT have duplicate items (items ## 2 and 1 are identical)');
|
|
2107
|
+
expect(error.getInstancePath()).to.equal('/documents/niceDocument/dependentRequired/zxy');
|
|
2045
2108
|
});
|
|
2046
2109
|
});
|
|
2047
2110
|
|
|
2048
|
-
it
|
|
2111
|
+
it('should return invalid result with circular $ref pointer', async () => {
|
|
2112
|
+
const rawDataContract = dataContract.toObject();
|
|
2113
|
+
rawDataContract.$defs = {};
|
|
2049
2114
|
rawDataContract.$defs.object = { $ref: '#/$defs/object' };
|
|
2050
2115
|
|
|
2051
2116
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -2055,11 +2120,10 @@ describe('validateDataContractFactory', function main() {
|
|
|
2055
2120
|
const [error] = result.getErrors();
|
|
2056
2121
|
|
|
2057
2122
|
expect(error.getCode()).to.equal(1014);
|
|
2058
|
-
|
|
2059
|
-
expect(error.message).to.startsWith('Invalid JSON Schema $ref: Circular $ref pointer found');
|
|
2060
2123
|
});
|
|
2061
2124
|
|
|
2062
2125
|
it('should return invalid result if indexed string property missing maxLength constraint', async () => {
|
|
2126
|
+
const rawDataContract = dataContract.toObject();
|
|
2063
2127
|
delete rawDataContract.documents.indexedDocument.properties.firstName.maxLength;
|
|
2064
2128
|
|
|
2065
2129
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -2071,10 +2135,11 @@ describe('validateDataContractFactory', function main() {
|
|
|
2071
2135
|
expect(error.getCode()).to.equal(1012);
|
|
2072
2136
|
expect(error.getPropertyName()).to.equal('firstName');
|
|
2073
2137
|
expect(error.getConstraintName()).to.equal('maxLength');
|
|
2074
|
-
expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2138
|
+
expect(error.getReason()).to.equal('should be less or equal than 63');
|
|
2075
2139
|
});
|
|
2076
2140
|
|
|
2077
2141
|
it('should return invalid result if indexed string property have to big maxLength', async () => {
|
|
2142
|
+
const rawDataContract = dataContract.toObject();
|
|
2078
2143
|
rawDataContract.documents.indexedDocument.properties.firstName.maxLength = 2048;
|
|
2079
2144
|
|
|
2080
2145
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -2086,73 +2151,80 @@ describe('validateDataContractFactory', function main() {
|
|
|
2086
2151
|
expect(error.getCode()).to.equal(1012);
|
|
2087
2152
|
expect(error.getPropertyName()).to.equal('firstName');
|
|
2088
2153
|
expect(error.getConstraintName()).to.equal('maxLength');
|
|
2154
|
+
expect(error.getReason()).to.equal('should be less or equal than 63');
|
|
2155
|
+
});
|
|
2156
|
+
|
|
2157
|
+
// TODO: support indexed arrays
|
|
2158
|
+
it.skip('should return invalid result if indexed array property missing maxItems constraint',
|
|
2159
|
+
async () => {
|
|
2160
|
+
const rawDataContract = dataContract.toObject();
|
|
2161
|
+
delete rawDataContract.documents.indexedArray.properties.mentions.maxItems;
|
|
2162
|
+
|
|
2163
|
+
const result = await validateDataContract(rawDataContract);
|
|
2164
|
+
|
|
2165
|
+
expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2166
|
+
|
|
2167
|
+
const [error] = result.getErrors();
|
|
2168
|
+
|
|
2169
|
+
expect(error.getCode()).to.equal(1012);
|
|
2170
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
2171
|
+
expect(error.getConstraintName()).to.equal('maxItems');
|
|
2172
|
+
expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2173
|
+
});
|
|
2174
|
+
|
|
2175
|
+
// TODO support indexed arrays
|
|
2176
|
+
it.skip('should return invalid result if indexed array property have to big maxItems', async () => {
|
|
2177
|
+
const rawDataContract = dataContract.toObject();
|
|
2178
|
+
rawDataContract.documents.indexedArray.properties.mentions.maxItems = 2048;
|
|
2179
|
+
|
|
2180
|
+
const result = await validateDataContract(rawDataContract);
|
|
2181
|
+
|
|
2182
|
+
expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2183
|
+
|
|
2184
|
+
const [error] = result.getErrors();
|
|
2185
|
+
|
|
2186
|
+
expect(error.getCode()).to.equal(1012);
|
|
2187
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
2188
|
+
expect(error.getConstraintName()).to.equal('maxItems');
|
|
2189
|
+
expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2190
|
+
});
|
|
2191
|
+
|
|
2192
|
+
// TODO support indexed arrays
|
|
2193
|
+
it.skip('should return invalid result if indexed array property have string item without maxItems constraint', async () => {
|
|
2194
|
+
const rawDataContract = dataContract.toObject();
|
|
2195
|
+
delete rawDataContract.documents.indexedArray.properties.mentions.maxItems;
|
|
2196
|
+
|
|
2197
|
+
const result = await validateDataContract(rawDataContract);
|
|
2198
|
+
|
|
2199
|
+
expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2200
|
+
|
|
2201
|
+
const [error] = result.getErrors();
|
|
2202
|
+
|
|
2203
|
+
expect(error.getCode()).to.equal(1012);
|
|
2204
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
2205
|
+
expect(error.getConstraintName()).to.equal('maxItems');
|
|
2089
2206
|
expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2090
2207
|
});
|
|
2091
2208
|
|
|
2092
|
-
//
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
// it('should return invalid result if indexed array property have to big maxItems', async () => {
|
|
2109
|
-
// rawDataContract.documents.indexedArray.properties.mentions.maxItems = 2048;
|
|
2110
|
-
//
|
|
2111
|
-
// const result = await validateDataContract(rawDataContract);
|
|
2112
|
-
//
|
|
2113
|
-
// expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2114
|
-
//
|
|
2115
|
-
// const [error] = result.getErrors();
|
|
2116
|
-
//
|
|
2117
|
-
// expect(error.getCode()).to.equal(1012);
|
|
2118
|
-
// expect(error.getPropertyName()).to.equal('mentions');
|
|
2119
|
-
// expect(error.getConstraintName()).to.equal('maxItems');
|
|
2120
|
-
// expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2121
|
-
// });
|
|
2122
|
-
//
|
|
2123
|
-
// it('should return invalid result if indexed array property
|
|
2124
|
-
// have string item without maxItems constraint', async () => {
|
|
2125
|
-
// delete rawDataContract.documents.indexedArray.properties.mentions.maxItems;
|
|
2126
|
-
//
|
|
2127
|
-
// const result = await validateDataContract(rawDataContract);
|
|
2128
|
-
//
|
|
2129
|
-
// expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2130
|
-
//
|
|
2131
|
-
// const [error] = result.getErrors();
|
|
2132
|
-
//
|
|
2133
|
-
// expect(error.getCode()).to.equal(1012);
|
|
2134
|
-
// expect(error.getPropertyName()).to.equal('mentions');
|
|
2135
|
-
// expect(error.getConstraintName()).to.equal('maxItems');
|
|
2136
|
-
// expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2137
|
-
// });
|
|
2138
|
-
//
|
|
2139
|
-
// it('should return invalid result if indexed array property have
|
|
2140
|
-
// string item with maxItems bigger than 1024', async () => {
|
|
2141
|
-
// rawDataContract.documents.indexedArray.properties.mentions.maxItems = 2048;
|
|
2142
|
-
//
|
|
2143
|
-
// const result = await validateDataContract(rawDataContract);
|
|
2144
|
-
//
|
|
2145
|
-
// expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2146
|
-
//
|
|
2147
|
-
// const [error] = result.getErrors();
|
|
2148
|
-
//
|
|
2149
|
-
// expect(error.getCode()).to.equal(1012);
|
|
2150
|
-
// expect(error.getPropertyName()).to.equal('mentions');
|
|
2151
|
-
// expect(error.getConstraintName()).to.equal('maxItems');
|
|
2152
|
-
// expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2153
|
-
// });
|
|
2209
|
+
// TODO support indexed arrays
|
|
2210
|
+
it.skip('should return invalid result if indexed array property have string item with maxItems bigger than 1024', async () => {
|
|
2211
|
+
const rawDataContract = dataContract.toObject();
|
|
2212
|
+
rawDataContract.documents.indexedArray.properties.mentions.maxItems = 2048;
|
|
2213
|
+
|
|
2214
|
+
const result = await validateDataContract(rawDataContract);
|
|
2215
|
+
|
|
2216
|
+
expectValidationError(result, InvalidIndexedPropertyConstraintError);
|
|
2217
|
+
|
|
2218
|
+
const [error] = result.getErrors();
|
|
2219
|
+
|
|
2220
|
+
expect(error.getCode()).to.equal(1012);
|
|
2221
|
+
expect(error.getPropertyName()).to.equal('mentions');
|
|
2222
|
+
expect(error.getConstraintName()).to.equal('maxItems');
|
|
2223
|
+
expect(error.getReason()).to.equal('should be less or equal 63');
|
|
2224
|
+
});
|
|
2154
2225
|
|
|
2155
2226
|
it('should return invalid result if indexed byte array property missing maxItems constraint', async () => {
|
|
2227
|
+
const rawDataContract = dataContract.toObject();
|
|
2156
2228
|
delete rawDataContract.documents.withByteArrays.properties.byteArrayField.maxItems;
|
|
2157
2229
|
|
|
2158
2230
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -2168,6 +2240,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
2168
2240
|
});
|
|
2169
2241
|
|
|
2170
2242
|
it('should return invalid result if indexed byte array property have to big maxItems', async () => {
|
|
2243
|
+
const rawDataContract = dataContract.toObject();
|
|
2171
2244
|
rawDataContract.documents.withByteArrays.properties.byteArrayField.maxItems = 8192;
|
|
2172
2245
|
|
|
2173
2246
|
const result = await validateDataContract(rawDataContract);
|
|
@@ -2183,6 +2256,7 @@ describe('validateDataContractFactory', function main() {
|
|
|
2183
2256
|
});
|
|
2184
2257
|
|
|
2185
2258
|
it('should return valid result if Data Contract is valid', async () => {
|
|
2259
|
+
const rawDataContract = dataContract.toObject();
|
|
2186
2260
|
const result = await validateDataContract(rawDataContract);
|
|
2187
2261
|
|
|
2188
2262
|
expect(result).to.be.an.instanceOf(ValidationResult);
|