<commit_before>/**
 * Test case for sequelizeDriver.
 * Runs with mocha.
 */
'use strict'

const SequelizeDriver = require('../lib/sequelize_driver.js')
const clayDriverTests = require('clay-driver-tests')
const clayLump = require('clay-lump')
const {EOL} = require('os')
const {ok, equal, deepEqual, strictEqual} = require('assert')
const path = require('path')
const {exec} = require('child_process')
const fs = require('fs')
const asleep = require('asleep')
const mkdirp = require('mkdirp')
const rimraf = require('rimraf')

describe('sequelize-driver', function () {
  this.timeout(80000)
  const storage01 = `${__dirname}/../tmp/testing-driver.db`
  const storage02 = `${__dirname}/../tmp/testing-driver-2.db`
  const storage03 = `${__dirname}/../tmp/testing-driver-3.db`
  const storage04 = `${__dirname}/../tmp/testing-driver-4.db`
  const storage05 = `${__dirname}/../tmp/testing-driver-5.db`
  const storage06 = `${__dirname}/../tmp/testing-driver-6.db`
  const storage07 = `${__dirname}/../tmp/testing-driver-7.db`
  const storage08 = `${__dirname}/../tmp/testing-driver-8.db`
  const storage09 = `${__dirname}/../tmp/testing-driver-9.db`
  const storage10 = `${__dirname}/../tmp/testing-driver-10.db`
  const storage11 = `${__dirname}/../tmp/testing-driver-11.db`
  const storage12 = `${__dirname}/../tmp/testing-driver-12.db`
  const storage13 = `${__dirname}/../tmp/testing-driver-13.db`
  const storage14 = `${__dirname}/../tmp/testing-driver-14.db`
  const storage15 = `${__dirname}/../tmp/testing-driver-15.db`
  const storage16 = `${__dirname}/../tmp/testing-driver-16.db`
  const storage17 = `${__dirname}/../tmp/testing-driver-17.db`

  before(async () => {
    const storages = [
      storage01,
      storage02,
      storage03,
      storage04,
      storage05,
      storage06,
      storage07,
      storage08,
      storage09,
      storage10,
      storage11,
      storage12,
      storage13,
      storage14,
      storage15,
      storage16,
      storage17,
    ]
    for (let storage of storages) {
      rimraf.sync(storage)
      mkdirp.sync(path.dirname(storage))
    }
  })

  after(async () => {

  })

  it('Sequelize driver', async () => {
    const driver = new SequelizeDriver('hoge', '', '', {
      storage: storage01,
      dialect: 'sqlite',
      benchmark: true,
      logging: console.log
    })

    ok(driver.config)

    equal(driver.config.database, 'hoge')

    const created = await driver.create('User', {
      username: 'okunishinishi',
      birthday: new Date('1985/08/26')
    })
    ok(created)
    ok(created.id)
    ok(created.$$num)
    const one = await driver.one('User', created.id)
    equal(String(one.id), String(created.id))

    await asleep(50)
    const created2 = await driver.create('User', {
      username: 'hoge',
      birthday: new Date('1990/08/26')
    })

    await asleep(10)
    const created3 = await driver.create('User', {
      username: 'foge',
      birthday: new Date('1983/08/26')
    })
    ok(created2.id !== created.id)
    equal(created.username, 'okunishinishi')

    equal(created2.$$as, 'User')
    ok(created2.$$at)
    await asleep(50)
    {
      const {entities} = await driver.list('User', {filter: {$$num: created3.$$num}})
      equal(entities.length, 1)
      equal(String(entities[0].id), String(created3.id))
    }
    await asleep(50)
    {
      const {entities} = await driver.list('User', {sort: ['-$$at']})
      equal(entities.length, 3)
      equal(String(entities[0].id), String(created3.id))
      equal(String(entities[1].id), String(created2.id))
    }
    await asleep(50)
    {
      const list01 = await driver.list('User', {
        filter: {}
      })
      equal(String(list01.entities[0].id), String(created.id))
      equal(list01.entities[0].$$as, 'User')
      ok(list01.entities[0].$$at)
      ok(list01.meta)
      deepEqual(list01.meta, {offset: 0, limit: 100, total: 3, length: 3})
      await asleep(50)
      const list02 = await driver.list('User', {
        filter: {$or: [{username: 'okunishinishi'}]}
      })
      ok(list02.meta)
      deepEqual(list02.meta, {offset: 0, limit: 100, total: 1, length: 1})

      const list03 = await driver.list('User', {
        sort: ['birthday']
      })
      equal(list03.entities[0].username, 'foge')
      await asleep(50)
      const list04 = await driver.list('User', {
        sort: ['-birthday'],
        page: {size: 2, number: 1}
      })
      equal(list04.entities[0].username, 'hoge')
      deepEqual(list04.meta, {offset: 0, limit: 2, total: 3, length: 2})
      await asleep(10)
      const list05 = await driver.list('User', {
        filter: {'__unknown_column__': 0}
      })
      deepEqual(list05.meta, {offset: 0, limit: 100, total: 3, length: 3})
      await asleep(10)
      const list06 = await driver.list('User', {
        filter: {id: created2.id}
      })
      deepEqual(list06.meta, {offset: 0, limit: 100, total: 1, length: 1})
    }

    await driver.update('User', created2.id, {username: 'hogehoge'})

    {
      let beforeDestroy = await driver.one('User', created3.id)
      ok(beforeDestroy)
      ok(beforeDestroy.$$num)
    }

    await driver.destroy('User', created3.id)

    {
      let afterDestroy = await driver.one('User', created3.id)
      ok(!afterDestroy)
    }

    {
      let byId = await driver.list('User', {filter: {id: created3.id}})
      ok(byId)
    }
<commit_msg>fix test<commit_after>/**
 * Test case for sequelizeDriver.
 * Runs with mocha.
 */
'use strict'

const SequelizeDriver = require('../lib/sequelize_driver.js')
const clayDriverTests = require('clay-driver-tests')
const clayLump = require('clay-lump')
const {EOL} = require('os')
const {ok, equal, deepEqual, strictEqual} = require('assert')
const path = require('path')
const {exec} = require('child_process')
const fs = require('fs')
const asleep = require('asleep')
const mkdirp = require('mkdirp')
const rimraf = require('rimraf')

describe('sequelize-driver', function () {
  this.timeout(80000)
  const storage01 = `${__dirname}/../tmp/testing-driver.db`
  const storage02 = `${__dirname}/../tmp/testing-driver-2.db`
  const storage03 = `${__dirname}/../tmp/testing-driver-3.db`
  const storage04 = `${__dirname}/../tmp/testing-driver-4.db`
  const storage05 = `${__dirname}/../tmp/testing-driver-5.db`
  const storage06 = `${__dirname}/../tmp/testing-driver-6.db`
  const storage07 = `${__dirname}/../tmp/testing-driver-7.db`
  const storage08 = `${__dirname}/../tmp/testing-driver-8.db`
  const storage09 = `${__dirname}/../tmp/testing-driver-9.db`
  const storage10 = `${__dirname}/../tmp/testing-driver-10.db`
  const storage11 = `${__dirname}/../tmp/testing-driver-11.db`
  const storage12 = `${__dirname}/../tmp/testing-driver-12.db`
  const storage13 = `${__dirname}/../tmp/testing-driver-13.db`
  const storage14 = `${__dirname}/../tmp/testing-driver-14.db`
  const storage15 = `${__dirname}/../tmp/testing-driver-15.db`
  const storage16 = `${__dirname}/../tmp/testing-driver-16.db`
  const storage17 = `${__dirname}/../tmp/testing-driver-17.db`

  before(async () => {
    const storages = [
      storage01,
      storage02,
      storage03,
      storage04,
      storage05,
      storage06,
      storage07,
      storage08,
      storage09,
      storage10,
      storage11,
      storage12,
      storage13,
      storage14,
      storage15,
      storage16,
      storage17,
    ]
    for (let storage of storages) {
      rimraf.sync(storage)
      mkdirp.sync(path.dirname(storage))
    }
  })

  after(async () => {

  })

  it('Sequelize driver', async () => {
    const driver = new SequelizeDriver('hoge', '', '', {
      storage: storage01,
      dialect: 'sqlite',
      benchmark: true,
      logging: console.log
    })

    ok(driver.config)

    equal(driver.config.database, 'hoge')

    const created = await driver.create('User', {
      username: 'okunishinishi',
      birthday: new Date('1985/08/26')
    })
    ok(created)
    ok(created.id)
    ok(created.$$num)
    await asleep(50)
    const one = await driver.one('User', created.id)
    equal(String(one.id), String(created.id))

    await asleep(50)
    const created2 = await driver.create('User', {
      username: 'hoge',
      birthday: new Date('1990/08/26')
    })

    await asleep(10)
    const created3 = await driver.create('User', {
      username: 'foge',
      birthday: new Date('1983/08/26')
    })
    ok(created2.id !== created.id)
    equal(created.username, 'okunishinishi')

    equal(created2.$$as, 'User')
    ok(created2.$$at)
    await asleep(50)
    {
      const {entities} = await driver.list('User', {filter: {$$num: created3.$$num}})
      equal(entities.length, 1)
      equal(String(entities[0].id), String(created3.id))
    }
    await asleep(50)
    {
      const {entities} = await driver.list('User', {sort: ['-$$at']})
      equal(entities.length, 3)
      equal(String(entities[0].id), String(created3.id))
      equal(String(entities[1].id), String(created2.id))
    }
    await asleep(50)
    {
      const list01 = await driver.list('User', {
        filter: {}
      })

      equal(String(list01.entities[0].id), String(created.id))
      equal(list01.entities[0].$$as, 'User')
      ok(list01.entities[0].$$at)
      ok(list01.meta)
      deepEqual(list01.meta, {offset: 0, limit: 100, total: 3, length: 3})
      await asleep(50)
      const list02 = await driver.list('User', {
        filter: {$or: [{username: 'okunishinishi'}]}
      })
      ok(list02.meta)
      deepEqual(list02.meta, {offset: 0, limit: 100, total: 1, length: 1})
      await asleep(150)
      const list03 = await driver.list('User', {
        sort: ['birthday']
      })
      equal(list03.entities[0].username, 'foge')
      await asleep(50)
      const list04 = await driver.list('User', {
        sort: ['-birthday'],
        page: {size: 2, number: 1}
      })
      equal(list04.entities[0].username, 'hoge')
      deepEqual(list04.meta, {offset: 0, limit: 2, total: 3, length: 2})
      await asleep(10)
      const list05 = await driver.list('User', {
        filter: {'__unknown_column__': 0}
      })
      deepEqual(list05.meta, {offset: 0, limit: 100, total: 3, length: 3})
      await asleep(100)
      const list06 = await driver.list('User', {
        filter: {id: created2.id}
      })
      deepEqual(list06.meta, {offset: 0, limit: 100, total: 1, length: 1})
    }
    await asleep(50)
    await driver.update('User', created2.id, {username: 'hogehoge'})

    {
      let beforeDestroy = await driver.one('User', created3.id)
      ok(beforeDestroy)
      ok(beforeDestroy.$$num)
    }
    await asleep(50)
    await driver.destroy('User', created3.id)

    {
      let afterDestroy = await driver.one('User', created3.id)
      ok(!afterDestroy)
    }

    {
      let byId = await driver.list('User', {filter: {id: created3.id}})
      ok(byId)
    }

{'fraction_non_alphanumeric': 0.17133412909741988, 'fraction_numerical': 0.04370581213846295, 'mean_word_length': 2.846045197740113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4528241', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3669, 'n_words': 729}