[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test-utils / factories / softwareProduct / SoftwareProductQSchemaFactory.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the 'License');
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an 'AS IS' BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import {Factory} from 'rosie';
17
18 const parsePropertiesForSchema = (obj) => {
19         let schemaProperties = {};
20
21         Object.keys(obj).forEach(prop => {
22                 let type = typeof obj[prop];
23                 if (type === undefined){throw new Error('Schema property cannot be undefined');}
24                 if (type === 'object'){
25                         if (Array.isArray(obj[prop])) {
26                                 schemaProperties[prop] = {type: 'array'};
27                         } else if (Object.is(obj[prop], null)){
28                                 throw new Error('Schema property cannot be null');
29                         } else {
30                                 schemaProperties[prop] = {properties: parsePropertiesForSchema(obj[prop]), type: 'object'};
31                         }
32                 } else {
33                         schemaProperties[prop] = {type};
34                 }
35         });
36
37         return schemaProperties;
38 };
39
40 export default new Factory()
41         .after(schema => {
42                 const propertiesForSchema = parsePropertiesForSchema(schema);
43                 for (let attribute in schema) {
44                         delete schema[attribute];
45                 }
46                 schema.$schema = 'http://json-schema.org/draft-04/schema#';
47                 schema.type = 'object';
48                 schema.properties = propertiesForSchema;
49         });
50
51
52 export const SchemaGenericFieldInfoFactory = new Factory()
53         .attrs({
54                 'general/affinityData': {
55                         'hasErrors': false,
56                         'errorText': '',
57                         'type': 'string',
58                         'enum': [{'enum': 'Affinity', 'title': 'Affinity'}, {
59                                 'enum': 'Anti Affinity',
60                                 'title': 'Anti Affinity'
61                         }, {'enum': 'None', 'title': 'None'}],
62                         'default': '',
63                         'validations': []
64                 },
65                 'general/availability/useAvailabilityZonesForHighAvailability': {
66                         'hasErrors': false,
67                         'errorText': '',
68                         'type': 'boolean',
69                         'default': false,
70                         'validations': []
71                 },
72                 'general/regionsData/multiRegion': {
73                         'hasErrors': false,
74                         'errorText': '',
75                         'type': 'boolean',
76                         'default': false,
77                         'validations': []
78                 },
79                 'general/regionsData/regions': {
80                         'hasErrors': false,
81                         'errorText': '',
82                         'enum': [{'enum': 'Alphareta', 'title': 'Alphareta'}, {
83                                 'enum': 'Birmingham',
84                                 'title': 'Birmingham'
85                         }, {'enum': 'Dallas', 'title': 'Dallas'}, {
86                                 'enum': 'Fairfield CA',
87                                 'title': 'Fairfield CA'
88                         }, {'enum': 'Hayward CA', 'title': 'Hayward CA'}, {'enum': 'Lisle', 'title': 'Lisle'}, {
89                                 'enum': 'Mission',
90                                 'title': 'Mission'
91                         }, {'enum': 'San Diego', 'title': 'San Diego'}, {'enum': 'Secaucus', 'title': 'Secaucus'}],
92                         'items': {
93                                 'type': 'string',
94                                 'enum': ['', 'Alphareta', 'Birmingham', 'Dallas', 'Fairfield CA', 'Hayward CA', 'Lisle', 'Mission', 'San Diego', 'Secaucus'],
95                                 'default': ''
96                         },
97                         'validations': []
98                 },
99                 'general/storageDataReplication/storageReplicationAcrossRegion': {
100                         'hasErrors': false,
101                         'errorText': '',
102                         'type': 'boolean',
103                         'default': false,
104                         'validations': []
105                 },
106                 'general/storageDataReplication/storageReplicationSize': {
107                         'hasErrors': false,
108                         'errorText': '',
109                         'type': 'number',
110                         'exclusiveMaximum': true,
111                         'validations': [{'type': 'maximumExclusive', 'data': 100}]
112                 },
113                 'general/storageDataReplication/storageReplicationFrequency': {
114                         'hasErrors': false,
115                         'errorText': '',
116                         'type': 'number',
117                         'validations': [{'type': 'minimum', 'data': 5}]
118                 },
119                 'general/storageDataReplication/storageReplicationSource': {
120                         'hasErrors': false,
121                         'errorText': '',
122                         'type': 'string',
123                         'validations': [{'type': 'maxLength', 'data': 300}]
124                 },
125                 'general/storageDataReplication/storageReplicationDestination': {
126                         'hasErrors': false,
127                         'errorText': '',
128                         'type': 'string',
129                         'validations': [{'type': 'maxLength', 'data': 300}]
130                 }
131         });