Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adds tests for Orama Switch #787

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"*.png",
"*.svg",
"*.xml",
"*.ico"
"*.ico",
"./packages/tokenizers"
],
"maxSize": 10000000000
},
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"trailingComma": "none",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
18 changes: 9 additions & 9 deletions packages/orama/tests/levenshtein.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,34 +198,34 @@ t.test('syncBoundedLevenshtein substrings are ok even if with tolerance pppppp',
t.test('Issue #744', async (t) => {
const index = await create({
schema: {
libelle: 'string',
libelle: 'string'
} as const
})

await insertMultiple(index, [
{libelle: 'ABRICOT MOELLEUX'},
{libelle: 'MOELLEUX CHOC BIO'},
{libelle: 'CREPE MOELLEUSE'},
{libelle: 'OS MOELLE'},
{ libelle: 'ABRICOT MOELLEUX' },
{ libelle: 'MOELLEUX CHOC BIO' },
{ libelle: 'CREPE MOELLEUSE' },
{ libelle: 'OS MOELLE' }
])

const s1 = await search(index, {
term: 'moelleux',
term: 'moelleux'
})

const s2 = await search(index, {
term: 'moelleux',
tolerance: 1,
threshold: 0,
threshold: 0
})

const s3 = await search(index, {
term: 'moelleux',
tolerance: 2,
threshold: 0,
threshold: 0
})

t.equal(s1.count, 2)
t.equal(s2.count, 1)
t.equal(s3.count, 4)
})
})
6 changes: 4 additions & 2 deletions packages/switch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"files": ["dist"],
"scripts": {
"build": "tsup"
"build": "tsup",
"test": "tsx --test tests/search.test.ts"
},
"keywords": ["orama", "orama cloud"],
"type": "module",
Expand All @@ -30,6 +31,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"tsup": "^7.2.0"
"tsup": "^7.2.0",
"tsx": "^4.19.0"
}
}
54 changes: 54 additions & 0 deletions packages/switch/tests/search.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { OramaClient } from '@oramacloud/client'
import { create, insertMultiple } from '@orama/orama'
import { Switch } from '../src/index.js'

test('local client', async () => {
const db = await create({
schema: {
name: 'string',
age: 'number'
} as const
})

await insertMultiple(db, [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 40 },
{ name: 'Charlie', age: 50 }
])

const client = new Switch(db)

const r1 = await client.search({ term: 'Alice' })
const r2 = await client.search({ term: 'Bob', where: { age: { eq: 40 } } })
const r3 = await client.search({ term: 'Charlie', where: { age: { lte: 10 } } })

assert.deepStrictEqual(r1?.hits[0].document, { name: 'Alice', age: 30 })
assert.deepStrictEqual(r2?.hits[0].document, { name: 'Bob', age: 40 })
assert.strictEqual(r3?.count, 0)
})

test('remote client', async (t) => {
const CLOUD_URL = process.env.ORAMA_CLOUD_E2E_URL
const CLOUD_API_KEY = process.env.ORAMA_CLOUD_E2E_API_KEY

if (!CLOUD_URL || !CLOUD_API_KEY) {
console.log(
'Skipping Orama Switch remote client test since ORAMA_CLOUD_E2E_URL and ORAMA_CLOUD_E2E_API_KEY are not set'
)
t.skip('Environment variables not set')
return
}

const orama = new OramaClient({
api_key: CLOUD_API_KEY,
endpoint: CLOUD_URL
})

const client = new Switch(orama)

const r1 = await client.search({ term: 'Orama Cloud' })

assert.ok(r1!.count > 0)
})
Loading
Loading