|
1 | | -import { expectType } from 'tsd' |
| 1 | +import { expect, test } from 'tstyche' |
2 | 2 |
|
3 | 3 | import { InternalTypedDocument, Orama, PartialSchemaDeep, Results, Schema, SearchParams, TypedDocument } from '@orama/orama' |
4 | 4 | import Fastify from 'fastify' |
@@ -43,35 +43,45 @@ app.register(fastifyOrama, { |
43 | 43 | }) |
44 | 44 |
|
45 | 45 | const appWithOrama = app.withOrama<typeof mySchema>() |
46 | | -appWithOrama.orama.insert({ quote: 'Hello', author: 'World' }).then(id => { |
47 | | - expectType<string>(id) |
| 46 | + |
| 47 | +test('should enable the insertion of documents', () => { |
| 48 | + appWithOrama.orama.insert({ quote: 'Hello', author: 'World' }).then(id => { |
| 49 | + expect(id).type.toBe<string>() |
| 50 | + }) |
48 | 51 | }) |
49 | 52 |
|
50 | | -appWithOrama.get('/hello', async () => { |
| 53 | +test('should enable the searching of documents', () => { |
| 54 | + appWithOrama.get('/hello', async () => { |
51 | 55 |
|
52 | | - const {orama} = appWithOrama |
53 | | - const result = await orama.search({ term: 'hello' }) |
| 56 | + const {orama} = appWithOrama |
| 57 | + const result = await orama.search({ term: 'hello' }) |
54 | 58 |
|
55 | | - expectType<Results<InternalTypedDocument<MySchema>>>(result) |
56 | | - expectType<string>(result.hits[0].document.author) |
| 59 | + expect(result).type.toBe<Results<InternalTypedDocument<MySchema>>>() |
| 60 | + expect(result.hits[0].document.author).type.toBe<string>() |
57 | 61 |
|
58 | | - return { |
59 | | - hello: result.hits |
60 | | - } |
| 62 | + return { |
| 63 | + hello: result.hits |
| 64 | + } |
| 65 | + }) |
61 | 66 | }) |
62 | 67 |
|
63 | | -expectType<{ |
64 | | - insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>, |
65 | | - search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>, |
66 | | - persist?: () => Promise<any>, |
67 | | -}>(appWithOrama.orama) |
68 | | - |
69 | | -fp(function(fastify) { |
70 | | - const fastifyWithOrama = fastify.withOrama<typeof mySchema>() |
71 | | - |
72 | | - expectType<{ |
| 68 | +test('should expose the Orama API', () => { |
| 69 | + expect(appWithOrama.orama).type.toBe<{ |
73 | 70 | insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>, |
74 | 71 | search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>, |
75 | 72 | persist?: () => Promise<any>, |
76 | | - }>(fastifyWithOrama.orama) |
| 73 | + }>() |
| 74 | +}) |
| 75 | + |
| 76 | + |
| 77 | +test('should enable the withOrama method', () => { |
| 78 | + fp(function(fastify) { |
| 79 | + const fastifyWithOrama = fastify.withOrama<typeof mySchema>() |
| 80 | + |
| 81 | + expect(fastifyWithOrama.orama).type.toBe<{ |
| 82 | + insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>, |
| 83 | + search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>, |
| 84 | + persist?: () => Promise<any>, |
| 85 | + }>() |
| 86 | + }) |
77 | 87 | }) |
0 commit comments