<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const moment = require('moment');
const path = require('path');

chai.use(chaiAsPromised);
const expect = chai.expect;

const recreateDB = require('./common').recreateDB;
const db = require('../../models/database').db;
const Meter = require('../../models/Meter');
const readMetasysData = require('../../services/readMetasysData');

const mocha = require('mocha');

mocha.describe('Insert Metasys readings from a file', () => {
	mocha.beforeEach(recreateDB);
	let meter;
	mocha.beforeEach(() => db.task(async t => {
		await new Meter(undefined, 'Meter', null, false, Meter.type.METASYS).insert(t);
		meter = await Meter.getByName('Meter', t);
	}));

	mocha.it('loads the correct number of rows from a file', () => db.task(async t => {
		const testFilePath = path.join(__dirname, 'Meter.csv');
		// readMetasysData(filepath, interval, repetition)
		await readMetasysData(testFilePath, 30, 1, false,t);
		const count = await db.one('SELECT COUNT(*) as count FROM readings');
		expect(parseInt(count)).to.equal(225);
			// .then(() => db.one('SELECT COUNT(*) as count FROM readings'))
			// .then(({ count }) => expect(parseInt(count)).to.equal(225));
	}));
});
<commit_msg>Changed the promise style to .then<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const moment = require('moment');
const path = require('path');

chai.use(chaiAsPromised);
const expect = chai.expect;

const recreateDB = require('./common').recreateDB;
const db = require('../../models/database').db;
const Meter = require('../../models/Meter');
const readMetasysData = require('../../services/readMetasysData');

const mocha = require('mocha');

mocha.describe('Insert Metasys readings from a file', () => {
	mocha.beforeEach(recreateDB);
	let meter;
	mocha.beforeEach(() => db.task(async t => {
		await new Meter(undefined, 'Meter', null, false, Meter.type.METASYS).insert(t);
		meter = await Meter.getByName('Meter', t);
	}));

	mocha.it('loads the correct number of rows from a file', () => {
		const testFilePath = path.join(__dirname, 'Meter.csv');
	//	const readingDuration = moment.duration(1, 'hours');
		// readMetasysData(filepath, interval, repetition, cumulative & reset)
		return readMetasysData(testFilePath, 30,1, false)
			.then(() => db.one('SELECT COUNT(*) as count FROM readings'))
			.then(({ count }) => expect(parseInt(count)).to.equal(225));
	});
});

{'fraction_non_alphanumeric': 0.17491408934707903, 'fraction_numerical': 0.008247422680412371, 'mean_word_length': 4.441121495327103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '7047936', 'n_tokens_mistral': 992, 'n_tokens_neox': 936, 'n_words': 262}