|
| 1 | +import { assert } from 'console'; |
| 2 | +import weaviate, { |
| 3 | + WeaviateClient, |
| 4 | +} from '..'; |
| 5 | +import { requireAtLeast } from '../../test/version'; |
| 6 | +import { Alias } from './types'; |
| 7 | + |
| 8 | +requireAtLeast(1, 32, 0).describe("manages collection aliases", () => { |
| 9 | + let client: WeaviateClient; |
| 10 | + const collectionsWithAliases = ["PaulHewson", "GeorgeBarnes", "ColsonBaker"]; |
| 11 | + |
| 12 | + beforeAll(async () => { |
| 13 | + client = await weaviate.connectToLocal(); |
| 14 | + await Promise.all(collectionsWithAliases.map(client.collections.delete)); |
| 15 | + await Promise.all(collectionsWithAliases.map(name => client.collections.create({ name }))); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should create alias", () => { |
| 19 | + return Promise.all([ |
| 20 | + client.alias.create({ collection: "PaulHewson", alias: "Bono" }), |
| 21 | + client.alias.create({ collection: "GeorgeBarnes", alias: "MachineGunKelly" }), |
| 22 | + ]) |
| 23 | + .then(() => client.alias.listAll()) |
| 24 | + .then(aliases => { |
| 25 | + expect(aliases).not.toBeUndefined(); |
| 26 | + expect(aliases).toHaveLength(2); |
| 27 | + expect(aliases).toEqual<Alias[]>([ |
| 28 | + { collection: "PaulHewson", alias: "Bono" }, |
| 29 | + { collection: "GeorgeBarnes", alias: "MachineGunKelly" }, |
| 30 | + ]); |
| 31 | + }); |
| 32 | + }) |
| 33 | + |
| 34 | + it("should update alias", () => { |
| 35 | + return client.alias.update({ alias: "MachineGunKelly", newTargetCollection: "ColsonBaker" }) |
| 36 | + .then(() => client.alias.get("MachineGunKelly")) |
| 37 | + .then(alias => { |
| 38 | + expect(alias.collection).toEqual("ColsonBaker"); |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + it("should delete alias Bono", () => { |
| 43 | + return client.alias.delete("Bono") |
| 44 | + .then(() => client.alias.listAll("PaulHewson")) |
| 45 | + .then(aliases => expect(aliases).toEqual([])); |
| 46 | + }) |
| 47 | + |
| 48 | + it("should delete alias MachineGunKelly", () => { |
| 49 | + return client.alias.delete("MachineGunKelly") |
| 50 | + .then(() => client.alias.listAll("ColsonBaker")) |
| 51 | + .then(aliases => expect(aliases).toEqual([])); |
| 52 | + }) |
| 53 | +}) |
0 commit comments