2019-09-13 13:49:11 +02:00
|
|
|
import o from "ospec"
|
2018-10-12 10:50:17 +02:00
|
|
|
import type {BrowserData} from "../../src/misc/ClientConstants"
|
|
|
|
import type {Db} from "../../src/api/worker/search/SearchTypes"
|
|
|
|
import {IndexerCore} from "../../src/api/worker/search/IndexerCore"
|
|
|
|
import {EventQueue} from "../../src/api/worker/search/EventQueue"
|
2022-01-13 13:24:37 +01:00
|
|
|
import {DbFacade, DbTransaction} from "../../src/api/worker/search/DbFacade"
|
2021-11-04 14:05:23 +01:00
|
|
|
import {assertNotNull, neverNull} from "@tutao/tutanota-utils"
|
2022-01-27 12:20:21 +01:00
|
|
|
import type {DesktopKeyStoreFacade} from "../../src/desktop/KeyStoreFacadeImpl"
|
2021-11-04 14:05:23 +01:00
|
|
|
import {mock} from "@tutao/tutanota-test-utils"
|
2021-11-19 14:48:33 +01:00
|
|
|
import {aes256RandomKey, fixedIv, uint8ArrayToKey} from "@tutao/tutanota-crypto"
|
2018-10-12 10:50:17 +02:00
|
|
|
|
2022-01-07 15:58:30 +01:00
|
|
|
export const browserDataStub: BrowserData = {
|
|
|
|
needsMicrotaskHack: false,
|
|
|
|
needsExplicitIDBIds: false,
|
|
|
|
indexedDbSupported: true
|
|
|
|
}
|
2018-10-12 10:50:17 +02:00
|
|
|
|
|
|
|
export function makeCore(args?: {
|
|
|
|
db?: Db,
|
|
|
|
queue?: EventQueue,
|
|
|
|
browserData?: BrowserData,
|
|
|
|
transaction?: DbTransaction
|
2022-01-07 15:58:30 +01:00
|
|
|
}, mocker?: (_: any) => void): IndexerCore {
|
2022-01-13 13:24:37 +01:00
|
|
|
const safeArgs = args ?? {}
|
2022-01-07 15:58:30 +01:00
|
|
|
const {transaction} = safeArgs
|
2018-10-12 10:50:17 +02:00
|
|
|
const defaultDb = {
|
|
|
|
key: aes256RandomKey(),
|
|
|
|
iv: fixedIv,
|
2022-01-13 13:24:37 +01:00
|
|
|
dbFacade: ({createTransaction: () => Promise.resolve(transaction)} as Partial<DbFacade>),
|
2018-10-12 10:50:17 +02:00
|
|
|
initialized: Promise.resolve()
|
2022-01-13 13:24:37 +01:00
|
|
|
} as Partial<Db> as Db
|
|
|
|
const defaultQueue = {} as Partial<EventQueue> as EventQueue
|
|
|
|
const {db, queue, browserData} = {
|
|
|
|
...{db: defaultDb, browserData: browserDataStub, queue: defaultQueue},
|
|
|
|
...safeArgs,
|
2018-10-12 10:50:17 +02:00
|
|
|
}
|
2022-01-13 13:24:37 +01:00
|
|
|
const core = new IndexerCore(db, queue, browserData)
|
2018-10-12 10:50:17 +02:00
|
|
|
mocker && mock(core, mocker)
|
|
|
|
return core
|
2019-03-12 11:58:31 +01:00
|
|
|
}
|
2020-01-30 18:58:00 +01:00
|
|
|
|
2019-09-13 13:49:11 +02:00
|
|
|
export function preTest() {
|
|
|
|
browser(() => {
|
|
|
|
const p = document.createElement("p")
|
|
|
|
p.id = "report"
|
|
|
|
p.style.fontWeight = "bold"
|
|
|
|
p.style.fontSize = "30px"
|
|
|
|
p.style.fontFamily = "sans-serif"
|
|
|
|
p.textContent = "Running tests..."
|
|
|
|
neverNull(document.body).appendChild(p)
|
|
|
|
})()
|
|
|
|
}
|
|
|
|
|
2022-01-07 15:58:30 +01:00
|
|
|
export function reportTest(results: any, stats: any) {
|
|
|
|
// @ts-ignore
|
2019-09-13 13:49:11 +02:00
|
|
|
const errCount = o.report(results, stats)
|
|
|
|
if (typeof process != "undefined" && errCount !== 0) process.exit(1) // eslint-disable-line no-process-exit
|
|
|
|
browser(() => {
|
|
|
|
const p = assertNotNull(document.getElementById("report"))
|
|
|
|
// errCount includes bailCount
|
|
|
|
p.textContent = errCount === 0 ? "No errors" : `${errCount} error(s) (see console)`
|
2022-01-07 15:58:30 +01:00
|
|
|
// @ts-ignore
|
2021-12-28 13:53:11 +01:00
|
|
|
p.style.Color = errCount === 0 ? "green" : "red"
|
2019-09-13 13:49:11 +02:00
|
|
|
})()
|
2021-03-25 17:12:17 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 12:20:21 +01:00
|
|
|
export function makeKeyStoreFacade(uint8ArrayKey: Uint8Array): DesktopKeyStoreFacade {
|
2021-03-25 17:12:17 +01:00
|
|
|
return {
|
|
|
|
getDeviceKey() {
|
|
|
|
return Promise.resolve(uint8ArrayToKey(uint8ArrayKey))
|
2022-01-25 15:04:16 +01:00
|
|
|
},
|
|
|
|
getCredentialsKey(): Promise<Aes256Key> {
|
|
|
|
return Promise.resolve(uint8ArrayToKey(uint8ArrayKey))
|
2021-03-25 17:12:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-22 18:24:32 +02:00
|
|
|
}
|