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

.match() for mockUpdate() #216

Closed
cristinawithout opened this issue Jul 6, 2016 · 10 comments
Closed

.match() for mockUpdate() #216

cristinawithout opened this issue Jul 6, 2016 · 10 comments

Comments

@cristinawithout
Copy link
Contributor

I don't see a way to verify the data sent to my endpoint on update is correct as I can with mockCreate().match()

@danielspaniel
Copy link
Collaborator

err .. um .. well .. let's see, I am digging through my thoughts for this one, and the answer is?
no found
oh well ..
not sure why I never did that .. is that something nice to have ..
I just never thought of it
since I usually set stuff and update it and only care about returning extra attrs but never checking that the attrs I am sending are this way or that

but you know, it's not a bad idea

might be easy to do

you want to take a shot at it?
maybe give me example of what you want to do so I can be 100% certain I don't mess it up.

@cristinawithout
Copy link
Contributor Author

I'll see if I can make a PR with at least some tests.

cristinawithout added a commit to cristinawithout/ember-data-factory-guy that referenced this issue Jul 6, 2016
cristinawithout added a commit to cristinawithout/ember-data-factory-guy that referenced this issue Jul 7, 2016
@danielspaniel
Copy link
Collaborator

v2.7.0-beta.10 has this ability

@danielspaniel
Copy link
Collaborator

danielspaniel commented Jul 12, 2016

@cristinawithout => side note. I thought this was a pretty silly feature at first, and lo and behold as soon as I finished it, I used it right away 👍

seems to happen every time I get a feature request. I kind of think ( who would ever need that ). Then it ends up being me using it pretty much the next day.

In fact I even wrote up something in Tips and Tricks because of this very feature

@cristinawithout
Copy link
Contributor Author

👍 Nice. I'm using it along with mockJack's throwUnmocked:true in acceptance tests to make sure A. all the form inputs are hooked up to the buffered model (our own implementation similar to buffered proxy - but handles relationships) B. the values in the buffered model transfer to the model on save C. The values are serializing as expected.

Using match(), I can make sure all of those things are working. Without it, the update would return success, and the test would pass even if the the model wasn't connected to the inputs and/or the serializer was returning nothing.

An update acceptance test where I'm using it is basically like this:

test('can update entry type', function(assert) {
    mockFindAll('section', 5);
    mockFindAll('entry-type', [{
        id: '100',
        name: 'My Entry Type',
        handle: 'my_entry_type',
        section: {
            id: '5',
            type: 'section',
        }
    }]);
    let mock = mockUpdate('entry-type', 100)
        .match({
            name: 'New Name',
            handle: 'new_name',
            section: {id: '1', type: 'section'}
        });

    visit('/entry-types/100/update');

    // Edit the name, handle and section relationship.
    fillIn('[data-test=et-name] input', 'New Name');
    fillIn('[data-test=et-handle] input', 'new_name');
    click('[data-test=et-section] .chosen-container'); // (uses Chosen plugin)
    click('[data-test=et-section] .chosen-container .chosen-results li:eq(0)');

    // Submit form
    click('button[type=submit]');

    andThen(function() {
        // Check for errors rendered when the response fails. 
       // If values don't match, it'll come back with an error because throwUnmocked is true.
        assert.equal(find('.alert-danger').length, 0, 'Should not have error alert');
         // Make sure the mock was called.
        assert.equal(mock.timesCalled, 1);
    });
});

@mdentremont
Copy link
Contributor

@danielspaniel Does this work for mockCreate as well, or just mockUpdate (+ mockFind, etc)?

@danielspaniel
Copy link
Collaborator

@mdentremont: only mockUpdate and mockCreate has the concept of match attributes.
Don't think it would be possible with mockFind or the GET calls because there are no attributes being passed. Only parameters ( if any ) ..

@mdentremont
Copy link
Contributor

@danielspaniel Sorry, I was referring to the timesCalled - I thought when it is was first introduced it wasn't available via mockCreate

@danielspaniel
Copy link
Collaborator

Oops .. yes, timesCalled is available to all the mocks .. and your right .. it was not available to mockCreate until I refactored it to use the same base class at all requests

@mdentremont
Copy link
Contributor

@danielspaniel Awesome, that is great news!

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

No branches or pull requests

3 participants