core: fix tests

This commit is contained in:
Abdullah Atta
2025-10-02 09:23:38 +05:00
parent 86da8a3620
commit 6f80334296
3 changed files with 38 additions and 16 deletions

View File

@@ -17,7 +17,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Cipher, NNCrypto, SerializedKey } from "@notesnook/crypto";
import {
Cipher,
NNCrypto,
SerializedKey,
SerializedKeyPair
} from "@notesnook/crypto";
import { IStorage } from "../src/interfaces.js";
export class NodeStorageInterface implements IStorage {
@@ -109,4 +114,17 @@ export class NodeStorageInterface implements IStorage {
): Promise<SerializedKey> {
return { password, salt };
}
generateCryptoKeyPair(): Promise<SerializedKeyPair> {
throw new Error("Method not implemented.");
}
generateCryptoKeyFallback(
password: string,
salt?: string
): Promise<SerializedKey> {
throw new Error("Method not implemented.");
}
deriveCryptoKeyFallback(credentials: SerializedKey): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@@ -57,6 +57,7 @@ function databaseTest(type: "memory" | "persistent" = "memory") {
eventsource: EventSource,
fs: FS,
compressor: async () => Compressor,
maxNoteVersions: async () => 1000,
sqliteOptions: {
dialect: (name) =>
new SqliteDialect({

View File

@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { expect, test } from "vitest";
import { transformQuery } from "../query-transformer.js";
const TRANSFORM_QUERY_TESTS: [string, string][] = [
const TRANSFORM_QUERY_TESTS: [string, string | undefined][] = [
["hello world", `hello AND world`],
["hello world OR bar", `hello AND world OR bar`],
["hello world OR bar NOT baz", `hello AND world OR bar NOT baz`],
@@ -29,34 +29,37 @@ const TRANSFORM_QUERY_TESTS: [string, string][] = [
["hello world -foo", `hello AND world AND "-foo"`],
["hello world phrase-with-dash", `hello AND world AND "phrase-with-dash"`],
["hello world phrase-with-dash*", 'hello AND world AND "phrase-with-dash*"'],
["example + foo + bar", `example AND foo AND bar`],
["example + foo + bar", `example AND "+" AND foo AND "+" AND bar`],
["example OR foo NOT bar", `example OR foo NOT bar`],
[
'example "quoted phrase" "another quoted phrase"',
`example AND "quoted phrase" AND "another quoted phrase"`
],
['"phrase-with-dash*"', `"phrase-with-dash*"`],
['-foo + bar OR "quoted-phrase"', `"-foo" AND bar OR "quoted-phrase"`],
[
'-foo + bar OR "quoted-phrase"',
`"-foo" AND "+" AND bar OR "quoted-phrase"`
],
[
'phrase-with-dash* + "quoted-phrase"',
`"phrase-with-dash*" AND "quoted-phrase"`
`"phrase-with-dash*" AND "+" AND "quoted-phrase"`
],
[
'example -foo + bar + "quoted-dash-phrase*" OR "another-quoted-phrase"',
`example AND "-foo" AND bar AND "quoted-dash-phrase*" OR "another-quoted-phrase"`
`example AND "-foo" AND "+" AND bar AND "+" AND "quoted-dash-phrase*" OR "another-quoted-phrase"`
],
["", ""],
["", undefined],
["foo", `foo`],
['"quoted"', '"quoted"'],
["-foo -bar", `"-foo" AND "-bar"`],
["foo + + bar", `foo AND bar`],
["foo + OR", `foo`],
["foo + + bar", `foo AND "+" AND "+" AND bar`],
["foo + OR", `foo AND "+"`],
['"special -phrase*"', '"special -phrase*"'],
["foo* + bar*", `"foo*" AND "bar*"`],
["(foo + bar) -baz", `"(foo" AND "bar)" AND "-baz"`],
["foo* + bar*", `"foo*" AND "+" AND "bar*"`],
["(foo + bar) -baz", `"(foo" AND "+" AND "bar)" AND "-baz"`],
['"phrase with "quotes""', '"phrase with ""quotes"""'],
['foo + "bar -baz" OR "qux*"', `foo AND "bar -baz" OR "qux*"`],
["foo + bar + ", `foo AND bar`],
['foo + "bar -baz" OR "qux*"', `foo AND "+" AND "bar -baz" OR "qux*"`],
["foo + bar + ", `foo AND "+" AND bar AND "+"`],
["+foo bar", `"+foo" AND bar`],
["foo*bar*", `"foo*bar*"`],
['"escaped "quotes""', '"escaped ""quotes"""'],
@@ -65,12 +68,12 @@ const TRANSFORM_QUERY_TESTS: [string, string][] = [
["*helo*", `"*helo*"`],
[">he", `">he"`],
["something<hello", `"something<hello"`],
["<", ``],
[">", ``]
["<", `"<"`],
[">", `">"`]
];
for (const [input, expectedOutput] of TRANSFORM_QUERY_TESTS) {
test(`should transform "${input}" into a valid SQL query`, () => {
expect(transformQuery(input).query).toBe(expectedOutput);
expect(transformQuery(input).content?.query).toBe(expectedOutput);
});
}