-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-seafowl.test.ts
92 lines (82 loc) · 2.45 KB
/
db-seafowl.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { describe, it, expect } from "vitest";
import { makeDb } from "./db-seafowl";
import { SeafowlImportFilePlugin } from "./plugins/importers/seafowl-import-file-plugin";
import { shouldSkipSeafowlTests } from "@madatdata/test-helpers/env-config";
describe("importData", () => {
it("returns false for unknown plugin", async () => {
const examplePlugins = [
{
__name: "csv",
importData: () =>
Promise.resolve({ response: "import-ok", error: null, info: null }),
},
{
__name: "export-something", // NOTE: duplicate names intentional, they implement different interfaces
exportData: (_args: { foo?: string }) =>
Promise.resolve({ response: "export-ok", error: null, info: null }),
},
{
__name: "mongo",
importData: () =>
Promise.resolve({ response: "import-ok", error: null, info: null }),
},
];
const db = makeDb({
plugins: examplePlugins,
});
await expect(async () =>
// @ts-expect-error not a valid plugin
db.importData("unknown-doesnotexist", {}, {}).catch((err) => {
throw err;
})
).rejects.toThrowErrorMatchingInlineSnapshot(
'"plugin not found: unknown-doesnotexist"'
);
});
});
const createDb = () => {
// const transformRequestHeaders = vi.fn((headers) => ({
// ...headers,
// foobar: "fizzbuzz",
// }));
const db = makeDb({
database: {
dbname: "default",
},
authenticatedCredential: {
// @ts-expect-error https://stackoverflow.com/a/70711231
token: import.meta.env.VITE_TEST_SEAFOWL_SECRET,
anonymous: false,
},
host: {
// temporary hacky mess
dataHost: "127.0.0.1:8080",
apexDomain: "bogus",
apiHost: "bogus",
baseUrls: {
gql: "bogus",
sql: "http://127.0.0.1:8080",
auth: "bogus",
},
postgres: {
host: "127.0.0.1",
port: 6432,
ssl: false,
},
},
plugins: [new SeafowlImportFilePlugin({})],
});
return db;
};
describe.skipIf(shouldSkipSeafowlTests())("seafowl stub test", () => {
it("can fingerprint with sha256 by default", async () => {
const db = createDb();
const fingerprint = await db.fingerprintQuery("select 1");
expect(fingerprint).toMatchInlineSnapshot(`
{
"fingerprint": "822ae07d4783158bc1912bb623e5107cc9002d519e1143a9c200ed6ee18b6d0f",
"normalized": "select 1",
}
`);
});
});