diff options
author | 2025-05-09 21:47:04 -0700 | |
---|---|---|
committer | 2025-05-10 05:47:04 +0100 | |
commit | 83193d43cfb7fb28254f0ff3fb717a7bdd65977b (patch) | |
tree | 9196c816b6bbe305a716138064dbe83aa44faf58 /packages/db/test/unit/db-client.test.js | |
parent | 527f5c93541df1590b506c82107c348ece822cdc (diff) | |
download | astro-83193d43cfb7fb28254f0ff3fb717a7bdd65977b.tar.gz astro-83193d43cfb7fb28254f0ff3fb717a7bdd65977b.tar.zst astro-83193d43cfb7fb28254f0ff3fb717a7bdd65977b.zip |
Fix(db): update db-client connection options parsing (#13772)
* update AstroDB client
* Update packages/db/src/runtime/db-client.ts
Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
* add test
* fix function to ensure only values that are passed are actually being passed
---------
Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
Diffstat (limited to 'packages/db/test/unit/db-client.test.js')
-rw-r--r-- | packages/db/test/unit/db-client.test.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/packages/db/test/unit/db-client.test.js b/packages/db/test/unit/db-client.test.js new file mode 100644 index 000000000..ac41aa07f --- /dev/null +++ b/packages/db/test/unit/db-client.test.js @@ -0,0 +1,56 @@ +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 + }) + }) +})
\ No newline at end of file |