Example #1
0
    test('complex array', (t) => {
      const actual = t.context.document.buildValue(items({
        type: 'object',
        data: { count: 5 },
        properties: {
          first_name: {
            type: 'string',
            description: 'The childs first_name',
            data: { fake: '{{name.firstName}}' },
          },
          gender: {
            type: 'string',
            description: 'The childs gender',
            data: { build: () => to.random(1, 10) >= 3 ? to.random([ 'M', 'F' ]) : null },
          },
          age: {
            type: 'integer',
            description: 'The childs age',
            data: { build: () => to.random(1, 17) },
          },
        }
      }), []);

      is.assert(actual, is.array()
        .items(is.object({
          first_name: is.string().regex(/[A-Z][a-zA-Z\s]+/),
          gender: [ is.string().regex(/M|F/), is.allow(null) ],
          age: is.number().min(1).max(17),
        }))
        .length(5));
    });
Example #2
0
var getOrCreateUser = module.exports.getOrCreateUser = function(externalId, tenantId, name, callback) {
  // Parameter validation
  var validationSchema = Joi.object().keys({
    externalId: Joi.string().required(),
    tenantId: Joi.number().required(),
    name: [Joi.string().optional(), Joi.allow(null)]
  });
  var validationResult = Joi.validate({
    externalId: externalId,
    tenantId: tenantId,
    name: name
  }, validationSchema);
  if (validationResult.error) {
    return callback({code: 400, msg: validationResult.error.details[0].message});
  }
  // Get the user from the DB or create it if it doesn't exist yet
  var options = {
    where: {
      external_id: externalId,
      tenant_id: tenantId
    },
    defaults: {
      name: name
    }
  };
  DB.User.findOrCreate(options).complete(function(err, data) {
    if (err) {
      log.error({err: err}, 'Failed to get or create a user');
      return callback({code: 500, msg: err.message});
    }
    var user = data[0];
    var wasCreated = data[1];
    if (wasCreated) {
      log.info({id: user.id}, 'Created a new user');
    }
    return callback(null, user);
  });
};
Example #3
0
    app: Joi.object().allow(null),
    compression: Joi.boolean(),
    load: Joi.object(),
    plugins: Joi.object(),
    router: Joi.object({
        isCaseSensitive: Joi.boolean(),
        stripTrailingSlash: Joi.boolean()
    }),
    routes: internals.routeBase,
    state: Joi.object()                                     // Cookie defaults
});


internals.server = Joi.object({
    app: Joi.object().allow(null),
    cache: Joi.allow(null),                                 // Validated elsewhere
    connections: internals.connectionBase,
    debug: Joi.object({
        request: Joi.array().items(Joi.string()).single().allow(false),
        log: Joi.array().items(Joi.string()).single().allow(false)
    }).allow(false),
    load: Joi.object(),
    mime: Joi.object(),
    plugins: Joi.object(),
    useDomains: Joi.boolean()
});


internals.connection = internals.connectionBase.keys({
    autoListen: Joi.boolean(),
    host: Joi.string().hostname(),
module.exports = function (server, conf) {
	
	var handlers = require('./dataprovider.handlers')(server, conf);
	var Joi = require('joi');	

	var clinicaldatapost = Joi.object({
        	type: Joi.string().valid('clinicalData').required(),
        	patientId: Joi.any().required(),
        	date: Joi.date().required(),
        	scope: Joi.array().items(Joi.string()).optional()
        }).unknown();

	var clinicaldata = Joi.object({
			_id: Joi.string().alphanum().required(),
			_rev: Joi.string().required(),
        	type: Joi.string().valid('clinicalData').required(),
        	patientId: Joi.any().required(),
        	date: Joi.date().optional(),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        }).unknown();

	var clinicalcollectionpost = Joi.object({
			name: Joi.string().required(),
        	type: Joi.string().valid('clinicalDataCollection'),
        	items: Joi.array().items(Joi.object().keys({
        		_id: Joi.string().alphanum().required()
        	})),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        });

	var clinicalcollection = Joi.object({
			_id: Joi.string().alphanum().required(),
			_rev: Joi.string().required(),
        	type: Joi.string().valid('clinicalDataCollection').required(),
        	name: Joi.string().required(),
        	scope: Joi.array().items(Joi.string()).required(),
        	items: Joi.array().items(Joi.object().keys({
        		_id: Joi.string().alphanum()
        	})),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        });

	var morphologicaldatapost = Joi.object({
        	type: Joi.string().valid('morphologicalData').required(),
        	patientId: Joi.any().required(),
        	date: Joi.date().required(),
        	scope: Joi.array().items(Joi.string()).optional()
        }).unknown();

	var morphologicaldata = Joi.object({
			_id: Joi.string().alphanum().required(),
			_rev: Joi.string().required(),
        	type: Joi.string().valid('morphologicalData').required(),
        	patientId: Joi.any().required(),
        	date: Joi.date().optional(),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        }).unknown();

	var morphologicalcollectionpost = Joi.object({
			name: Joi.string().required(),
        	type: Joi.string().valid('morphologicalDataCollection'),
        	items: Joi.array().items(Joi.object().keys({
        		_id: Joi.string().alphanum().required()
        	})),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        });

	var morphologicalcollection = Joi.object({
			_id: Joi.string().alphanum().required(),
			_rev: Joi.string().required(),
        	type: Joi.string().valid('morphologicalDataCollection').required(),
        	name: Joi.string().required(),
        	scope: Joi.array().items(Joi.string()).required(),
        	items: Joi.array().items(Joi.object().keys({
        		_id: Joi.string().alphanum()
        	})),
        	scope: Joi.array().items(Joi.string()).optional(),
        	owner: Joi.string().email().optional()
        });

	var dataowned = Joi.object({
			_id: Joi.string().alphanum().required(),
			formId: Joi.string().required(),
			patientId: Joi.any().required(),
			owner: Joi.string().required(),
			date: Joi.string().required()
		}).unknown();
	
	var project = Joi.object({
			_id: Joi.string().alphanum().required(),
			_rev: Joi.string().required(),
			type: Joi.string().valid('project').required(),
			name: Joi.string().required(),
			patients: Joi.string().alphanum().optional(),
			description: Joi.string().required(),
			collections: Joi.allow(Joi.array().items(Joi.object().keys({
				_id: Joi.string().alphanum()
			})), Joi.object().optional()),
			scope: Joi.array().items(Joi.string()).optional(),
			analyses: Joi.array().items(Joi.object()).optional(),
			owner: Joi.string().email().optional()
		});

	var projectpost = Joi.object({
			name: Joi.string().required(),
        	type: Joi.string().valid('project').required(),
        	description: Joi.string().required(),
        	patients: Joi.string().alphanum().optional(),
        	collections: Joi.array().items(Joi.object().keys({
        		_id: Joi.string().alphanum().required()
        	})),
        	owner: Joi.string().email().optional()
        });


	server.route({
		path: '/dcbia/clinical/collections',
		method: 'GET',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getClinicalCollections,
			validate: {
				query: false,
		        payload: false,
		        params: false
			},
			response: {
				schema: Joi.array().items(clinicalcollection)
			},
			description: 'Get all the clinical data collections in the database.'
		}
	});

	server.route({
		path: '/dcbia/clinical/collection',
		method: 'POST',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.createDocument,
			validate: {
				query: false,
		        payload: clinicalcollectionpost,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'Create a new clinical data collection.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/clinical/collection/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: clinicalcollection
			},
			description: 'Get a clinical data collection document from the database'
	    }
	});

	server.route({
		path: '/dcbia/clinical/collection/{id}',
		method: 'DELETE',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.deleteDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			payload:{
				output: 'data'
			},
			description: 'Delete a clinical collection from the database'
		}
	});

	server.route({
		path: '/dcbia/clinical/collection',
		method: 'PUT',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.updateDocument,
			validate: {
				query: false,
		        payload: clinicalcollection,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'Update a clinical data collection.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/clinical/collection/data",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getAllClinicalCollectionData,
			validate: {
			  	query: false,
			    params: false, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(clinicaldata)
			},
			description: 'Get all clinical data'
	    }
	});


	server.route({
		method: 'GET',
		path: "/dcbia/clinical/collection/data/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getClinicalCollectionData,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(clinicaldata)
			},
			description: 'Get the data from a clinical data collection'
	    }
	});

	server.route({
		method: 'GET',
		path: "/dcbia/clinical/data/owner",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getClinicalDataOwner,
			validate: {
			  	query: {
			    	email: Joi.string().optional()
			    },
			    params: false, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(dataowned)
			},
			description: 'Get clinical data by the owner who created the collection'
	    }
	});

	server.route({
		path: '/dcbia/clinical/data',
		method: 'GET',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getClinicalData,
			validate: {
				query: {
			    	patientId: Joi.string().optional(),
			    	date: Joi.date().optional()
			    },
		        payload: false,
		        params: false
			},
			response: {
				schema: Joi.array().items(clinicaldata)
			},
			description: 'Get clinical data from the database using optional query parameters patientId and/or date'
		}
	});

	server.route({
		path: '/dcbia/clinical/data',
		method: 'POST',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.createDocument,
			validate: {
				query: false,
		        payload: clinicaldatapost,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'Create a new clinical data item'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/clinical/data/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: clinicaldata
			},
			description: 'Get a clinical data item from the database'
	    }
	});

	server.route({
		path: '/dcbia/clinical/data/{id}',
		method: 'DELETE',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.deleteDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to delete job documents from the database'
		}
	});

	server.route({
		path: '/dcbia/clinical/data',
		method: 'PUT',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.updateDocument,
			validate: {
				query: false,
		        payload: clinicaldata,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to update a job document in the couch database.'
		}
	});

	server.route({
		path: '/dcbia/morphological/collections',
		method: 'GET',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getMorphologicalCollections,
			validate: {
				query: false,
		        payload: false,
		        params: false
			},
			response: {
				schema: Joi.array().items(morphologicalcollection)
			},
			description: 'This route will be used to post job documents to the couch database.'
		}
	});

	server.route({
		path: '/dcbia/morphological/collection',
		method: 'POST',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.createDocument,
			validate: {
				query: false,
		        payload: morphologicalcollectionpost,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to post job documents to the couch database.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/collection/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: morphologicalcollection
			},
			description: 'Get the job document posted to the database'
	    }
	});

	server.route({
		path: '/dcbia/morphological/collection/{id}',
		method: 'DELETE',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.deleteDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to delete job documents from the database'
		}
	});

	server.route({
		path: '/dcbia/morphological/collection',
		method: 'PUT',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.updateDocument,
			validate: {
				query: false,
		        payload: morphologicalcollection,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to update a job document in the couch database.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/collection/data",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getAllMorphologicalCollectionData,
			validate: {
			  	query: false,
			    params: false, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(morphologicaldata)
			},
			description: 'Get all morphological data'
	    }
	});


	server.route({
		method: 'GET',
		path: "/dcbia/morphological/collection/data/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getMorphologicalCollectionData,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(morphologicaldata)
			},
			description: 'Get the morphological data for a collection given the collectionId'
	    }
	});


	server.route({
		path: '/dcbia/morphological/data',
		method: 'POST',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.createDocument,
			validate: {
				query: false,
		        payload: morphologicaldatapost,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to post job documents to the couch database.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/data/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: morphologicaldata
			},
			description: 'Get the job document posted to the database'
	    }
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/data/patientId/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getMorphologicalDataByPatientId,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			response: {
				schema: Joi.array(morphologicaldata)
			},
			description: 'Get the morphological data by patientId'
	    }
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/data",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getMorphologicalData,
			validate: {
			  	query: {
			    	patientId: Joi.string().optional(),
			    	date: Joi.date().optional()
			    },
			    params: false, 
			    payload: false
			},
			response: {
				schema: Joi.array(morphologicaldata)
			},
			description: 'Get the morphological data by patientId'
	    }
	});

	server.route({
		path: '/dcbia/morphological/data/{id}',
		method: 'DELETE',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.deleteDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to delete job documents from the database'
		}
	});

	server.route({
		path: '/dcbia/morphological/data',
		method: 'PUT',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.updateDocument,
			validate: {
				query: false,
		        payload: morphologicaldata,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to update a job document in the couch database.'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/{id}/{name}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getAttachment,
	      	validate: {
		      	query: false,
		        params: {
		        	id: Joi.string().alphanum().required(),
		        	name: Joi.string().required()
		        },
		        payload: false
		    },
		    description: 'Get attachment data'
	    }
	});

	server.route({
		method: 'PUT',
		path: "/dcbia/{id}/{name}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.addAttachment,
	      	validate: {
		      	query: false,
		        params: {
		        	id: Joi.string().alphanum().required(),
		        	name: Joi.string().required()
		        },
		        payload: true
		    },
		    payload: {
	        	maxBytes: 1024 * 1024 * 1024,
	    		output: 'stream'
	        },
		    description: 'Add attachment data'
	    }
	});

	server.route({
		method: 'GET',
		path: "/dcbia/projects",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getProjects,
			validate: {
			  	query: false,
			    params: false, 
			    payload: false
			},
			response: {
				schema: Joi.array().items(project)
			},
			description: 'Get the job document posted to the database'
	    }
	});

	server.route({
		method: 'GET',
		path: "/dcbia/project/{id}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string()
			    }, 
			    payload: false
			},
			response: {
				schema: project
			},
			description: 'Get the job document posted to the database'
	    }
	});	

	server.route({
		path: '/dcbia/projects',
		method: 'PUT',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.updateDocument,
			validate: {
				query: false,
		        payload: project,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to update a job document in the couch database.'
		}
	});


	server.route({
		method: 'POST',
		path: "/dcbia/projects",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.createDocument,
			validate: {
				query: false,
		        payload: projectpost,
		        params: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to post job documents to the couch database.'
		}
	});

	server.route({
		path: '/dcbia/project/{id}',
		method: 'DELETE',
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.deleteDocument,
			validate: {
			  	query: false,
			    params: {
			    	id: Joi.string().alphanum().required()
			    }, 
			    payload: false
			},
			payload:{
				output: 'data'
			},
			description: 'This route will be used to delete job documents from the database'
		}
	});

	server.route({
		method: 'GET',
		path: "/dcbia/morphological/data/{collectionId}/patient/{patientId}",
		config: {
			auth: {
                strategy: 'token',
                scope: ['dentist']
            },
			handler: handlers.getMorphologicalDataByCollectionIdPatientId,
			validate: {
			  	query: false,
			    params: {
			    	collectionId: Joi.string(),
			    	patientId: Joi.string()
			    }, 
			    payload: false
			},
			response: {
				schema: Joi.array(morphologicaldata)
			},
			description: 'Get the attachment files from the database'
	    }
	});


}
Example #5
0
        .example('2018-10-10T21:35:31Z'),
    username: Joi.string()
        .label('Username')
        .example('d2lam'),
    userProfile: Joi.string()
        .uri()
        .label('Link to Profile')
        .example('https://github.com/anonymous')
}).label('SCM Pull Request');

const SCHEMA_HOOK = Joi.object().keys({
    action: Joi.string()
        .when('type', { is: 'pr',
            then: Joi.valid(['opened', 'reopened', 'closed', 'synchronized']) })
        .when('type', { is: 'repo', then: Joi.valid(['push', 'release', 'tag']) })
        .when('type', { is: 'ping', then: Joi.allow('').optional(), otherwise: Joi.required() })
        .label('Action of the event'),

    branch: Joi.string()
        .when('type', { is: 'ping', then: Joi.allow('').optional(), otherwise: Joi.required() })
        .label('Branch of the repository'),

    checkoutUrl: Joi
        .string().regex(Regex.CHECKOUT_URL)
        .required()
        .label('Checkout URL for the application')
        .example('git@github.com:screwdriver-cd/data-schema.git#master')
        .example('https://github.com/screwdriver-cd/data-schema.git#master'),

    hookId: Joi.string()
        .allow('')
Example #6
0
File: team.js Project: dfrsol/newww
   is: 'updateWritePermissions',
   then: Joi.required()
 }).when('updateType', {
   is: 'removePackage',
   then: Joi.required()
 }).when('updateType', {
   is: 'removeUser',
   then: Joi.required()
 }),
 names: Joi.any().when('updateType', {
   is: 'addPackagesToTeam',
   then: Joi.required()
 }),
 writePermission: Joi.string().when('updateType', {
   is: 'updateWritePermissions',
   then: Joi.allow('on')
 }),
 writePermissions: Joi.object().when('updateType', {
   is: 'addPackagesToTeam',
   then: Joi.required()
 }),
 'team-description': Joi.string().when('updateType', {
   is: 'updateInfo',
   then: Joi.required()
 }),
 member: Joi.any().when('updateType', {
   is: 'addUsersToTeam',
   then: Joi.required()
 }),
 teams: Joi.any().optional(),
 personal: Joi.any().optional()
Example #7
0
'use strict'

const Joi = require('joi')
const serverSecrets = require('../../lib/server-secrets')
const { BaseJsonService } = require('..')
const { isLegacyVersion } = require('./sonar-helpers')

const schema = Joi.object({
  component: Joi.object({
    measures: Joi.array()
      .items(
        Joi.object({
          metric: Joi.string().required(),
          value: Joi.alternatives(
            Joi.number().min(0),
            Joi.allow('OK', 'ERROR')
          ).required(),
        }).required()
      )
      .required(),
  }).required(),
}).required()

const legacyApiSchema = Joi.array()
  .items(
    Joi.object({
      msr: Joi.array()
        .items(
          Joi.object({
            key: Joi.string().required(),
            val: Joi.alternatives(
'use strict'

const Joi = require('joi')
const t = (module.exports = require('../tester').createServiceTester())

const isQualityGateStatus = Joi.allow('passed', 'failed')

t.create('Quality Gate')
  .get('/https/sonarcloud.io/swellaby%3Aazdo-shellcheck/quality_gate.json')
  .expectBadge({
    label: 'quality gate',
    message: isQualityGateStatus,
  })

t.create('Quality Gate (Alert Status)')
  .get(
    '/http/sonar.petalslink.com/org.ow2.petals%3Apetals-se-ase/alert_status.json?sonarVersion=4.2'
  )
  .expectBadge({
    label: 'quality gate',
    message: isQualityGateStatus,
  })