<commit_before>var assert = require("assert")
require('../src/parse-mockdb');
var Parse = require('parse').Parse;

var Brand = Parse.Object.extend("Brand");
var Item = Parse.Object.extend("Item");
var Store = Parse.Object.extend("Store");

function createBrandP(name) {
  var brand = new Brand();
  brand.set("name", name);
  return brand.save();
}

function createItemP(price, brand) {
  var item = new Item();
  item.set("price", price);

  if (brand) {
    item.set("brand", brand);
  }
  return item.save();
}

function createStoreWithItemP(item) {
  var store = new Store();
  store.set("item", item);
  return store.save();
}

function itemQueryP(price) {
  var query = new Parse.Query(Item);
  query.equalTo("price", price);
  return query.find();
}

describe('ParseMock', function(){
  beforeEach(function() {
    Parse.MockDB.mockDB();
  });

  afterEach(function() {
    Parse.MockDB.cleanUp();
  });

  it("should save correctly", function(done) {
    createItemP(30).then(function(item) {
      assert(item.get("price") == 30);
      done();
    });
  });

  it("should match a correct equalTo query on price", function(done) {
    createItemP(30).then(function(item) {
      itemQueryP(30).then(function(results) {
        assert(results[0].id == item.id);
        assert(results[0].get("price") == item.get("price"));
        done();
      });
    });
  });

  it('should save and find an item', function (done) {
    var Item = Parse.Object.extend("Item");
    var item = new Item();
    item.set("price", 30);
    item.save().then(function(item) {
      var query = new Parse.Query(Item);
      query.equalTo("price", 30);
      return query.find().then(function(items) {
        assert(items[0].get("price") == 30);
        done();
      });
    });
  });

  it("should correctly computed nested includes", function(done) {
    createBrandP("Acme").then(function(brand) {
      createItemP(30, brand).then(function(item) {
        var brand = item.get("brand");
        createStoreWithItemP(item).then(function(savedStore) {
          var query = new Parse.Query(Store);<commit_msg>get() and first() tests<commit_after>var assert = require("assert")
require('../src/parse-mockdb');
var Parse = require('parse').Parse;

var Brand = Parse.Object.extend("Brand");
var Item = Parse.Object.extend("Item");
var Store = Parse.Object.extend("Store");

function createBrandP(name) {
  var brand = new Brand();
  brand.set("name", name);
  return brand.save();
}

function createItemP(price, brand) {
  var item = new Item();
  item.set("price", price);

  if (brand) {
    item.set("brand", brand);
  }
  return item.save();
}

function createStoreWithItemP(item) {
  var store = new Store();
  store.set("item", item);
  return store.save();
}

function itemQueryP(price) {
  var query = new Parse.Query(Item);
  query.equalTo("price", price);
  return query.find();
}

describe('ParseMock', function(){
  beforeEach(function() {
    Parse.MockDB.mockDB();
  });

  afterEach(function() {
    Parse.MockDB.cleanUp();
  });

  it("should save correctly", function(done) {
    createItemP(30).then(function(item) {
      assert(item.get("price") == 30);
      done();
    });
  });

  it("should get a specific ID correctly", function(done) {
    createItemP(30).then(function(item) {
      var query = new Parse.Query(Item);
      query.get(item.id).then(function(fetchedItem) {
        assert(fetchedItem.id == item.id);
        done();
      });
    });
  });

  it("should match a correct equalTo query on price", function(done) {
    createItemP(30).then(function(item) {
      itemQueryP(30).then(function(results) {
        assert(results[0].id == item.id);
        assert(results[0].get("price") == item.get("price"));
        done();
      });
    });
  });

  it('should save and find an item', function (done) {
    var Item = Parse.Object.extend("Item");
    var item = new Item();
    item.set("price", 30);
    item.save().then(function(item) {
      var query = new Parse.Query(Item);
      query.equalTo("price", 30);
      return query.find().then(function(items) {
        assert(items[0].get("price") == 30);
        done();
      });
    });
  });

  it('should save 2 items and get one for a first() query', function (done) {
    Parse.Promise.when([createItemP(30), createItemP(20)]).then(function(item1, item2) {
      var query = new Parse.Query(Item);
      return query.first().then(function(item) {
        assert(item.get("price") == 30);
        done();
      });
    });
  });

  it("should correctly computed nested includes", function(done) {
    createBrandP("Acme").then(function(brand) {
      createItemP(30, brand).then(function(item) {
        var brand = item.get("brand");
        createStoreWithItemP(item).then(function(savedStore) {
          var query = new Parse.Query(Store);
{'fraction_non_alphanumeric': 0.18144159072079535, 'fraction_numerical': 0.010149130074565037, 'mean_word_length': 3.3465346534653464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544504', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1522, 'n_words': 317}