<commit_before>import sinon from "sinon";
import { CryptoOps, CachedKeyPair } from "../../src/crypto/CryptoOps";
import { GuidGenerator } from "../../src/crypto/GuidGenerator";
import { BrowserCrypto } from "../../src/crypto/BrowserCrypto";
import {createHash} from "crypto";
import { PkceCodes, BaseAuthRequest } from "@azure/msal-common";
import { TEST_URIS } from "../utils/StringConstants";
import { DatabaseStorage } from "../../src/cache/DatabaseStorage";

describe("CryptoOps.ts Unit Tests", () => {
    let cryptoObj: CryptoOps;
    let dbStorage = {};
    beforeEach(() => {
        sinon.stub(DatabaseStorage.prototype, "open").callsFake(async (): Promise<void> => {
            dbStorage = {};
        });

        sinon.stub(DatabaseStorage.prototype, "put").callsFake(async (key: string, payload: CachedKeyPair): Promise<void> => {
            dbStorage[key] = payload;
        });
        cryptoObj = new CryptoOps();
    });

    afterEach(() => {
        sinon.restore();
    });

    it("createNewGuid()", () => {
        expect(GuidGenerator.isGuid(cryptoObj.createNewGuid())).toBe(true);
    });

    it("base64Encode()", () => {
        /**<commit_msg>Update CryptoOps.spec.ts<commit_after>import sinon from "sinon";
import { CryptoOps, CachedKeyPair } from "../../src/crypto/CryptoOps";
import { GuidGenerator } from "../../src/crypto/GuidGenerator";
import { BrowserCrypto } from "../../src/crypto/BrowserCrypto";
import { createHash } from "crypto";
import { PkceCodes, BaseAuthRequest } from "@azure/msal-common";
import { TEST_URIS } from "../utils/StringConstants";
import { DatabaseStorage } from "../../src/cache/DatabaseStorage";

describe("CryptoOps.ts Unit Tests", () => {
    let cryptoObj: CryptoOps;
    let dbStorage = {};
    beforeEach(() => {
        sinon.stub(DatabaseStorage.prototype, "open").callsFake(async (): Promise<void> => {
            dbStorage = {};
        });

        sinon.stub(DatabaseStorage.prototype, "put").callsFake(async (key: string, payload: CachedKeyPair): Promise<void> => {
            dbStorage[key] = payload;
        });
        cryptoObj = new CryptoOps();
    });

    afterEach(() => {
        sinon.restore();
    });

    it("createNewGuid()", () => {
        expect(GuidGenerator.isGuid(cryptoObj.createNewGuid())).toBe(true);
    });

    it("base64Encode()", () => {
        /**
{'fraction_non_alphanumeric': 0.18328383538396267, 'fraction_numerical': 0.0016970725498515061, 'mean_word_length': 3.1080139372822297, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '969694', 'n_tokens_mistral': 700, 'n_tokens_neox': 701, 'n_words': 129}