<commit_before>import assert from 'assert'
import sinon from 'sinon'
import { Settings } from 'model/settings'
import SettingsStore from 'db/settings'
import { NotFoundError } from 'utils/errors'

describe('Settings', () => {
  describe('vaildateURL', () => {
    it('should return true if the URL is valid', async () => {
      const settings = new Settings()
      const urls = ['https://example.com', 'http://example.com', 'example.com', 'https://example.com/test']
      urls.forEach(url => {
        assert(settings.validateURL(url))
      })
    })

    it('should return false if the URL is invalid', async () => {
      const settings = new Settings()
      const urls = ['https://', '', 'https://example']
      urls.forEach(url => {
        assert(!settings.validateURL(url))
      })
    })
  })

  describe('getServiceName', () => {
    afterEach(() => {
      SettingsStore.prototype.get.restore()
    })

    it('should return one component', async () => {
      const expected = 'value'
      sinon.stub(SettingsStore.prototype, 'get').returns(expected)

      const actual = await new Settings().getServiceName()
      assert(actual === expected)
    })

    it('should return empty string when matched no component', async () => {
      sinon.stub(SettingsStore.prototype, 'get').throws(new NotFoundError())
      const actual = await new Settings().getServiceName()
      assert(actual === '')
    })

    it('should throw error when error returned', async () => {
      sinon.stub(SettingsStore.prototype, 'get').throws(new Error())
      let error
      try {
        await new Settings().getServiceName()
      } catch (e) {
        error = e
      }
      assert(error.name === 'Error')
    })
  })

  describe('setServiceName', () => {
    afterEach(() => {
      SettingsStore.prototype.update.restore()
    })

    it('should return one component', async () => {
      const expected = 'value'
      sinon.stub(SettingsStore.prototype, 'update').returns(expected)

      const actual = await new Settings().setServiceName(expected)
      assert(actual === expected)
    })

    it('should throw error when error returned', async () => {
      sinon.stub(SettingsStore.prototype, 'update').throws(new Error())
      let error
      try {
        await new Settings().setServiceName('')
      } catch (e) {
        error = e
      }
      assert(error.name === 'Error')
    })
  })
})<commit_msg>Fix lambda test<commit_after>import assert from 'assert'
import sinon from 'sinon'
import { Settings } from 'model/settings'
import SettingsStore from 'db/settings'
import { NotFoundError } from 'utils/errors'

describe('Settings', () => {
  describe('vaildateURL', () => {
    it('should return true if the URL is valid', async () => {
      const settings = new Settings()
      const urls = ['https://example.com', 'http://example.com', 'example.com', 'https://example.com/test']
      urls.forEach(url => {
        assert(settings.validateURL(url))
      })
    })

    it('should return false if the URL is invalid', async () => {
      const settings = new Settings()
      const urls = ['https://', '', 'https://example']
      urls.forEach(url => {
        assert(!settings.validateURL(url))
      })
    })
  })

  describe('getServiceName', () => {
    afterEach(() => {
      SettingsStore.prototype.get.restore()
    })

    it('should return one component', async () => {
      const expected = 'value'
      sinon.stub(SettingsStore.prototype, 'get').returns(expected)

      const actual = await new Settings().getServiceName()
      assert(actual === expected)
    })

    it('should return empty string when matched no component', async () => {
      sinon.stub(SettingsStore.prototype, 'get').throws(new NotFoundError())
      const actual = await new Settings().getServiceName()
      assert(actual === '')
    })

    it('should throw error when error returned', async () => {
      sinon.stub(SettingsStore.prototype, 'get').throws(new Error())
      let error
      try {
        await new Settings().getServiceName()
      } catch (e) {
        error = e
      }
      assert(error.name === 'Error')
    })
  })

  describe('setServiceName', () => {
    afterEach(() => {
      SettingsStore.prototype.update.restore()
    })

    it('should update the service name and user pool', async () => {
      const expected = 'value'
      const updateStub = sinon.stub(SettingsStore.prototype, 'update')
      updateStub.returns(expected)
      const updateUserPoolStub = sinon.stub(Settings.prototype, 'updateUserPool')

      await new Settings().setServiceName(expected)
      assert(updateStub.called)
      assert(updateUserPoolStub.called)
      Settings.prototype.updateUserPool.restore()
    })

    it('should throw error when error returned', async () => {
      sinon.stub(SettingsStore.prototype, 'update').throws(new Error())
      let error
      try {
        await new Settings().setServiceName('')
      } catch (e) {
        error = e
      }
      assert(error.name === 'Error')
    })
  })
})
{'fraction_non_alphanumeric': 0.1541204437400951, 'fraction_numerical': 0.0, 'mean_word_length': 2.8134441087613293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 8, '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': '1870605', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1411, 'n_words': 340}