<commit_before>import initStorageManager from 'src/search/memory-storex'
import CustomListBg from 'src/custom-lists/background'
import SocialBackground from './'
import SocialStorage from './storage'
import { StorageManager } from 'src/search'
import * as DATA from './storage.test.data'
import { Tweet, SocialPage } from '../types'
import { SocialSearchPlugin } from 'src/search/background/social-search'
import { SocialSearchParams } from 'src/search/background/types'

const assertTweetsEqual = (received: Tweet, expected: Tweet) => {
    expect(received.id).toEqual(expected.id)
    expect(received.text).toEqual(expected.text)
    expect(received.userId).toEqual(expected.userId)
    expect(received.createdAt).toEqual(expected.createdAt)
}

describe('Social storage', () => {
    let socialStorage: SocialStorage
    let storageManager: StorageManager
    let socialBg: SocialBackground
    let customListBg: CustomListBg
    let listId: number

    const search = ({
        skip = 0,
        limit = 10,
        ...args
    }: SocialSearchParams): Promise<Map<number, SocialPage>> =>
        storageManager.operation(SocialSearchPlugin.SEARCH_OP_ID, {
            limit,
            skip,
            ...args,
        })

    async function insertTestData() {
        listId = await customListBg.createCustomList({
            name: DATA.customListNameA,
        })

        for (const tweet of [DATA.tweetA, DATA.tweetB]) {
            await socialStorage.addSocialPost({ ...tweet })
        }
    }

    beforeEach(async () => {
        storageManager = initStorageManager()
        customListBg = new CustomListBg({
            storageManager,
            getDb: () => storageManager['dexieInstance'],
        })
        socialBg = new SocialBackground({
            storageManager,
        })

        socialStorage = socialBg['storage']

        await storageManager.finishInitialization()
        await insertTestData()
    })

    const addBookmarkTest = async () => {
        const id = await socialStorage.addSocialBookmark({
            postId: DATA.tweetA.id,
        })

        const results = await search({ bookmarksOnly: true })
        const firstRes = [...results.values()][0]
        assertTweetsEqual(firstRes, DATA.tweetA)
        return id
    }

    const addListEntryTest = async () => {<commit_msg>Add missing annots BG instantiation in social tests<commit_after>import initStorageManager from 'src/search/memory-storex'
import CustomListBg from 'src/custom-lists/background'
import AnnotsBg from 'src/direct-linking/background'
import SocialBackground from './'
import SocialStorage from './storage'
import { StorageManager } from 'src/search'
import * as DATA from './storage.test.data'
import { Tweet, SocialPage } from '../types'
import { SocialSearchPlugin } from 'src/search/background/social-search'
import { SocialSearchParams } from 'src/search/background/types'

const assertTweetsEqual = (received: Tweet, expected: Tweet) => {
    expect(received.id).toEqual(expected.id)
    expect(received.text).toEqual(expected.text)
    expect(received.userId).toEqual(expected.userId)
    expect(received.createdAt).toEqual(expected.createdAt)
}

describe('Social storage', () => {
    let socialStorage: SocialStorage
    let storageManager: StorageManager
    let socialBg: SocialBackground
    let customListBg: CustomListBg
    let listId: number

    const search = ({
        skip = 0,
        limit = 10,
        ...args
    }: SocialSearchParams): Promise<Map<number, SocialPage>> =>
        storageManager.operation(SocialSearchPlugin.SEARCH_OP_ID, {
            limit,
            skip,
            ...args,
        })

    async function insertTestData() {
        listId = await customListBg.createCustomList({
            name: DATA.customListNameA,
        })

        for (const tweet of [DATA.tweetA, DATA.tweetB]) {
            await socialStorage.addSocialPost({ ...tweet })
        }
    }

    beforeEach(async () => {
        storageManager = initStorageManager()
        customListBg = new CustomListBg({
            storageManager,
            getDb: () => storageManager['dexieInstance'],
        })
        socialBg = new SocialBackground({
            storageManager,
        })
        new AnnotsBg({
            storageManager,
            getDb: () => storageManager['dexieInstance'],
            socialBg,
        })

        socialStorage = socialBg['storage']

        await storageManager.finishInitialization()
        await insertTestData()
    })

    const addBookmarkTest = async () => {
        const id = await socialStorage.addSocialBookmark({
            postId: DATA.tweetA.id,
        })

        const results = await search({ bookmarksOnly: true })
        const firstRes = [...results.values()][0]
        assertTweetsEqual(firstRes, DATA.tweetA)
        return id
    }

    const addListEntryTest = async () => {
{'fraction_non_alphanumeric': 0.1101123595505618, 'fraction_numerical': 0.001634320735444331, 'mean_word_length': 2.648286140089419, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '7551811', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1312, 'n_words': 295}