Skip to content

Commit bcf7d4f

Browse files
committed
Make analyzer tests work
There's a known limitation in ArangoDB 3.5.0 with some analyzer API routes only supporting prefixed or unprefixed names.
1 parent 10dddc6 commit bcf7d4f

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

src/test/28-accessing-analyzers.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const ARANGO_VERSION = Number(process.env.ARANGO_VERSION || 30500);
77
const describe35 = ARANGO_VERSION >= 30500 ? describe : describe.skip;
88

99
describe35("Accessing analyzers", function() {
10-
let name = `testdb_${Date.now()}`;
10+
const builtins: string[] = [];
11+
const name = `testdb_${Date.now()}`;
1112
let db: Database;
1213
before(async () => {
1314
db = new Database({
@@ -16,6 +17,8 @@ describe35("Accessing analyzers", function() {
1617
});
1718
await db.createDatabase(name);
1819
db.useDatabase(name);
20+
builtins.push(...(await db.listAnalyzers()).map(a => a.name));
21+
expect(builtins).not.to.have.length(0);
1922
});
2023
after(async () => {
2124
try {
@@ -36,42 +39,53 @@ describe35("Accessing analyzers", function() {
3639
});
3740
});
3841
describe("database.listAnalyzers", () => {
39-
let analyzerNames = range(4).map(i => `a_${Date.now()}_${i}`);
42+
const analyzerNames = range(4).map(i => `${name}::a_${Date.now()}_${i}`);
43+
let allNames: string[];
4044
before(async () => {
45+
allNames = [...builtins, ...analyzerNames].sort();
4146
await Promise.all(
4247
analyzerNames.map(name =>
43-
db.analyzer(name).create({ type: "identity" })
48+
db.analyzer(name.replace(/^[^:]+::/, "")).create({ type: "identity" })
4449
)
4550
);
4651
});
4752
after(async () => {
48-
await Promise.all(analyzerNames.map(name => db.analyzer(name).drop()));
53+
await Promise.all(
54+
analyzerNames.map(name =>
55+
db.analyzer(name.replace(/^[^:]+::/, "")).drop()
56+
)
57+
);
4958
});
5059
it("fetches information about all analyzers", async () => {
5160
const analyzers = await db.listAnalyzers();
52-
expect(analyzers.length).to.equal(analyzerNames.length);
53-
expect(analyzers.map(a => a.name).sort()).to.eql(analyzerNames);
61+
console.log(analyzers.map(a => a.name), allNames);
62+
expect(analyzers.map(a => a.name).sort()).to.eql(allNames);
5463
});
5564
});
5665
describe("database.analyzers", () => {
57-
let analyzerNames = range(4).map(i => `a_${Date.now()}_${i}`);
66+
const analyzerNames = range(4).map(i => `${name}::a_${Date.now()}_${i}`);
67+
let allNames: string[];
5868
before(async () => {
69+
allNames = [...builtins, ...analyzerNames].sort();
5970
await Promise.all(
6071
analyzerNames.map(name =>
61-
db.analyzer(name).create({ type: "identity" })
72+
db.analyzer(name.replace(/^[^:]+::/, "")).create({ type: "identity" })
6273
)
6374
);
6475
});
6576
after(async () => {
66-
await Promise.all(analyzerNames.map(name => db.analyzer(name).drop()));
77+
await Promise.all(
78+
analyzerNames.map(name =>
79+
db.analyzer(name.replace(/^[^:]+::/, "")).drop()
80+
)
81+
);
6782
});
6883
it("creates ArangoAnalyzer instances", async () => {
6984
const analyzers = await db.analyzers();
70-
let arangoAnalyzers = analyzers
71-
.filter(a => a instanceof ArangoAnalyzer)
72-
.sort();
73-
expect(arangoAnalyzers.length).to.equal(analyzerNames.length);
74-
expect(arangoAnalyzers.map(a => a.name).sort()).to.eql(analyzerNames);
85+
for (const analyzer of analyzers) {
86+
expect(analyzer).to.be.instanceOf(ArangoAnalyzer);
87+
}
88+
expect(analyzers.map(a => a.name).sort()).to.eql(allNames);
7589
});
7690
});
7791
});

src/test/29-manipulating-analyzers.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const ARANGO_VERSION = Number(process.env.ARANGO_VERSION || 30500);
66
const describe35 = ARANGO_VERSION >= 30500 ? describe : describe.skip;
77

88
describe35("Manipulating analyzers", function() {
9-
let db: Database;
109
const name = `testdb_${Date.now()}`;
10+
let db: Database;
1111
before(async () => {
1212
db = new Database({
1313
url: process.env.TEST_ARANGODB_URL || "http://localhost:8529",
@@ -43,15 +43,16 @@ describe35("Manipulating analyzers", function() {
4343
});
4444
it("fetches information about the analyzer", async () => {
4545
const data = await analyzer.get();
46-
expect(data).to.have.property("name", analyzer.name);
46+
expect(data).to.have.property("name", `${name}::${analyzer.name}`);
4747
});
4848
});
4949
describe("analyzer.create", () => {
5050
it("creates the analyzer", async () => {
5151
const analyzer = db.analyzer(`a_${Date.now()}`);
5252
await analyzer.create({ type: "identity" });
5353
const data = await analyzer.get();
54-
expect(data).to.have.property("name", `${db.name}::${analyzer.name}`);
54+
expect(data).to.have.property("name", `${name}::${analyzer.name}`);
55+
expect(data).to.have.property("type", "identity");
5556
});
5657
});
5758
describe("analyzer.drop", () => {
@@ -62,12 +63,7 @@ describe35("Manipulating analyzers", function() {
6263
});
6364
it("destroys the analyzer", async () => {
6465
await analyzer.drop();
65-
try {
66-
await analyzer.get();
67-
} catch (e) {
68-
expect(await analyzer.exists()).to.equal(false);
69-
}
70-
expect.fail();
66+
expect(await analyzer.exists()).to.equal(false);
7167
});
7268
});
7369
});

0 commit comments

Comments
 (0)