-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Added tests for Ember Data Model Fragment factory support in unit tests #188
Added tests for Ember Data Model Fragment factory support in unit tests #188
Conversation
a35708d
to
89cfe9c
Compare
This is a great start, so thanks for helping me understand how the model-fragments work. |
hooray .. that worked, so that test now passes |
Boy, if you could now do some acceptance tests I will be your best friend for a whole day. I can't wait to get this thing finished ( for some reason ) .. not sure why though. |
I just pushed that change to model-definition so you can see that |
Great stuff @danielspaniel, I'll add the acceptance tests. Will I keep them here or add them to a separate PR? I probably won't get to it for a day or two though. |
Putting them here is better I reckon @patocallaghan ... so we can wrap it up in one go. |
2798d1b
to
ef47155
Compare
@danielspaniel I've added a single acceptance so far (see 2nd commit) and it's showing a failure due to Also did you push your |
ef47155
to
7e46672
Compare
ok(employee.get('name.lastName') === 'Lannister'); | ||
ok(employee.get('hasDirtyAttributes')); | ||
employee.save(); | ||
ok(!employee.get('hasDirtyAttributes')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielspaniel I've just added this other failing unit test I've been getting. I'm not sure if it's related to model-fragments
or not but if not I'll pull it out to a separate issue if you like.
Basically when doing a mockUpdate
and then doing a save()
the attributes are still dirty (is that expected?). Then test fails with the following error:
Promise rejected after update the employee: Assertion Failed: You can only unload a record which is not inFlight
which I'm presuming happens because the test is trying to clean up but the record is dirty.
Ok @patocallaghan .. I "fixed" up that test so it will not get the inflight errors .. but I moved that mockUpdate tests to the shared-factory-guy-test-helper-tests.js file The test in that file is here => test('with model that has model fragment as the updated field' ... ( line 1450 ) The error I am getting is: I read the docs in model fragments ( there was issue for this ) .. and they suggest setting a serializer for you fragments? I think. Not sure I quite get it. Any ideas? I got tests to pass with this change in fixture-converter.js ( line 31 ) getTransformValueFunction(type) {
if (!this.transformKeys || type.match('-mf')) {
return this.noTransformFn;
} but do people ever want to custom serialize their values? I assumed they would want to value to stay as JSON and not really mess with it, but that might be naive. Anyway .. this is the last sticking point I think before this can be pushed out.. Any ideas? |
@danielspaniel that's great you figured it out. Just have some questions if you don't mind :)
Re: model fragments + JSON API, unfortunately I don't know much about it but from the docs it seems like it definitely is not allowed. It seems by default model fragments bypasses the application serializer (as it could be JSONAPI) and always registers its own based on the |
Looks like I have been pushing to my own branch or your code in factory guy repo .. oops. I will try and fix that JSONAPI thing .. for the tests .. it's a royal pain .. but that was helpful to see the tests you pointed too .. |
Actually .. hold on.. I see the probable issue in the JSONAPI thing. |
I fixed it .. so I will merge that ..and then maybe add another test if you like ? What did you mean with this question: me not understand. |
I release a new version 2.5 that has all our work.. so thanks a ton for helping on this. |
Thanks @danielspaniel this is great! re: my question:
You mention in #188 (comment) above that you moved my original test so that it would have an application serializer. I was just wondering was that something I needed to specifically include in my unit tests when using |
Oh .. right ..good question. |
As discussed in #184 I've added unit tests to test for support of https://github.com/lytics/ember-data-model-fragments. It's not comprehensive but it's a start. Acceptance tests can follow.
I've added an
employee
model which from amodel-fragment
point of view looks like:As
model-fragment
supports polymorphicfragmentArrays
I addedbilling-address
andmailing-address
as well but was unsure how to construct the list using a factory to test it.@danielspaniel anything else you think we should test for?