<commit_before>import * as assert from "assert";
import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil";

import {
    RavenErrorType,
    IDocumentStore,
    GetCountersOperation,
    CreateDatabaseOperation,
    DeleteDatabasesOperation,
    IDocumentSession,
    DocumentCountersOperation,
    CounterOperation,
    CounterBatch,
    CounterBatchOperation,
} from "../../../src";
import { User, Company, Order, Employee } from "../../Assets/Entities";
import { assertThat } from "../../Utils/AssertExtensions";

describe("SessionCountersTest", function () {

    let store: IDocumentStore;

    beforeEach(async function () {
        store = await testContext.getDocumentStore();
    });

    afterEach(async () => 
        await disposeTestDocumentStore(store));

    it("sessionIncrementCounter", async () => {
        {
            const session = store.openSession();
            await session.store(Object.assign(new User(), { name: "Aviv1" }), "users/1-A");
            await session.store(Object.assign(new User(), { name: "Aviv2" }), "users/2-A");
            await session.saveChanges();
        }
        {
            const session = store.openSession();
            session.countersFor("users/1-A").increment("likes", 100);
            session.countersFor("users/1-A").increment("downloads", 500);
            session.countersFor("users/2-A").increment("votes", 1000);
            await session.saveChanges();
        }
        {
            let counters = (await store.operations.send(
                new GetCountersOperation("users/1-A", ["likes", "downloads"]))).counters;
            assert.strictEqual(counters.length, 2);
            assert.strictEqual(
                counters.filter(x => x.counterName === "likes")[0].totalValue, 100);
            assert.strictEqual(
                counters.filter(x => x.counterName === "downloads")[0].totalValue, 500);
            
            counters = (await store.operations.send(new GetCountersOperation("users/2-A", ["votes"]))).counters;
            assert.strictEqual(counters.length, 1);
            assert.strictEqual(
                counters.filter(x => x.counterName === "votes")[0].totalValue, 1000);
        }
    });

    it("sessionDeleteCounter", async function () {
        {
            const session = store.openSession();
            await session.store(Object.assign(new User(), { name: "Aviv1" }), "users/1-A");
            await session.store(Object.assign(new User(), { name: "Aviv2" }), "users/2-A");
            await session.saveChanges();
        }
        {
            const session = store.openSession();
            session.countersFor("users/1-A").increment("likes", 100);
            session.countersFor("users/1-A").increment("downloads", 500);
            session.countersFor("users/2-A").increment("votes", 1000);
            await session.saveChanges();
        }

        const { counters } = (await store.operations
                   .send(new GetCountersOperation("users/1-A", ["likes", "downloads"])));
        assert.strictEqual(counters.length, 2);

        {
            const session = store.openSession();
            session.countersFor("users/1-A").delete("likes");
            session.countersFor("users/1-A").delete("downloads");
            session.countersFor("users/2-A").delete("votes");
            await session.saveChanges();
        }

        counters = (await store.operations
            .send(new GetCountersOperation("users/1-A", ["likes", "downloads"])))
            .counters;

        assertThat(counters)
            .hasSize(2);
        assertThat(counters[0])
            .isNull();<commit_msg>fixed test<commit_after>import * as assert from "assert";
import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil";

import {
    RavenErrorType,
    IDocumentStore,
    GetCountersOperation,
    CreateDatabaseOperation,
    DeleteDatabasesOperation,
    IDocumentSession,
    DocumentCountersOperation,
    CounterOperation,
    CounterBatch,
    CounterBatchOperation,
} from "../../../src";
import { User, Company, Order, Employee } from "../../Assets/Entities";
import { assertThat } from "../../Utils/AssertExtensions";

describe("SessionCountersTest", function () {

    let store: IDocumentStore;

    beforeEach(async function () {
        store = await testContext.getDocumentStore();
    });

    afterEach(async () => 
        await disposeTestDocumentStore(store));

    it("sessionIncrementCounter", async () => {
        {
            const session = store.openSession();
            await session.store(Object.assign(new User(), { name: "Aviv1" }), "users/1-A");
            await session.store(Object.assign(new User(), { name: "Aviv2" }), "users/2-A");
            await session.saveChanges();
        }
        {
            const session = store.openSession();
            session.countersFor("users/1-A").increment("likes", 100);
            session.countersFor("users/1-A").increment("downloads", 500);
            session.countersFor("users/2-A").increment("votes", 1000);
            await session.saveChanges();
        }
        {
            let counters = (await store.operations.send(
                new GetCountersOperation("users/1-A", ["likes", "downloads"]))).counters;
            assert.strictEqual(counters.length, 2);
            assert.strictEqual(
                counters.filter(x => x.counterName === "likes")[0].totalValue, 100);
            assert.strictEqual(
                counters.filter(x => x.counterName === "downloads")[0].totalValue, 500);
            
            counters = (await store.operations.send(new GetCountersOperation("users/2-A", ["votes"]))).counters;
            assert.strictEqual(counters.length, 1);
            assert.strictEqual(
                counters.filter(x => x.counterName === "votes")[0].totalValue, 1000);
        }
    });

    it("sessionDeleteCounter", async function () {
        {
            const session = store.openSession();
            await session.store(Object.assign(new User(), { name: "Aviv1" }), "users/1-A");
            await session.store(Object.assign(new User(), { name: "Aviv2" }), "users/2-A");
            await session.saveChanges();
        }
        {
            const session = store.openSession();
            session.countersFor("users/1-A").increment("likes", 100);
            session.countersFor("users/1-A").increment("downloads", 500);
            session.countersFor("users/2-A").increment("votes", 1000);
            await session.saveChanges();
        }

        let { counters } = (await store.operations
                   .send(new GetCountersOperation("users/1-A", ["likes", "downloads"])));
        assert.strictEqual(counters.length, 2);

        {
            const session = store.openSession();
            session.countersFor("users/1-A").delete("likes");
            session.countersFor("users/1-A").delete("downloads");
            session.countersFor("users/2-A").delete("votes");
            await session.saveChanges();
        }

        counters = (await store.operations
            .send(new GetCountersOperation("users/1-A", ["likes", "downloads"])))
            .counters;

        assertThat(counters)
            .hasSize(2);
        assertThat(counters[0])
            .isNull();
{'fraction_non_alphanumeric': 0.15317166735169202, 'fraction_numerical': 0.016166598164132073, 'mean_word_length': 2.324225865209472, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6709575', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2029, 'n_words': 340}