Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#203 support nullable nested objects #219

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aloysb
Copy link

@aloysb aloysb commented May 22, 2022

This is regarding issue #203

I have extended the existing ModelValueType and the function isModelValueType to allow for object type.

I also added a new test case covering the scenario described in #203 .

It was indeed failing at the beginning, the object would be null no matter whether or not you passed to create an existing object.
This was caused by isModelValueType that would return false if the object was not a Primitive or an Array of Primitives.

The test is now passing, and I've also tested it manually.

Note that this is my PR for this project and unfortunately the tests were not all green out of the box. So I manually checked where these functions/types were used to ensure I didn't break existing functionalities.

Please don't hesitate to let me know if anything needs to be changed.

Aloys Berger added 6 commits May 22, 2022 12:56
…using exisiting type AnyObject

Change the definition of ModelValueType from 'Object' to 'AnyObject' (an existing type of the
library)

re 203
when using nullable<MyObject>( ... ), it is impossible to provide an object. It returns 'null' no
matter whether an object has been provided or not.

re 203
node 'node_modules/.bin/jest' '/Users/aloysberger/FOSS/data/test/model/create.test.ts' -c
'/Users/aloysberger/FOSS/data/test/jest.config.ts' -t 'supports nested nullable object' --runInBand

re mswjs#203
…bjects

Update tests to cover nested nullable objects

re mswjs#203
return (
isPrimitiveValueType(value) ||
Array.isArray(value) ||
typeof value === 'object'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this is too permissive?

@JasonShin
Copy link

Nice one, can we get it merged?

@roertbb
Copy link
Contributor

roertbb commented Jul 3, 2022

Hi there! 👋 I've also tried to tackle that one. I think that there may be some parts missing, when for example we'd like to have some default value for nullable object property

const db = factory({
  user: {
    id: primaryKey(faker.datatype.uuid),
    address: nullable(() => ({
      street: () => "Wall Street",
      number: nullable<number>(() => null),
    })),
  },
});

const user = db.user.create();

we may want to have something like

{
    "id": "...",
    "address": {
        "street": "Wall Street",
        "number": null
    }
}

for user, right?

Also, if you run all tests, you may see that there are some issues with types in test/query/pagination.test.ts.

I created #231 with some investigation I've made some time ago and finished today. Maybe you could take a look there, because you're familiar with the problem and we could figure out some working solution together?

@aloysb
Copy link
Author

aloysb commented Aug 18, 2022

Hi @roertbb, sorry I was quite busy, I'll have a look at your code and get back to you ASAP 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants