<commit_before>'use strict';
var request = require('supertest');
var should = require('should');
var RSVP = require('rsvp');

module.exports = function(options){
  describe('should upsert logic', function(){
    var ids, baseUrl;
    beforeEach(function(){
      ids = options.ids;
      baseUrl = options.baseUrl;
    });

    function createDuplicate(){
      return new RSVP.Promise(function(resolve){
        request(baseUrl).post('/people')
          .set('content-type', 'application/json')
          .send(JSON.stringify({
            people: [
              {
                "name": "Dupe",
                "appearances": 987,
                "birthday": "1958-04-02",
                "email": "<EMAIL>",
                upsertTest: 'match'
              }
            ]
          }))
          .expect(201)
          .end(function(err){
            should.not.exist(err);
            resolve();
          });
      });
    }

    function countDupes(){
      return new RSVP.Promise(function(resolve) {
        request(baseUrl).get('/people?filter[upsertTest]=match')
          .end(function (err, res) {
            var body = JSON.parse(res.text);
            resolve(body.people.length);
          });
      });
    }

    it('should not create duplicate user with matching upsert key', function(done){
      createDuplicate().then(function(){
          return createDuplicate();
        }).then(function(){
          return countDupes();
        }).then(function(count){
          count.should.equal(1);
          done();
        })
    });
    it('should not create duplicate user with matching upsert key if creates are running in parallel', function(done){
      RSVP.all([
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate()
      ]).then(function(){
        return countDupes();
      }).then(function(count){
        count.should.equal(1);
        done();
      });
    });
    it.only('should not overwrite embedded documents', function(done){
        request(baseUrl).post('/people')
          .set('content-type', 'application/json')
          .send(JSON.stringify({
            people: [
              {
                "email": "<EMAIL>",
                upsertTest: 'match',
                nested: {<commit_msg>Uncomment tests<commit_after>'use strict';
var request = require('supertest');
var should = require('should');
var RSVP = require('rsvp');

module.exports = function(options){
  describe('should upsert logic', function(){
    var ids, baseUrl;
    beforeEach(function(){
      ids = options.ids;
      baseUrl = options.baseUrl;
    });

    function createDuplicate(){
      return new RSVP.Promise(function(resolve){
        request(baseUrl).post('/people')
          .set('content-type', 'application/json')
          .send(JSON.stringify({
            people: [
              {
                "name": "Dupe",
                "appearances": 987,
                "birthday": "1958-04-02",
                "email": "<EMAIL>",
                upsertTest: 'match'
              }
            ]
          }))
          .expect(201)
          .end(function(err){
            should.not.exist(err);
            resolve();
          });
      });
    }

    function countDupes(){
      return new RSVP.Promise(function(resolve) {
        request(baseUrl).get('/people?filter[upsertTest]=match')
          .end(function (err, res) {
            var body = JSON.parse(res.text);
            resolve(body.people.length);
          });
      });
    }

    it('should not create duplicate user with matching upsert key', function(done){
      createDuplicate().then(function(){
          return createDuplicate();
        }).then(function(){
          return countDupes();
        }).then(function(count){
          count.should.equal(1);
          done();
        })
    });
    it('should not create duplicate user with matching upsert key if creates are running in parallel', function(done){
      RSVP.all([
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate(),
        createDuplicate()
      ]).then(function(){
        return countDupes();
      }).then(function(count){
        count.should.equal(1);
        done();
      });
    });
    it('should not overwrite embedded documents', function(done){
        request(baseUrl).post('/people')
          .set('content-type', 'application/json')
          .send(JSON.stringify({
            people: [
              {
                "email": "<EMAIL>",
                upsertTest: 'match',
                nested: {
{'fraction_non_alphanumeric': 0.14357157741196083, 'fraction_numerical': 0.006668055844967702, 'mean_word_length': 1.8285209192692988, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, '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': '5299165', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1250, 'n_words': 257}