Skip to content

Commit cdf1016

Browse files
committed
Add additional collection tests
1 parent ee9aecc commit cdf1016

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

__tests__/collection.test.ts

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,84 @@ import { describe, test } from "mocha";
33
import { expect } from "chai";
44

55
const { ASTRA_DB_TOKEN, ASTRA_DB_ID } = process.env;
6+
const epoch = new Date().getTime();
67

78
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+
})
818
describe("Namespaces", () => {
919
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 });
1829
const countResults = await astra
1930
.collection("test")
2031
.countDocuments();
2132
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 });
2284
});
2385
});
2486
});

0 commit comments

Comments
 (0)