keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.62k stars 2.21k forks source link

[4.0.0-beta.3] Validation of type Name #3722

Open langovoi opened 8 years ago

langovoi commented 8 years ago

Steps to reproduce the behavior

  1. Create list with required field with type Name
  2. Get model and create new item keystone.List(listName).model().save()

Expected behavior

Get validation error

Actual behavior

Item successfully saved

langovoi commented 8 years ago

I think problem is here, because default option always overrides.

vadimshvetsov commented 7 years ago

I have the same issue.

const newUser = {
        name: {
          first: 'Foo',
          last: 'Bar',
        },
        email: 'for@bar.biz',
        password: 'foobar',
      };

it('should reject a new user without name', function (done) {
        const invalidUser = Object.assign({}, newUser);
        delete invalidUser.name;
        new User(invalidUser).validate((err) => {
          assert.equal('Path `name` is required.', err.errors.name.message);
          done();
        });
      });

I have field with type.Name as required in model, but it's able to add item without name in DB. Error is null here. For complete overview - the email validation isn't work too for me at this moment in unit tests.