1
1
import { IndexifyClient } from "../src" ;
2
2
import { IExtractionPolicy } from "../src/types" ;
3
3
import { isAxiosError } from "axios" ;
4
+
4
5
const fs = require ( "fs" ) ;
5
6
6
7
jest . setTimeout ( 30000 ) ;
7
8
9
+ function generateNanoId ( length : number = 21 ) : string {
10
+ const characters =
11
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
12
+ let result = "" ;
13
+ for ( let i = 0 ; i < length ; i ++ ) {
14
+ const randomIndex = Math . floor ( Math . random ( ) * characters . length ) ;
15
+ result += characters [ randomIndex ] ;
16
+ }
17
+ return result ;
18
+ }
19
+
8
20
test ( "Create Client" , async ( ) => {
9
21
const client = await IndexifyClient . createClient ( ) ;
10
22
expect ( client . namespace ) . toBe ( "default" ) ;
11
23
} ) ;
12
24
13
25
test ( "Create Namespace" , async ( ) => {
26
+ const nanoid = generateNanoId ( 8 ) ;
27
+ const namespaceName = `testnamespace.${ nanoid } ` ;
14
28
const client = await IndexifyClient . createNamespace ( {
15
- namespace : "testnamespace" ,
29
+ namespace : namespaceName ,
16
30
extraction_policies : [
17
31
{
32
+ id : nanoid ,
18
33
extractor : "tensorlake/minilm-l6" ,
19
- name : " testpolicy" ,
34
+ name : ` testpolicy` ,
20
35
} ,
21
36
] ,
37
+ } ) . catch ( ( e ) => {
38
+ if ( isAxiosError ( e ) ) {
39
+ console . log ( e . response ?. data ) ;
40
+ }
41
+ console . log ( "error creating namespace" ) ;
42
+ throw e ;
22
43
} ) ;
23
44
24
- expect ( client . namespace ) . toBe ( "testnamespace" ) ;
45
+ expect ( client . namespace ) . toBe ( namespaceName ) ;
25
46
// test get namespaces
26
47
const namespaces = await IndexifyClient . namespaces ( ) ;
27
- expect (
28
- namespaces . filter ( ( item ) => item . name === "testnamespace" ) . length
29
- ) . toBe ( 1 ) ;
48
+ expect ( namespaces . filter ( ( item ) => item . name === namespaceName ) . length ) . toBe (
49
+ 1
50
+ ) ;
30
51
} ) ;
31
52
32
53
test ( "Get Extractors" , async ( ) => {
@@ -36,8 +57,9 @@ test("Get Extractors", async () => {
36
57
} ) ;
37
58
38
59
test ( "Add Documents" , async ( ) => {
60
+ const nanoid = generateNanoId ( 8 ) ;
39
61
const client = await IndexifyClient . createNamespace ( {
40
- namespace : " test.adddocuments" ,
62
+ namespace : ` test.adddocuments. ${ nanoid } ` ,
41
63
} ) ;
42
64
43
65
// add single documents
@@ -71,14 +93,16 @@ test("Add Documents", async () => {
71
93
} ) ;
72
94
73
95
test ( "Search" , async ( ) => {
96
+ const nanoid = generateNanoId ( 8 ) ;
97
+
74
98
const policy : IExtractionPolicy = {
75
99
extractor : "tensorlake/minilm-l6" ,
76
- name : " minilml6" ,
100
+ name : ` minilml6. ${ nanoid } ` ,
77
101
labels_eq : "source:test" ,
78
102
} ;
79
103
80
104
const client = await IndexifyClient . createNamespace ( {
81
- namespace : " testsearch" ,
105
+ namespace : ` testsearch. ${ nanoid } ` ,
82
106
} ) ;
83
107
84
108
const resp = await client . addExtractionPolicy ( policy ) ;
@@ -91,9 +115,10 @@ test("Search", async () => {
91
115
{ text : "This is a test2" , labels : { source : "test" } } ,
92
116
] ) ;
93
117
94
- await new Promise ( ( r ) => setTimeout ( r , 15000 ) ) ;
118
+ await new Promise ( ( r ) => setTimeout ( r , 10000 ) ) ;
95
119
96
120
const searchResult = await client . searchIndex ( indexName , "test" , 3 ) ;
121
+ console . log ( searchResult ) ;
97
122
expect ( searchResult . length ) . toBe ( 2 ) ;
98
123
} ) ;
99
124
@@ -114,8 +139,9 @@ test("Upload file", async () => {
114
139
} ) ;
115
140
116
141
test ( "Get content" , async ( ) => {
142
+ const nanoid = generateNanoId ( 8 ) ;
117
143
const client = await IndexifyClient . createNamespace ( {
118
- namespace : " testgetcontent" ,
144
+ namespace : ` testgetcontent. ${ nanoid } ` ,
119
145
} ) ;
120
146
await client . addDocuments ( [
121
147
{ text : "This is a test1" , labels : { source : "test" } } ,
@@ -136,8 +162,9 @@ test("Get content", async () => {
136
162
} ) ;
137
163
138
164
test ( "Download content" , async ( ) => {
165
+ const nanoid = generateNanoId ( 8 ) ;
139
166
const client = await IndexifyClient . createNamespace ( {
140
- namespace : " testgetcontent" ,
167
+ namespace : ` testgetcontent. ${ nanoid } ` ,
141
168
} ) ;
142
169
await client . addDocuments ( [
143
170
{ text : "This is a download" , labels : { source : "testdownload" } } ,
@@ -175,7 +202,7 @@ test("Ingest remote url", async () => {
175
202
) ;
176
203
} ) ;
177
204
178
- test . only ( "Test Extract Method" , async ( ) => {
205
+ test ( "Test Extract Method" , async ( ) => {
179
206
// Test minilm feature extract
180
207
const client = await IndexifyClient . createClient ( ) ;
181
208
const res = await client . extract ( {
0 commit comments