<commit_before>const {Table} = require('../src/table');
const {expect} = require('code');
const file = require('../src/file');
const query = require('../src/query');
const sinon = require('sinon');

describe('Table', () => {

  const idbName = 'db-name';
  const tableName = 'table-name';
  let sandbox,
    table;

  beforeEach(() => {

    sandbox = sinon.sandbox.create();
    table = new Table(idbName, tableName);

    sandbox.stub(file);
    sandbox.stub(query);

  });

  afterEach(() => sandbox.restore());

  it('should be initialized and used as object', () => {

    expect(table).to.be.object();

  });

  describe('on saving', () => {

    let tableData,
      loadTable,
      saveTable,
      updatedTableData;

    beforeEach(() => {

      tableData = {rows: []};
      updatedTableData = {rows: ['updated']};

      loadTable = Promise.resolve(tableData);
      saveTable = Promise.resolve();

      file.saveTable.returns(saveTable);
      file.loadTable.returns(loadTable);

      query.run.returns(updatedTableData);

    });

    it('should return a promise', () => {

      expect(table.save()).instanceOf(Promise).equals(saveTable);

    });

    it('should load table data', () => {

      table.save();

      sinon.assert.calledOnce(file.loadTable);
      sinon.assert.calledWithExactly(file.loadTable, idbName, tableName);

    });

    it('should run the queries yet', () => {

      sinon.assert.notCalled(query.run);

    });

    describe('after loading the data', () => {

      beforeEach(async () => await table.save());<commit_msg>add more assertions on save<commit_after>const {Table} = require('../src/table');
const {expect} = require('code');
const file = require('../src/file');
const query = require('../src/query');
const sinon = require('sinon');

describe('Table', () => {

  const idbName = 'db-name';
  const tableName = 'table-name';
  let sandbox,
    table;

  beforeEach(() => {

    sandbox = sinon.sandbox.create();
    table = new Table(idbName, tableName);

    sandbox.stub(file);
    sandbox.stub(query);

  });

  afterEach(() => sandbox.restore());

  it('should be initialized and used as object', () => {

    expect(table).to.be.object();

  });

  describe('on saving', () => {

    let tableData,
      loadTable,
      saveTable,
      updatedTableData;

    beforeEach(() => {

      tableData = {rows: []};
      updatedTableData = {rows: ['updated']};

      loadTable = Promise.resolve(tableData);
      saveTable = Promise.resolve();

      file.saveTable.returns(saveTable);
      file.loadTable.returns(loadTable);

      query.run.returns(updatedTableData);

    });

    it('should return a promise', () => {

      expect(table.save()).instanceOf(Promise).equals(saveTable);

    });

    it('should load table data', () => {

      table.save();

      sinon.assert.calledOnce(file.loadTable);
      sinon.assert.calledWithExactly(file.loadTable, idbName, tableName);

    });

    it('should not run the queries yet', () => {

      sinon.assert.notCalled(query.run);

    });

    it('should not save the tables yet', () => {

      sinon.assert.notCalled(file.saveTable);

    });

    describe('after loading the data', () => {

      beforeEach(async () => await table.save());
{'fraction_non_alphanumeric': 0.17863720073664824, 'fraction_numerical': 0.0, 'mean_word_length': 2.988984088127295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '1503817', 'n_tokens_mistral': 1044, 'n_tokens_neox': 982, 'n_words': 193}