<commit_before>const jsdom = require("jsdom");
const window = jsdom.jsdom().defaultView;
const $ = require("jquery")(window);
global.$ = $;

const fs = require("fs");
const chai = require('chai');
const assert = chai.assert;
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);

const AboutCodeDB = require("../assets/js/aboutCodeDB");
const scanCodeJSONResults = JSON.parse(fs.readFileSync(__dirname + "/data/scancode-results.json", "utf8"));

describe("checkAboutCodeDB", function() {

    describe("addRows", function() {
        it("should add rows to database", function () {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.File.count())
                .then((rowCount) => assert.strictEqual(rowCount, 0))
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.File.count())
                .then((rowCount) => assert.strictEqual(rowCount, 2))
                .then(() => aboutCodeDB.License.count())
                .then((licenseCount) => assert.strictEqual(licenseCount,1))
                .then(() => aboutCodeDB.Copyright.count())
                .then((copyrightCount) => assert.strictEqual(copyrightCount, 2))
                .then(() => aboutCodeDB.Package.count())
                .then((packageCount) => assert.strictEqual(packageCount, 1))
                .then(() => aboutCodeDB.Email.count())
                .then((emailCount) => assert.strictEqual(emailCount, 1))
                .then(() => aboutCodeDB.Url.count())
                .then((urlCount) => assert.strictEqual(urlCount, 2))
        });
    });

    describe("findAll", function() {
        it("should return all rows", function() {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.findAll({ plain: true }))
                .then((rows) => {
                    rows = JSON.parse(JSON.stringify(rows));
                    assert.containSubset(rows, scanCodeJSONResults.files[0])
                })
        });
    });

    describe("findOne", function() {
        it("should return one", function() {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.findOne({
                    where: { path: "samples/JGroups/src"},
                    plain: true
                }))
                .then((rows) => {
                    rows = JSON.parse(JSON.stringify(rows));
                    assert.containSubset(rows, scanCodeJSONResults.files[1])
                })
        });
    });
});<commit_msg>#39: Fixed tests that were using "plain: true"<commit_after>const jsdom = require("jsdom");
const window = jsdom.jsdom().defaultView;
const $ = require("jquery")(window);
global.$ = $;

const fs = require("fs");
const chai = require('chai');
const assert = chai.assert;
const chaiSubset = require('chai-subset');
chai.use(chaiSubset);

const AboutCodeDB = require("../assets/js/aboutCodeDB");
const scanCodeJSONResults = JSON.parse(fs.readFileSync(__dirname + "/data/scancode-results.json", "utf8"));

describe("checkAboutCodeDB", function() {

    describe("addRows", function() {
        it("should add rows to database", function () {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.File.count())
                .then((rowCount) => assert.strictEqual(rowCount, 0))
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.File.count())
                .then((rowCount) => assert.strictEqual(rowCount, 2))
                .then(() => aboutCodeDB.License.count())
                .then((licenseCount) => assert.strictEqual(licenseCount,1))
                .then(() => aboutCodeDB.Copyright.count())
                .then((copyrightCount) => assert.strictEqual(copyrightCount, 2))
                .then(() => aboutCodeDB.Package.count())
                .then((packageCount) => assert.strictEqual(packageCount, 1))
                .then(() => aboutCodeDB.Email.count())
                .then((emailCount) => assert.strictEqual(emailCount, 1))
                .then(() => aboutCodeDB.Url.count())
                .then((urlCount) => assert.strictEqual(urlCount, 2))
        });
    });

    describe("findAll", function() {
        it("should return all rows", function() {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.findAll({}))
                .then((rows) => {
                    rows = rows.map(row => row.toJSON());
                    assert.containSubset(rows, scanCodeJSONResults.files);
                })
        });
    });

    describe("findOne", function() {
        it("should return one", function() {
            let aboutCodeDB = new AboutCodeDB();

            return aboutCodeDB.db
                .then(() => aboutCodeDB.addRows(scanCodeJSONResults))
                .then(() => aboutCodeDB.findOne({
                    where: { path: "samples/JGroups/src"}
                }))
                .then((row) => {
                    row = row.toJSON();
                    assert.containSubset(row, scanCodeJSONResults.files[1]);
                })
        });
    });
});
{'fraction_non_alphanumeric': 0.15628356605800214, 'fraction_numerical': 0.0037593984962406013, 'mean_word_length': 2.043028322440087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 46, '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': '5867436', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1479, 'n_words': 268}