<commit_before>import chai from 'chai';

chai.should();

import {createSnapshot, deleteSnapshot} from './testUtilities';
import databaseConfig from '../src/databaseConfig'
import MssqlSnapshot from '../src/MssqlSnapshot';

describe("when retrieving a list of snapshots and the configuration is valid", function() {
    let target, dbConfig = null;
    const snapshotName = 'mssql-snapshot-testdb-when-retrieving-list';
    let snapshotCreationTime = null;
    beforeEach((done) => {
        dbConfig = databaseConfig();
        target = new MssqlSnapshot(dbConfig);
        createSnapshot(snapshotName).then(
            () => {
                snapshotCreationTime = new Date();
                done()
            },
            (err) => {
                done(err);
            }
        );
    });
    afterEach((done) => {
        deleteSnapshot(snapshotName).then(
            () => {
                done();
            },
            (err) => {
                done(err);
            }
        );
    });
    it("it returns one result", (done) => {
        target.listAll().then(
            (result) => {
                result.length.should.eql(1);
                done();
            },
            (err) => {
                done(err);
            }
        );
    });
    it("it returns a result that contains the correct source database name", (done) => {
        target.listAll().then(
            (result) => {
                result[0].SourceDatabase.should.eql(dbConfig.database);
                done();
            },
            (err) => {
                done(err);
            }
        )
    });
    it("it returns a result that contains the correct date of creation", (done) => {
        target.listAll().then(
            (result) => {
                result[0].DateOfCreation.getDay().should.eql(snapshotCreationTime.getDay());
                result[0].DateOfCreation.getYear().should.eql(snapshotCreationTime.getYear());
                result[0].DateOfCreation.getMonth().should.eql(snapshotCreationTime.getMonth());
                result[0].DateOfCreation.getHours().should.eql(snapshotCreationTime.getHours() - 5);
                result[0].DateOfCreation.getMinutes().should.eql(snapshotCreationTime.getMinutes());
                result[0].DateOfCreation.getSeconds().should.eql(snapshotCreationTime.getSeconds());
                done();
            },
            (err) => {
                done(err);
            }
        )
    });
});

describe("when retrieving a list of snapshots and the configuration is invalid", function() {
    let target = null;
    beforeEach(function() {
        target = new MssqlSnapshot({
            name: 'fakeConnection'
        });
    });
    it("it returns a proper error", (done) => {
        target.listAll('fakeConnection').then(
            (result) => {
                done(result);
            },
            (err) => {
                err.code.should.eql('ENOCONN');
                err.message.should.eql('SqlContext Error. Failed on step "__result__" with: "No connection is specified for that request."');
                done();
            });
    });
});<commit_msg>adjust test for daylight savings time.  todo:  make test tolerant of DLST.<commit_after>import chai from 'chai';

chai.should();

import {createSnapshot, deleteSnapshot} from './testUtilities';
import databaseConfig from '../src/databaseConfig'
import MssqlSnapshot from '../src/MssqlSnapshot';

describe("when retrieving a list of snapshots and the configuration is valid", function() {
    let target, dbConfig = null;
    const snapshotName = 'mssql-snapshot-testdb-when-retrieving-list';
    let snapshotCreationTime = null;
    beforeEach((done) => {
        dbConfig = databaseConfig();
        target = new MssqlSnapshot(dbConfig);
        createSnapshot(snapshotName).then(
            () => {
                snapshotCreationTime = new Date();
                done()
            },
            (err) => {
                done(err);
            }
        );
    });
    afterEach((done) => {
        deleteSnapshot(snapshotName).then(
            () => {
                done();
            },
            (err) => {
                done(err);
            }
        );
    });
    it("it returns one result", (done) => {
        target.listAll().then(
            (result) => {
                result.length.should.eql(1);
                done();
            },
            (err) => {
                done(err);
            }
        );
    });
    it("it returns a result that contains the correct source database name", (done) => {
        target.listAll().then(
            (result) => {
                result[0].SourceDatabase.should.eql(dbConfig.database);
                done();
            },
            (err) => {
                done(err);
            }
        )
    });
	it("it returns a result that contains the correct date of creation", (done) => {
		this.timeout(15000);
		target.listAll().then(
			(result) => {
				result[0].DateOfCreation.getDay().should.eql(snapshotCreationTime.getDay());
				result[0].DateOfCreation.getYear().should.eql(snapshotCreationTime.getYear());
				result[0].DateOfCreation.getMonth().should.eql(snapshotCreationTime.getMonth());
				//todo:  the following assertion will fail depending on daylight savings time
				result[0].DateOfCreation.getHours().should.eql(snapshotCreationTime.getHours() - 4);
				result[0].DateOfCreation.getMinutes().should.eql(snapshotCreationTime.getMinutes());
				result[0].DateOfCreation.getSeconds().should.eql(snapshotCreationTime.getSeconds());
				done();
			},
			(err) => {
				done(err);
			}
		)
	});
});

describe("when retrieving a list of snapshots and the configuration is invalid", function() {
    let target = null;
    beforeEach(function() {
        target = new MssqlSnapshot({
            name: 'fakeConnection'
        });
    });
    it("it returns a proper error", (done) => {
        target.listAll('fakeConnection').then(
            (result) => {
                done(result);
            },
            (err) => {
                err.code.should.eql('ENOCONN');
                err.message.should.eql('SqlContext Error. Failed on step "__result__" with: "No connection is specified for that request."');
                done();
            });
    });
});
{'fraction_non_alphanumeric': 0.13978494623655913, 'fraction_numerical': 0.0036369386464263124, 'mean_word_length': 1.8388689407540395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '4313655', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1699, 'n_words': 339}