<commit_before>var Promise = require('bluebird')
var chai = require('chai')
chai.use(require('chai-as-promised'))
var expect = chai.expect
var generateSql = require('../../lib/generateSql')

describe('Generated SQL', function () {
  var challenges
  beforeEach(function () {
    challenges = {
      c1: {id: 1, name: 'c1', description: 'C1', difficulty: 1, category: '1'},
      c2: {id: 2, name: 'c2', description: 'C1', difficulty: 2, category: '2'},
      c3: {id: 3, name: 'c3', description: 'C2', difficulty: 3, category: '2'},
      c4: {id: 4, name: 'c4', description: 'C2', difficulty: 4, category: '3'},
      c5: {id: 5, name: 'c5', description: 'C2', difficulty: 5, category: '1'}
    }
  })

  it('should have DELETE statement prepended when option is chosen', function () {
    return expect(generateSql(challenges, true, false, '')).to.eventually.match(/^delete from challenges;/i)
  })

  it('should not have DELETE statement prepended when option is not chosen', function () {
    return expect(generateSql(challenges, false, false, '')).to.eventually.not.match(/^delete from challenges;/i)
  })

  it('should have SELECT statement appended when option is chosen', function () {
    return expect(generateSql(challenges, false, true, '')).to.eventually.match(/select \* from challenges;\s*$/i)
  })

  it('should not have SELECT statement appended when option not is chosen', function () {
    return expect(generateSql(challenges, false, false, '')).to.eventually.not.match(/select \* from challenges;\s*$/i)
  })

  it('should consist of one INSERT statement per challenge', function () {
    return Promise.all([
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(1.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(2.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(3.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(4.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(5.*;/i)
    ])
  })

  it('should log generator error to console', function () {
    return expect(generateSql({c1: undefined}, false, false, '')).to.be.rejectedWith('Failed to generate SQL statements! TypeError')
  })
})<commit_msg>Add empty challenges {} test<commit_after>var Promise = require('bluebird')
var chai = require('chai')
chai.use(require('chai-as-promised'))
var expect = chai.expect
var generateSql = require('../../lib/generateSql')

describe('Generated SQL', function () {
  var challenges
  beforeEach(function () {
    challenges = {
      c1: {id: 1, name: 'c1', description: 'C1', difficulty: 1, category: '1'},
      c2: {id: 2, name: 'c2', description: 'C1', difficulty: 2, category: '2'},
      c3: {id: 3, name: 'c3', description: 'C2', difficulty: 3, category: '2'},
      c4: {id: 4, name: 'c4', description: 'C2', difficulty: 4, category: '3'},
      c5: {id: 5, name: 'c5', description: 'C2', difficulty: 5, category: '1'}
    }
  })

  it('should have DELETE statement prepended when option is chosen', function () {
    return expect(generateSql(challenges, true, false, '')).to.eventually.match(/^delete from challenges;/i)
  })

  it('should not have DELETE statement prepended when option is not chosen', function () {
    return expect(generateSql(challenges, false, false, '')).to.eventually.not.match(/^delete from challenges;/i)
  })

  it('should have SELECT statement appended when option is chosen', function () {
    return expect(generateSql(challenges, false, true, '')).to.eventually.match(/select \* from challenges;\s*$/i)
  })

  it('should not have SELECT statement appended when option not is chosen', function () {
    return expect(generateSql(challenges, false, false, '')).to.eventually.not.match(/select \* from challenges;\s*$/i)
  })

  it('should consist of one INSERT statement per challenge', function () {
    return Promise.all([
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(1.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(2.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(3.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(4.*;/i),
      expect(generateSql(challenges, false, false, '')).to.eventually.match(/insert into challenges.*values \(5.*;/i)
    ])
  })

  it('should be empty when given no challenges', function () {
    return expect(generateSql({}, false, false, '')).to.eventually.equal('')
  })

  it('should log generator error to console', function () {
    return expect(generateSql({c1: undefined}, false, false, '')).to.be.rejectedWith('Failed to generate SQL statements! TypeError')
  })
})
{'fraction_non_alphanumeric': 0.17472852912142153, 'fraction_numerical': 0.014215202369200396, 'mean_word_length': 4.338250790305585, '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': '791826', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1501, 'n_words': 438}