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

Store empty after using makeList #147

Closed
jrm2k6 opened this issue Nov 2, 2015 · 12 comments
Closed

Store empty after using makeList #147

jrm2k6 opened this issue Nov 2, 2015 · 12 comments

Comments

@jrm2k6
Copy link

jrm2k6 commented Nov 2, 2015

Hi,

I have few factories that I use to populate items for my application store.

    var section1 = makeList('section', 1);
    var question1 = makeList('question', 1, {section: section1});
    var question2 = makeList('question', 1, {section: section1});
    var question3 = makeList('question', 1, {section: section1});

The controller method I want to unit test use the store to find a specific question and verify some properties on it.

I understood that makeList would create a model item and push it to the store. Neverthless I can see that my store is empty and always returns 'no model found for 'modelName'.
What am I missing here?

@danielspaniel
Copy link
Collaborator

well looks like you want to do this:

var section1 = make('section', 1);
var questions = makeList('question', 3, {section: section1});

or this:

var section1 = make('section', 1);
var question1 = make('question', {section: section1});
var question2 = make('question', {section: section1});
var question3 = make('question', {section: section1});

@danielspaniel
Copy link
Collaborator

do you see what you were doing that was a bit off?

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

I do. Updating my tests and will check if the store contains my items.

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

Alright, so here is my factories:

import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('section', {
    sequences: {
        sectionName: function(num) {
            return 'Section name' + num;
        },
        sectionPosition: function(num) {
            return 'Section position ' + num;
        }
    },

    default: {
        name: FactoryGuy.generate('sectionName'),
        position: FactoryGuy.generate('sectionPosition')
    }
});
import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('question', {
    sequences: {
        questionBody: function(num) {
            return 'body ' + num;
        },
        questionOrder: function(num) {
            return num;
        }
    },
    default: {
        body: FactoryGuy.generate('questionBody'),
        header: 'header',
        order: FactoryGuy.generate('questionOrder')
    }
});
    // given
    var controller = this.subject();
    var section1 = make('section');
    var question1 = make('question', {section: section1});
    var question2 = make('question', {section: section1});
    var question3 = make('question', {section: section1});

I still have the error about no model found for question.
My controller method is only returning this.store.peekAll('question')

@danielspaniel
Copy link
Collaborator

what do you get for

var question1 = make('question', {section: section1});
console.log(question1+'')

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

<patient-frontend@model:question::ember352:1> which seems to be fine.

Is there anything I need to specify to make sure it is pushed to the store?

@danielspaniel
Copy link
Collaborator

so it's making the questions .. but the controller must not be picking up the property change .. since its not a property .. might it be returning the peekAll results BEFORE you make the questions?

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

No, I explicitly call the method under test after setting up the questions. Is there some asynchronous work here?

@danielspaniel
Copy link
Collaborator

not with make and makeList .. but maybe I would have to see your whole setup .. your missing something

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

import { moduleFor, test } from 'ember-qunit';
import { make } from 'ember-data-factory-guy';
import startApp from '../../../helpers/start-app';
import sinon from 'sinon';

var App = null;

moduleFor('controller:signup.how-it-works', {
      needs: ['service:metrics'],
      beforeEach: function() {
          App = startApp();
      },
      afterEach: function() {
          Ember.run(App, 'destroy');
      }
});

test('action finding ordered last question answered returns last question if conditions are respected ', function(assert) {
    // given
    var section1 = make('section');
    var question1 = make('question', {section: section1});
    var question2 = make('question', {section: section1});
    var question3 = make('question', {section: section1});

    var controller = this.subject();
    // when
    var order = controller.findConditions();

    // then
    assert.equal(order, 1);

});
export default Ember.Controller.extend({
    findConditions: function() {
        let conditions = this.store.peekAll('question');
    }
});
"dependencies": {
    "ember": "2.0.2",
    "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.4",
    "ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
    "ember-data": "2.0.0",
    "ember-load-initializers": "ember-cli/ember-load-initializers#0.1.6",
    "ember-qunit": "0.4.9",
    "ember-qunit-notifications": "0.0.7",
    "ember-resolver": "~0.1.18",
    "jquery": "^1.11.3",
    "loader.js": "ember-cli/loader.js#3.2.1",
    "qunit": "~1.18.0",
    "ember-uploader": "0.3.9",
    "moment": ">= 2.8.0",
    "jquery.inputmask": "3.1.49",
    "bootstrap-datepicker": "~1.4.1",
    "sinonjs": "~1.14.1",
    "fastclick": "~1.0.6",
    "moment-timezone": ">= 0.1.0"
  },

@danielspaniel
Copy link
Collaborator

    // given
    var section1 = make('section');
    var question1 = make('question', {section: section1});
    var question2 = make('question', {section: section1});
    var question3 = make('question', {section: section1});

var controller = this.subject();
// when
var order = controller.findOrderQuestionLastQuestionAnswered();

// then
assert.equal(order, 1);


});
export default Ember.Controller.extend({
findOrderQuestionLastQuestionAnswered: function() {
        return this.store.peekAll('question');
}
});

is this what you meant to do?
this code is kinda confusing .. maybe I need a strong drink .. but I don't get why you calling:

controller.findConditions();

when that method not on the contoller and then the other method ( findOrderQuestionLastQuestionAnswered ) never returned anything .. strange

@jrm2k6
Copy link
Author

jrm2k6 commented Nov 2, 2015

Yes I actually edited the names to make it simpler. Both are now named findConditions.

@jrm2k6 jrm2k6 closed this as completed Mar 25, 2016
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

2 participants