-
-
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
handleCreate().match does not work with ActiveModelSerializer #165
Comments
It's alway nice to try to throw out more hay when trying to find a needle in the haystack. You're making my life difficult by doing stuff like TestHelper.handleCreate('shipment').match({
order: this.pack.get('order'),
shipOrder: true,
shipItems: true,
shippingMethod: this.methods[0],
shippingRef: this.ref,
orderItems: this.pack.get('orderItems'),
}); because I have no idea what is in: this.pack.get('orderItems'), or this.methods[0], or this.pack.get('order'). What I suggest is throwing out hay: just do this: TestHelper.handleCreate('shipment') and see what happens .. forget the match .. and see if it works .. then add one item to match at a time till it fails. That's what I would do. And if still does not work .. your going to have to lay out json so I can see the values .. and not => this.pack.get('orderItems'). speaking of which .. you should not match on belongs to or has many relations .. just attributes |
oops .. did you just say your data looked like this: expectedData == {
order: "1",
orderItems: Array[2],
shipItems: true,
shipOrder: true,
shippingMethod: "1",
shippingRef: "AZE123",
} I think you did .. so sorry about that .. did not mean to say you did not show data .. cause there it is. |
Thanks for taking a look. The no match solution is working and I defaulted to that for now. However the whole point of the form I'm testing is to fill in this data. So not asserting the sent data makes the test way less useful. All associations are serialized as ids so they should work (and it's quite an important data to test in that request). Defaulting the attributes to Object.keys(expectedData) and ObjectKeys(requestData) would work in my case from what I see in the debugger but I don't know enough the code here to say if this would be a valid fix. To complete the data, here is the code of the serializer for this model:
|
Hmm ... good point .. about no match being useless for this case .. I did not mean to suggest it was the end of the game .. just throwing out hay. So you are saying that one field causes error also .. was that an attribute field or an association. |
Any field triggers the same error. Here is everything we have (still on the 1.13 branch, so not too late):
|
I don't think ember-cli-rails should be a problem, but do try to upgrade to factory guy v2.1.3 .. it supports all the way back to ember data 1.13.5 .. you are using pretty old version of FG |
Upgrading to 2.1.3 then prevents the whole test suite to load. I believe due to some ES6 stuff. It's time for us to upgrade our ember-cli version anyway, so I'll come back to you when that's done. |
Upgraded ember, ember-cli and factory guy. It almost fixed my issue. Now I only have it for compound class names For instance if the model file is app/models/foo-bar.js then either I do TestHelper.handleCreate('fooBar').match({a: 1} and it fails with the same error because in https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mock-create-request.js#L79 the modelName ('fooBar') does not match the model name in the request params ('foo_bar') or TestHelper.handleCreate('foo_bar').match({a: 1}) then the match is ok, but it's now failing at https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mock-create-request.js#L106 because definition is empty because the model definition keys are camelCase. I'm not sure what's the right fix. Maybe, it's the factory definition that is not correct. For the compound models I do:
In the meanwhile, the workaround I've found is forcing the id with a andReturn({ id: ...} but it's not very satisfactory Maybe a more robust solution would be to try harder in https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/factory-guy.js#L130 by trying the various options (camelize, underscore, dasherize). If that's ok with you, I'll do a PR. |
I think @gleseur has the right idea, the underlying issue seems to be that this line: https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mocks/mock-create-request.js#L106 is using the I made this change on my branch and it fixed the issue for me: #187 the request of the |
I think v2.6.2 fixed this issue .. let me know if I am wrong and I will fix it ASAP. |
Hi,
I'm using ActiveModelSerializer and I have an issue when using handleCreate.match.
It raises an error https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mock-create-request.js#L81 because expectedData.data is undefined.
I have :
(so you can see there is no data node)
but going through normalize at https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mock-create-request.js#L76 and https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mock-create-request.js#L79 does not add a data node.
The test code is:
I don't think anything in the app is interfering with this.
Is it a workaround to this ? (or maybe I'm not using it right ?)
Thanks
The text was updated successfully, but these errors were encountered: