aboutsummaryrefslogtreecommitdiff
path: root/packages/db/test/unit/db-client.test.js
blob: 22df2610e49a960a426da9e15ba3ae28c5bc9ed2 (plain) (blame)
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
import assert from 'node:assert';
import test, { describe } from 'node:test';
import { parseOpts } from '../../dist/runtime/db-client.js';

describe('db client config', () => {
	test('parse config options from URL (docs example url)', () => {
		const remoteURLToParse = new URL(
			'file://local-copy.db?encryptionKey=your-encryption-key&syncInterval=60&syncUrl=libsql%3A%2F%2Fyour.server.io',
		);
		const options = Object.fromEntries(remoteURLToParse.searchParams.entries());

		const config = parseOpts(options);

		assert.deepEqual(config, {
			encryptionKey: 'your-encryption-key',
			syncInterval: 60,
			syncUrl: 'libsql://your.server.io',
		});
	});

	test('parse config options from URL (test booleans without value)', () => {
		const remoteURLToParse = new URL('file://local-copy.db?readYourWrites&offline&tls');
		const options = Object.fromEntries(remoteURLToParse.searchParams.entries());

		const config = parseOpts(options);

		assert.deepEqual(config, {
			readYourWrites: true,
			offline: true,
			tls: true,
		});
	});

	test('parse config options from URL (test booleans with value)', () => {
		const remoteURLToParse = new URL(
			'file://local-copy.db?readYourWrites=true&offline=true&tls=true',
		);
		const options = Object.fromEntries(remoteURLToParse.searchParams.entries());

		const config = parseOpts(options);

		assert.deepEqual(config, {
			readYourWrites: true,
			offline: true,
			tls: true,
		});
	});

	test('parse config options from URL (test numbers)', () => {
		const remoteURLToParse = new URL('file://local-copy.db?syncInterval=60&concurrency=2');
		const options = Object.fromEntries(remoteURLToParse.searchParams.entries());

		const config = parseOpts(options);

		assert.deepEqual(config, {
			syncInterval: 60,
			concurrency: 2,
		});
	});
});