@@ -3,22 +3,84 @@ 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 ( "Collections" , ( ) => {
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 ( "Namespaces" , ( ) => {
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 : "test" } ) ;
20
+ const collectionName = `test${ epoch } ` ;
21
+ const results = await astra . createCollection ( { name : collectionName } ) ;
22
+ console . log ( results )
23
+ expect ( results . status . ok ) . to . equal ( 1 ) ;
24
+ await astra . deleteCollection ( { name : collectionName } ) ;
25
+ } ) ;
26
+ test ( "should count collection results" , async ( ) => {
27
+ const collectionName = `test${ epoch } ` ;
28
+ const results = await astra . createCollection ( { name : collectionName } ) ;
18
29
const countResults = await astra
19
30
. collection ( "test" )
20
31
. countDocuments ( ) ;
21
32
expect ( countResults . status . count ) . to . be . greaterThan ( 0 ) ;
33
+ await astra . deleteCollection ( { name : collectionName } ) ;
34
+ } ) ;
35
+ test ( "should insert one" , async ( ) => {
36
+ const collectionName = `test${ epoch } ` ;
37
+ await astra . createCollection ( { name : collectionName } ) ;
38
+ const insertResults = await astra . collection ( collectionName ) . insertOne ( {
39
+ document : {
40
+ name : "Alex" ,
41
+ age : 31 ,
42
+ } ,
43
+ } ) ;
44
+ expect ( insertResults . status . insertedIds ) . length . to . be . greaterThan ( 0 ) ;
45
+ await astra . deleteCollection ( { name : collectionName } ) ;
46
+ } ) ;
47
+ test ( "should insert many" , async ( ) => {
48
+ const collectionName = `test${ epoch } ` ;
49
+ await astra . createCollection ( { name : collectionName } ) ;
50
+ const insertResults = await astra . collection ( collectionName ) . insertMany ( {
51
+ documents : [ {
52
+ name : "Alex" ,
53
+ age : 31 ,
54
+ } , {
55
+ name : "Claire" ,
56
+ age : 31 ,
57
+ } ] ,
58
+ } ) ;
59
+ expect ( insertResults . status . insertedIds ) . length . to . have . length ( 2 ) ;
60
+ await astra . deleteCollection ( { name : collectionName } ) ;
61
+ } ) ;
62
+ test ( "should update one" , async ( ) => {
63
+ const collectionName = `test${ epoch } ` ;
64
+ await astra . createCollection ( { name : collectionName } ) ;
65
+ const insertResults = await astra . collection ( collectionName ) . insertOne ( {
66
+ document : {
67
+ name : "Alex" ,
68
+ age : 1 ,
69
+ }
70
+ } ) ;
71
+ const updateResults = await astra . collection ( collectionName ) . updateOne ( {
72
+ filter : {
73
+ name : "Alex" ,
74
+ } ,
75
+ update : {
76
+ '$set' : {
77
+ age : 2 ,
78
+ }
79
+ }
80
+ } ) ;
81
+ console . log ( updateResults ) ;
82
+ // expect(insertResults.status.insertedIds).length.to.have.length(2);
83
+ // await astra.deleteCollection({ name: collectionName });
22
84
} ) ;
23
85
} ) ;
24
86
} ) ;
0 commit comments