bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

schema validation and error message #101

Closed bwgjoseph closed 3 years ago

bwgjoseph commented 3 years ago

Hi,

Just upgraded to beta.2 and ran test, and notice some of the previous test fails. I'm not sure if it happens before beta.1/2.

Basically, I have schema where it has enum but it isn't a required field. When I ran the test, it is expecting me to provide those values.

Something along this line

const airplaneSchema = {
    callsign: {
        type: String,
        required: true,
    },
    size: {
        type: String,
        enum: [
            'S',
            'M',
            'L',
        ],
    },
    type: {
        type: String,
        enum: [
            'ECONOMY',
            'FIRST CLASS',
            'PRIVATE',
        ],
        uppercase: true,
        trim: true,
    },
}

So this is the test case

https://github.com/bwgjoseph/mongoose-vs-ottoman/blob/3a4917a60ff99482631a2742bd497be2a5f5b388/test/ts/errorMsg.test.ts#L31-L53

2 issue

  1. It's not a required field, so the validation should not be triggered
  2. Even if it is triggered, the error message is not consistent
"message": "Property 'name' is required, Property 'capacity' is more than the maximum allowed value of '550', Property 'model' is required, Property size value must be S,M,L, Property type value must be ECONOMY,FIRST CLASS,PRIVATE"

It is similar to the previous issue #72, so you see that Property size value must be S,M,L, where the size is not quoted like the rest

Thanks

AV25242 commented 3 years ago

Will get back to you on this

AV25242 commented 3 years ago

@bwgjoseph this should be fixed with next release

AV25242 commented 3 years ago

v2.0.0-beta.3 released