You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I cannot get my test to pass validation. Even though I'm setting the When() condition to only required the property if a certain condition is met, it's always requiring it. (See infantYouthParentsName property below)
Test:
lab.beforeEach((done)=>{letact={id: '123456789012345',name: undefined,location: undefined,for: undefined,address1: undefined,address2: undefined,baptismAge: undefined,city: undefined,clergyPhoneNumber: undefined,contactOrg: undefined,contact: undefined,country: undefined,dateActPerformed: undefined,dateOfBirth: undefined,infantYouthParentsName: undefined,remarks: undefined,state: undefined,stateOther: undefined,transferDate: undefined,witness1Name: undefined,witness2Name: undefined,zipcode: undefined};done();});lab.test('Name should pass with a valid choice',(done)=>{act.name='Transfer';ValidAct.validateExisting(act).then((val)=>{Code.expect(val).to.equal(act);done();}).catch((err)=>{// child "infantYouthParentsName" fails because ["infantYouthParentsName" is required]done(err);});});
Error:
child "infantYouthParentsName" fails because ["infantYouthParentsName" is required]
Source
'use strict';importBluebirdfrom'bluebird';importJoifrom'joi';let_names=['Baptism','Profession of Faith','Transfer'];let_ages=['Adult','Infant/Youth'];let_countries=['UNITED STATES OF AMERICA','AFGHANISTAN','ALBANIA','ALGERIA','AMERICAN SAMOA','ANDORRA','ANGOLA','ANGUILLA','ANTIGUA & BARBUDA','ARGENTINA','ARMENIA','ARUBA','AUSTRALIA','AUSTRIA','AZERBAIJAN','BAHAMAS','BAHRAIN','BANGLADESH','BARBADOS','BELARUS','BELGIUM','BELIZE','BENIN','BERMUDA','BHUTAN','BOLIVIA','BOSNIA AND HERZEGOVINA','BOTSWANA','BRAZIL','BRITISH VIRGIN ISLANDS','BRUNEI DARUSSALAM','BULGARIA','BURKINA FASO','BURUNDI','CAMBODIA','CAMEROON','CANADA','CAPE VERDE','CAYMAN ISLANDS','CENTRAL AFRICAN REPUBLIC','CHAD','CHANNEL ISLANDS','CHILE','CHINA','COCOS ISLANDS','COLOMBIA','COMOROS','COOK ISLANDS','COSTA RICA','COTE D\'IVOIRE','CROATIA','CUBA','CYPRUS','CZECH REPUBLIC','DEMOCRATIC REPUBLIC OF THE CONGO','DENMARK','DJIBOUTI','DOMINICA','DOMINICAN REPUBLIC','EAST TIMOR','ECUADOR','EGYPT','EL SALVADOR','EQUATORIAL GUINEA','ERITREA','ESTONIA','ETHIOPIA','FALKLAND ISLANDS','FAROE ISLANDS','FIJI','FINLAND','FRANCE','FRENCH GUIANA','FRENCH POLYNESIA','GABON','GAMBIA','GEORGIA','GERMANY','GHANA','GIBRALTAR','GREECE','GREENLAND','GRENADA','GUADELOUPE','GUAM','GUATEMALA','GUIANA, FRENCH','GUINEA','GUINEA-BISSAU','GUYANA','HAITI','HONDURAS','HONG KONG','HUNGARY','ICELAND','INDIA','INDONESIA','IRAN','IRAQ','IRELAND','ISLE OF MAN','ISRAEL','ITALY','JAMAICA','JAPAN','JORDAN','KAZAKHSTAN','KENYA','KIRIBATI','KOSOVO','KUWAIT','KYRGYZSTAN','LAOS','LATVIA','LEBANON','LESOTHO','LIBERIA','LIBYA','LIECHTENSTEIN','LITHUANIA','LUXEMBOURG','MACAO','MACEDONIA','MADAGASCAR','MALAWI','MALAYSIA','MALDIVES','MALI','MALTA','MARSHALL ISLANDS','MARTINIQUE','MAURITANIA','MAURITIUS','MAYOTTE','MEXICO','MICRONESIA','MOLDOVA','MONACO','MONGOLIA','MONTENEGRO','MONTSERRAT','MOROCCO','MOZAMBIQUE','MYANMAR','NAMIBIA','NAURU','NEPAL','NETHERLANDS','NETHERLANDS ANTILLES','NEW CALEDONIA','NEW ZEALAND','NICARAGUA','NIGER','NIGERIA','NORTHERN MARIANA ISLANDS','NORTH KOREA','NORWAY','OMAN','PAKISTAN','PALAU','PALESTINIAN TERRITORY','PANAMA','PAPUA NEW GUINEA','PARAGUAY','PERU','PHILIPPINES','PITCAIRN ISLAND','POLAND','PORTUGAL','PUERTO RICO','QATAR','REPUBLIC OF CONGO','REUNION','ROMANIA','RUSSIAN FEDERATION','RWANDA','SAINT HELENA','SAINT KITTS AND NEVIS','SAINT LUCIA','SAINT MAARTEN','SAINT VINCENT AND THE GRENADINES','SAN MARINO','SAO TOME AND PRINCIPE','SAUDI ARABIA','SENEGAL','SERBIA','SEYCHELLES','SIERRA LEONE','SINGAPORE','SLOVAKIA','SLOVENIA','SOLOMON ISLANDS','SOMALIA','SOUTH AFRICA','SOUTH KOREA','SPAIN','SRI LANKA','SUDAN','SURINAME','SWAZILAND','SWEDEN','SWITZERLAND','SYRIA','TAIWAN','TAJIKISTAN','TANZANIA','THAILAND','TOGO','TONGA','TRINIDAD & TOBAGO','TUNISIA','TURKEY','TURKMENISTAN','TURKS AND CAICOS ISLANDS','TUVALU','UGANDA','UKRAINE','UNITED ARAB EMIRATES','UNITED KINGDOM','UNITED STATES VIRGIN ISLANDS','URUGUAY','UZBEKISTAN','VANUATU','VATICAN CITY','VENEZUELA','VIET NAM','WALLIS AND FUTUNA ISLANDS','WESTERN SAMOA','YEMEN','ZAMBIA','ZIMBABWE','AE','AP','AA','OTHER','N/A'];let_states=['AK','AL','AR','AS','AZ','CA','CO','CT','DC','DE','FL','FM','GA','GU','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MH','MI','MN','MO','MP','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','PR','PW','RI','SC','SD','TN','TX','UT','VA','VI','VT','WA','WI','WV','WY','AB','BC','MB','NB','NL','NT','NS','NU','ON','PE','QC','SK','YT','N/A','Other/Specify'];letmsgContactOrg='Invalid Contact Organization';letmsgContact='Invalid Contact';letmsgId='Invalid Id';letmsgStateOther='Invalid State Other';let_schemaNew=Joi.object().keys({name: Joi.string().valid(_names),location: Joi.string().max(200),for: Joi.string().max(150),address1: Joi.string().max(150),address2: Joi.string().max(150),baptismAge: Joi.any().when('name',{is: 'Baptism',then: Joi.valid(_ages).required(),otherwise: Joi.forbidden()}),city: Joi.string().max(100),clergyPhoneNumber: Joi.string().max(25),contactOrg: Joi.string().min(15).max(15),country: Joi.string().valid(_countries),contact: Joi.string().min(15).max(18),dateActPerformed: Joi.date(),dateOfBirth: Joi.date(),infantYouthParentsName: Joi.string().when('baptismAge',{is: 'Infant/Youth',then: Joi.string().max(150).required(),otherwise: Joi.string().max(150)}),remarks: Joi.string().max(255),state: Joi.string().allow(_states),stateOther: Joi.string().when('state',{is: 'Other/Specify',then: Joi.string().max(100),otherwise: Joi.string().max(100)}),transferDate: Joi.date().when('name',{is: 'Transfer',then: Joi.date()}),witness1Name: Joi.string(),witness2Name: Joi.string().max(150),zipcode: Joi.string().max(25)});let_schemaId=Joi.object().keys({id: Joi.string().min(15).max(18).required()});let_schemaExisting=_schemaNew.concat(_schemaId);exportdefault{validate: Bluebird.promisify(Joi.validate),validateExisting(act){returnthis.validate(act,_schemaExisting);},validateNew(act){returnthis.validate(act,_schemaNew);},validateId(act){returnthis.validate(act,_schemaId);}}
The text was updated successfully, but these errors were encountered:
I cannot get my test to pass validation. Even though I'm setting the When() condition to only required the property if a certain condition is met, it's always requiring it. (See
infantYouthParentsName
property below)Test:
Error:
Source
The text was updated successfully, but these errors were encountered: