-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathschema.test.js
51 lines (41 loc) · 1.07 KB
/
schema.test.js
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
import { describe, test, beforeAll, expect } from 'vitest';
const map = require('./db');
const initPg = require('./initPg');
beforeAll(async () => {
await insertData('pg');
async function insertData(dbName) {
const { db, init } = getDb(dbName);
await init(db);
}
});
describe('search path custom', () => {
test('pgWithSchema', async () => await verify('pgWithSchema'));
async function verify(dbName) {
const { db } = getDb(dbName);
const customer = await db.withSchema.insert({
name: 'Voldemort',
});
const expected = {
id: 1,
name: 'Voldemort',
};
expect(customer).toEqual(expected);
}
});
const connections = {
pg: {
db: map({ db: con => con.postgres('postgres://postgres:postgres@postgres/postgres', { size: 1 }) }),
init: initPg
},
pgWithSchema: {
db: map({ db: con => con.postgres('postgres://postgres:postgres@postgres/postgres?search_path=custom', { size: 1 }) }),
}
};
function getDb(name) {
if (name === 'pg')
return connections.pg;
if (name === 'pgWithSchema')
return connections.pgWithSchema;
else
throw new Error('unknown');
}