How to use the ember-data-factory-guy.mockCreate function in ember-data-factory-guy

To help you get started, we’ve selected a few ember-data-factory-guy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(() => {
      let done = assert.async();

      let mock = mockCreate('profile').match({description: 'correct description'});

      FactoryGuy.store.createRecord('profile', {description: 'wrong description'}).save()
                .catch(() => {
                  assert.ok(true);
                  // our mock was NOT called
                  assert.equal(mock.timesCalled, 0);
                  done();
                });
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
      let mock1 = mockCreate('profile'),
          mock2 = mockCreate('profile');

      mock1.match(function() {
        assert.ok(true, 'matching function is called');
        return false;
      });

      await FactoryGuy.store.createRecord('profile').save();

      assert.equal(mock1.timesCalled, 0);
      assert.equal(mock2.timesCalled, 1);
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
        let company   = build('company'),
            comitBook = FactoryGuy.store.createRecord('comic-book');

        mockCreate('comic-book').returns({attrs: {company}});

        await comitBook.save();

        assert.equal(comitBook.get('company.id'), company.get('id').toString());
        assert.equal(comitBook.get('company.name'), company.get('name').toString());
      });
    });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
store.query('user', {name: 'Bob'}).then(function(users) {
        assert.equal(users.get('length'), 0);

        mockCreate('user', {name: 'Bob'});
        store.createRecord('user', {name: 'Bob'}).save().then(function(user) {

          bobQueryHander.returns({models: [user]});

          store.query('user', {name: 'Bob'}).then(function(users) {
            assert.equal(users.get('length'), 1);
            done();
          });
        });
      });
    });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
      let description          = "special description",
          camelCaseDescription = "special camelcase description",
          profile              = makeNew('profile', {description, camelCaseDescription});

      mockCreate(profile).match({camelCaseDescription, description});
      await profile.save();

      assert.ok(!profile.get('isNew'), 'Profile is saved');
      assert.deepEqual(
        profile.getProperties(['description', 'camelCaseDescription']),
        {camelCaseDescription, description},
        'correct model attributes present'
      );
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
      let mock = mockCreate('profile');

      mock.match(function() {
        assert.ok(true, 'matching function is called');
        return true;
      });

      await FactoryGuy.store.createRecord('profile').save();

      assert.equal(mock.timesCalled, 1);
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
      let customName = "special name";

      mockCreate('super-hero').match({name: customName});

      assert.ok(FactoryGuy.store.peekAll('super-hero').get('content.length') === 0);

      let hero = FactoryGuy.store.createRecord('super-hero', {name: customName});
      await hero.save();

      assert.ok(FactoryGuy.store.peekAll('super-hero').get('content.length') === 1, 'No extra records created');
      assert.ok(hero instanceof SuperHero, 'Creates the correct type of record');
      assert.ok(hero.get('name') === customName, 'Passes along the match attributes');
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
        let outfits = buildList('outfit', 2),
            hero    = FactoryGuy.store.createRecord('super-hero');

        mockCreate('super-hero').returns({attrs: {outfits}});

        await hero.save();

        assert.deepEqual(hero.get('outfits').mapBy('id'), ['1', '2']);
        assert.deepEqual(hero.get('outfits').mapBy('name'), ['Outfit-1', 'Outfit-2']);
      });
    });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
      let mock1 = mockCreate('profile'),
          mock2 = mockCreate('profile');

      mock1.match(function() {
        assert.ok(true, 'matching function is called');
        return false;
      });

      await FactoryGuy.store.createRecord('profile').save();

      assert.equal(mock1.timesCalled, 0);
      assert.equal(mock2.timesCalled, 1);
    });
  });
github danielspaniel / ember-data-factory-guy / tests / unit / shared-adapter-behaviour.js View on Github external
run(async () => {
        let person = build('super-hero'),
            outfit = FactoryGuy.store.createRecord('outfit');

        mockCreate('outfit').returns({attrs: {person}});

        await outfit.save()

        assert.equal(outfit.get('person.id'), person.get('id').toString());
        assert.equal(outfit.get('person.name'), person.get('name'));
      });
    });