@@ -3,31 +3,30 @@ import { describe, test } from "mocha";
3
3
import { expect } from "chai" ;
4
4
5
5
const { ASTRA_DB_TOKEN , ASTRA_DB_ID } = process . env ;
6
+ const epoch = new Date ( ) . getTime ( ) ;
6
7
7
8
describe ( "Astra" , ( ) => {
9
+ let astra ;
10
+ before ( async ( ) => {
11
+ astra = new Astra ( {
12
+ token : ASTRA_DB_TOKEN ,
13
+ databaseId : ASTRA_DB_ID ,
14
+ databaseRegion : "us-east1" ,
15
+ namespace : "test" ,
16
+ } ) ;
17
+ } )
8
18
describe ( "Collections" , ( ) => {
9
19
test ( "should create collection" , async ( ) => {
10
- const astra = new Astra ( {
11
- token : ASTRA_DB_TOKEN ,
12
- databaseId : ASTRA_DB_ID ,
13
- databaseRegion : "us-east1" ,
14
- namespace : "test" ,
15
- } ) ;
16
-
17
- const results = await astra . createCollection ( { name : "blah" } ) ;
20
+ const collectionName = `test${ epoch } ` ;
21
+ const results = await astra . createCollection ( { name : collectionName } ) ;
18
22
expect ( results . status . ok ) . to . equal ( 1 ) ;
23
+ await astra . deleteCollection ( { name : collectionName } ) ;
19
24
} ) ;
20
25
21
26
test ( "should create vector collection" , async ( ) => {
22
- const astra = new Astra ( {
23
- token : ASTRA_DB_TOKEN ,
24
- databaseId : ASTRA_DB_ID ,
25
- databaseRegion : "us-east1" ,
26
- namespace : "test" ,
27
- } ) ;
28
-
27
+ const collectionName = `test${ epoch } ` ;
29
28
const results = await astra . createCollection ( {
30
- name : "blahs" ,
29
+ name : collectionName ,
31
30
options : {
32
31
vector : {
33
32
size : 2 ,
@@ -36,28 +35,26 @@ describe("Astra", () => {
36
35
} ,
37
36
} ) ;
38
37
expect ( results . status . ok ) . to . equal ( 1 ) ;
38
+ await astra . deleteCollection ( { name : collectionName } ) ;
39
39
} ) ;
40
40
41
41
test ( "should find collections" , async ( ) => {
42
- const astra = new Astra ( {
43
- token : ASTRA_DB_TOKEN ,
44
- databaseId : ASTRA_DB_ID ,
45
- databaseRegion : "us-east1" ,
46
- namespace : "test" ,
42
+ const collectionName = `test${ epoch } ` ;
43
+ await astra . createCollection ( {
44
+ name : collectionName ,
45
+ options : {
46
+ vector : {
47
+ size : 2 ,
48
+ function : "cosine" ,
49
+ } ,
50
+ } ,
47
51
} ) ;
48
-
49
52
const results = await astra . findCollections ( ) ;
50
- expect ( results . status . collections [ 0 ] ) . to . equal ( "blah" ) ;
53
+ expect ( results . status . collections [ 0 ] ) . to . equal ( collectionName ) ;
54
+ await astra . deleteCollection ( { name : collectionName } ) ;
51
55
} ) ;
52
56
53
57
test ( "should delete collection that doesn't exist" , async ( ) => {
54
- const astra = new Astra ( {
55
- token : ASTRA_DB_TOKEN ,
56
- databaseId : ASTRA_DB_ID ,
57
- databaseRegion : "us-east1" ,
58
- namespace : "test" ,
59
- } ) ;
60
-
61
58
const collection = await astra . deleteCollection ( { name : "bah" } ) ;
62
59
expect ( collection . status . ok ) . to . equal ( 1 ) ;
63
60
} ) ;
0 commit comments