<commit_before>import "reflect-metadata";
import {Connection} from "../../../../../src/connection/Connection";
import {
    closeTestingConnections,
    createTestingConnections,
    reloadTestingDatabases
} from "../../../../utils/test-utils";
import {Post} from "./entity/Post";
import {expect} from "chai";

describe("mongodb > timestampable columns", () => {

    let connections: Connection[];
    before(async () => connections = await createTestingConnections({
        entities: [Post],
        enabledDrivers: ["mongodb"]
    }));
    beforeEach(() => reloadTestingDatabases(connections));
    after(() => closeTestingConnections(connections));

    it("should persist timestampable columns", () => Promise.all(connections.map(async connection => {
        const commentMongoRepository = connection.getMongoRepository(Post);

        // save a post
        const post = new Post();
        post.message = "Hello";
        await commentMongoRepository.save(post);
        expect(post.id).to.be.not.undefined;
        post.createdAt.should.be.instanceof(Date);
        const createdAt = post.createdAt;

        post.updatedAt.should.be.instanceof(Date);
        const updatedAt = post.updatedAt;

        expect(post.createdAt.getTime()).to.equal(post.updatedAt.getTime());

        // update
        const date = new Date();<commit_msg>test(mongodb): time comparing is stable (#4292)<commit_after>import "reflect-metadata";
import {Connection} from "../../../../../src/connection/Connection";
import {
    closeTestingConnections,
    createTestingConnections,
    reloadTestingDatabases
} from "../../../../utils/test-utils";
import {Post} from "./entity/Post";
import {expect} from "chai";

describe("mongodb > timestampable columns", () => {

    let connections: Connection[];
    before(async () => connections = await createTestingConnections({
        entities: [Post],
        enabledDrivers: ["mongodb"]
    }));
    beforeEach(() => reloadTestingDatabases(connections));
    after(() => closeTestingConnections(connections));

    it("should persist timestampable columns", () => Promise.all(connections.map(async connection => {
        const commentMongoRepository = connection.getMongoRepository(Post);

        // save a post
        const post = new Post();
        post.message = "Hello";
        await commentMongoRepository.save(post);
        expect(post.id).to.be.not.undefined;
        post.createdAt.should.be.instanceof(Date);
        const createdAt = post.createdAt;

        post.updatedAt.should.be.instanceof(Date);
        const updatedAt = post.updatedAt;

        // test has +/- delta range of 5 milliseconds, because earlier this test fell due to the difference of 1 millisecond
        expect(post.updatedAt.getTime() - post.createdAt.getTime()).to.be.closeTo(0, 5);

        // update
        const date = new Date();
{'fraction_non_alphanumeric': 0.14505417686123734, 'fraction_numerical': 0.0027962250961202375, 'mean_word_length': 3.1358381502890174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '985086', 'n_tokens_mistral': 782, 'n_tokens_neox': 750, 'n_words': 171}