<commit_before>/**
 * <%= modelName %> API Tests
 *
 * Tests the connectivity & responses of 
 * Discovery API for the <%= modelName %> Object
 */

var request = require('supertest');
var should  = require('chai').should();

describe('<%= modelName %> API', function() {
  var sessionCookie;

  before(function(done) {
    request(sails.hooks.http.app)
      .post('/auth/local')
      .send({
        identifier : '<EMAIL>',
        password   : "<PASSWORD>"
      })
      .end(function(err, res){
        sessionCookie = res.headers['set-cookie'];
        done();
      });
  });

  
  it('should create a model', function(done) {
    request(sails.hooks.http.app)
      .post('/<%= pluralModelName %>')
      .set('cookie', sessionCookie)
      .send({
        <%= camelModelName %> : {
          // insert attributes
          // name : 'Test Name'
        }
      })
      .expect(201)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        // reply.<%= camelModelName %>.name.should.equal('Test Name');

        <%= modelName %>.findOne(reply.<%= camelModelName %>.id, function(err, result) {
          should.not.exist(err);
          should.exist(result);
          // result.name.should.equal('Test Name');
          done();
        });
      });
  });
  
  it('should find all models', function(done) {
    request(sails.hooks.http.app)
      .get('/<%= pluralModelName %>')
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        reply.<%= camelModelName %>.length.should.be.above(0);
        done();
      });
  });
  
  it('should find a model', function(done) {
    request(sails.hooks.http.app)
      .get('/<%= pluralModelName %>/1')
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        reply.<%= camelModelName %>.id.should.equal(1);
        done();
      });
  });
  
  it('should update a model', function(done) {
    request(sails.hooks.http.app)
      .put('/<%= pluralModelName %>/1')
      .set('cookie', sessionCookie)
      .send({
        <%= camelModelName %> : {
          // insert attribute(s)
          // name: 'NEW'
        }
      })
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        // reply.<%= camelModelName %>.name.should.equal('NEW');

        <%= modelName %>.findOne(1, function(err, result) {
          should.not.exist(err);
          should.exist(result);
          // result.name.should.equal('NEW');
          done();
        });
      });
  });
  
  it('should delete a model', function(done) {
    request(sails.hooks.http.app)
      .delete('/<%= pluralModelName %>/1')
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        should.not.exist(err);
        (res.body || {}).should.be.empty;

        <%= modelName %>.findOne(1, function(err, result) {
          should.not.exist(err);
          should.not.exist(result);
          done();
        });
      });
  });

});

<commit_msg>base off createdModel instead of hard id of 1<commit_after>/**
 * <%= modelName %> API Tests
 *
 * Tests the connectivity & responses of 
 * Discovery API for the <%= modelName %> Object
 */

var request = require('supertest');
var should  = require('chai').should();

describe('<%= modelName %> API', function() {
  var sessionCookie;
  var createdModel;

  before(function(done) {
    request(sails.hooks.http.app)
      .post('/auth/local')
      .send({
        identifier : '<EMAIL>',
        password   : "<PASSWORD>"
      })
      .end(function(err, res){
        sessionCookie = res.headers['set-cookie'];
        done();
      });
  });

  
  it('should create a model', function(done) {
    request(sails.hooks.http.app)
      .post('/<%= pluralModelName %>')
      .set('cookie', sessionCookie)
      .send({
        <%= camelModelName %> : {
          // insert attributes
          // name : '<NAME>'
        }
      })
      .expect(201)
      .end(function(err, res) {
        var reply = res.body;
        createdModel = reply.<%= camelModelName %>
        should.not.exist(err);
        // reply.<%= camelModelName %>.name.should.equal('Test Name');

        <%= modelName %>.findOne(createdModel.id, function(err, result) {
          should.not.exist(err);
          should.exist(result);
          // result.name.should.equal('Test Name');
          done();
        });
      });
  });
  
  it('should find all models', function(done) {
    request(sails.hooks.http.app)
      .get('/<%= pluralModelName %>')
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        reply.<%= camelModelName %>.length.should.be.above(0);
        done();
      });
  });
  
  it('should find a model', function(done) {
    request(sails.hooks.http.app)
      .get('/<%= pluralModelName %>/'+createdModel.id)
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        reply.<%= camelModelName %>.id.should.equal(createdModel.id);
        done();
      });
  });
  
  it('should update a model', function(done) {
    request(sails.hooks.http.app)
      .put('/<%= pluralModelName %>/'+createdModel.id)
      .set('cookie', sessionCookie)
      .send({
        <%= camelModelName %> : {
          // insert attribute(s)
          // name: 'NEW'
        }
      })
      .expect(200)
      .end(function(err, res) {
        var reply = res.body;
        should.not.exist(err);
        // reply.<%= camelModelName %>.name.should.equal('NEW');

        <%= modelName %>.findOne(createdModel.id, function(err, result) {
          should.not.exist(err);
          should.exist(result);
          // result.name.should.equal('NEW');
          done();
        });
      });
  });
  
  it('should delete a model', function(done) {
    request(sails.hooks.http.app)
      .delete('/<%= pluralModelName %>/'+createdModel.id)
      .set('cookie', sessionCookie)
      .expect(200)
      .end(function(err, res) {
        should.not.exist(err);
        (res.body || {}).should.be.empty;

        <%= modelName %>.findOne(createdModel.id, function(err, result) {
          should.not.exist(err);
          should.not.exist(result);
          done();
        });
      });
  });

});


{'fraction_non_alphanumeric': 0.18307926829268292, 'fraction_numerical': 0.005945121951219512, 'mean_word_length': 2.0332871012482663, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, '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': '2989654', 'n_tokens_mistral': 2137, 'n_tokens_neox': 2039, 'n_words': 372}