<commit_before>const should = require('should')
const check = require('../assets/check.js')
const sinon = require('sinon')

function makeMock(result){
  return class MockApi{
    getUpdates(){
      return {result}
    }
  }
}

describe('check', () => {
  const jsonConfigStub = sinon.stub().returns({source: {}, version: null})

  it('should return a rejected promise if the conf is missing or not valid', done => {
    const main = check(sinon.spy())

    main()
      .then(done, ()=>done())
  })

  it('should return an empty list in case of no message available', async () =>{
    const main = check(jsonConfigStub, makeMock([]))
    const res = await main()

    return should(res).be.eql([])
  })

  it('should return an upadte for each message available', async ()=>{
    const main = check(jsonConfigStub, makeMock([{
      message: {text: 'hi'}, update_id: 42
    }]))
    const res = await main()

    return should(res).be.eql([{update_id: '42'}])
  })

  describe('with a filter defined', ()=>{
    const jsonConfigStub = sinon.stub().returns({source: {filter: "not_hi"}, version: null})
    it('should filter out messages not matching the regex',  async ()=>{
      const main = check(jsonConfigStub, makeMock([
        {message: {text: 'hi'}, update_id: 42},
        {message: {text: 'not_hi'}, update_id: 43},
      ]))
      const res = await main()

      return should(res).be.eql([{update_id: '43'}])
    })

    it('should filter out messages not matching the regex, even all of them',  async ()=>{
      const main = check(jsonConfigStub, makeMock([
        {message: {text: 'hi'}, update_id: 42},
      ]))
      const res = await main()

      return should(res).be.eql([])
    })
  })

})<commit_msg>more tests<commit_after>const should = require('should')
const check = require('../assets/check.js')
const sinon = require('sinon')

function makeMock(result){
  return class MockApi{
    getUpdates(){
      return {result}
    }
  }
}

describe('check', () => {
  const jsonConfigStub = sinon.stub().returns({source: {}, version: null})

  it('should return a rejected promise if the conf is missing or not valid', done => {
    const main = check(sinon.spy())

    main().then(done, ()=>done())
  })

  describe('with a valid configuration', ()=>{
    it('returns an empty list in case of no message available', async () =>{
      const main = check(jsonConfigStub, makeMock([]))
      const res = await main()

      return should(res).be.eql([])
    })

    it('returns an update for each message available', async ()=>{
      const main = check(jsonConfigStub, makeMock([{
        message: {text: 'hi'}, update_id: 42
      }]))
      const res = await main()

      return should(res).be.eql([{update_id: '42'}])
    })

  })

  describe('with a filter defined', ()=>{
    const jsonConfigStub = sinon.stub().returns({source: {filter: "not_hi"}, version: null})
    it('filters out messages not matching the regex',  async ()=>{
      const main = check(jsonConfigStub, makeMock([
        {message: {text: 'hi'}, update_id: 42},
        {message: {text: 'not_hi'}, update_id: 43},
      ]))
      const res = await main()

      return should(res).be.eql([{update_id: '43'}])
    })

    it('filters out messages not matching the regex, even all of them',  async ()=>{
      const main = check(jsonConfigStub, makeMock([
        {message: {text: 'hi'}, update_id: 42},
      ]))
      const res = await main()

      return should(res).be.eql([])
    })
  })
})
{'fraction_non_alphanumeric': 0.1686712485681558, 'fraction_numerical': 0.006872852233676976, 'mean_word_length': 3.163289630512515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '3700116', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1082, 'n_words': 318}