Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion data/checker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { buildObjectsPath } from "./path";

export default class Checker {
constructor(client) {
this.client = client;
Expand All @@ -9,6 +11,11 @@ export default class Checker {
return this;
};

withClassName = (className) => {
this.className = className;
return this;
};

validateIsSet = (prop, name, setter) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.errors = [
Expand All @@ -34,7 +41,7 @@ export default class Checker {
}
this.validate();

const path = `/objects/${this.id}`;
const path = buildObjectsPath(this.id, this.className);
return this.client.head(path);
};
}
9 changes: 8 additions & 1 deletion data/deleter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { buildObjectsPath } from "./path";

export default class Deleter {
constructor(client) {
this.client = client;
Expand All @@ -9,6 +11,11 @@ export default class Deleter {
return this;
};

withClassName = (className) => {
this.className = className;
return this;
}

validateIsSet = (prop, name, setter) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.errors = [
Expand All @@ -34,7 +41,7 @@ export default class Deleter {
}
this.validate();

const path = `/objects/${this.id}`;
const path = buildObjectsPath(this.id, this.className);
return this.client.delete(path);
};
}
10 changes: 9 additions & 1 deletion data/getterById.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { buildObjectsPath } from "./path";

export default class GetterById {
constructor(client) {
this.client = client;
Expand All @@ -10,6 +12,11 @@ export default class GetterById {
return this;
};

withClassName = (className) => {
this.className = className;
return this;
};

extendAdditionals = (prop) => {
this.additionals = [...this.additionals, prop];
return this;
Expand Down Expand Up @@ -45,7 +52,8 @@ export default class GetterById {
);
}

let path = `/objects/${this.id}`;
let path = buildObjectsPath(this.id, this.className);

if (this.additionals.length > 0) {
path += `?include=${this.additionals.join(",")}`;
}
Expand Down
117 changes: 107 additions & 10 deletions data/journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("gets one thing by id", () => {
it("gets one thing by id only", () => {
return client.data
.getterById()
.withId("1565c06c-463f-466c-9092-5930dbac3887")
Expand All @@ -178,6 +178,34 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("gets one thing by id and class name", () => {
return client.data
.getterById()
.withClassName(thingClassName)
.withId("1565c06c-463f-466c-9092-5930dbac3887")
.do()
.then((res) => {
expect(res).toEqual(
expect.objectContaining({
id: "1565c06c-463f-466c-9092-5930dbac3887",
properties: { stringProp: "with-id" },
})
);
})
.catch((e) => fail("it should not have errord: " + e));
});

it("fails to get one thing by id with invalid class name", () => {
return client.data
.getterById()
.withClassName("DoesNotExist")
.withId("1565c06c-463f-466c-9092-5930dbac3887")
.do()
.catch(err =>
expect(err).toEqual("usage error (500): {\"error\":[{\"message\":\"repo: object by id: index not found for class DoesNotExist\"}]}")
);
});

it("gets one thing by id with all optional additional props", () => {
return client.data
.getterById()
Expand Down Expand Up @@ -211,7 +239,7 @@ describe("data", () => {
});
});

it("updates a thing", () => {
it("updates a thing by id only", () => {
const id = "1565c06c-463f-466c-9092-5930dbac3887";
return client.data
.getterById()
Expand All @@ -236,6 +264,31 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("updates a thing by id and class name", () => {
const id = "1565c06c-463f-466c-9092-5930dbac3887";
return client.data
.getterById()
.withId(id)
.withClassName(thingClassName)
.do()
.then((res) => {
const properties = res.properties;
properties.stringProp = "thing-updated-with-class-name";
return client.data
.updater()
.withId(id)
.withClassName(thingClassName)
.withProperties(properties)
.do();
})
.then((res) => {
expect(res.properties).toEqual({
stringProp: "thing-updated-with-class-name",
});
})
.catch((e) => fail("it should not have errord: " + e));
});

it("merges a thing", () => {
const id = "1565c06c-463f-466c-9092-5930dbac3887";
return client.data
Expand Down Expand Up @@ -301,7 +354,7 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("checks that object exists", () => {
it("checks that object exists by id only", () => {
return client.data
.checker()
.withId("1565c06c-463f-466c-9092-5930dbac3887")
Expand All @@ -314,15 +367,29 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("deletes a thing", () => {
it("checks that object exists by id and class name", () => {
return client.data
.checker()
.withId("1565c06c-463f-466c-9092-5930dbac3887")
.withClassName(thingClassName)
.do()
.then((exists) => {
if (!exists) {
fail("it should exist in DB")
}
})
.catch((e) => fail("it should not have errord: " + e));
});

it("deletes a thing by id only", () => {
return client.data
.deleter()
.withId("1565c06c-463f-466c-9092-5930dbac3887")
.do()
.catch((e) => fail("it should not have errord: " + e));
});

it("checks that object doesn't exist anymore", () => {
it("checks that object doesn't exist anymore with delete by id only", () => {
return client.data
.checker()
.withId("1565c06c-463f-466c-9092-5930dbac3887")
Expand All @@ -335,11 +402,41 @@ describe("data", () => {
.catch((e) => fail("it should not have errord: " + e));
});

it("waits for es index updates", () => {
return new Promise((resolve, reject) => {
// TODO: remove in 1.0.0
setTimeout(resolve, 1000);
});
it("deletes a thing with id and class name", async () => {
const properties = { stringProp: "with-id" };
const id = "6781a974-cfbf-455d-ace8-f1dba4564230";

await client.data
.creator()
.withClassName(thingClassName)
.withProperties(properties)
.withId(id)
.do()
.then((res) => {
expect(res.properties).toEqual(properties);
expect(res.id).toEqual(id);
})
.catch((e) => fail("it should not have errord: " + e));

return client.data
.deleter()
.withId(id)
.withClassName(thingClassName)
.do()
.catch((e) => fail("it should not have errord: " + e));
})

it("checks that object doesn't exist anymore with delete by id and class name", () => {
return client.data
.checker()
.withId("6781a974-cfbf-455d-ace8-f1dba4564230")
.do()
.then((exists) => {
if (exists) {
fail("it should not exist in DB")
}
})
.catch((e) => fail("it should not have errord: " + e));
});

it("verifies there are now fewer things (after delete)", () => {
Expand Down
4 changes: 3 additions & 1 deletion data/merger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isValidStringProperty } from "../validation/string";
import { buildObjectsPath } from "./path";

export default class Merger {
constructor(client) {
Expand Down Expand Up @@ -55,7 +56,8 @@ export default class Merger {
new Error("invalid usage: " + this.errors.join(", "))
);
}
const path = `/objects/${this.id}`;

const path = buildObjectsPath(this.id, this.className);
return this.client.patch(path, this.payload());
};
}
9 changes: 9 additions & 0 deletions data/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { isValidStringProperty } from "../validation/string";

export function buildObjectsPath(id, className) {
let path = `objects`;
if (isValidStringProperty(className)) {
path = `${path}/${className}`;
}
return `/${path}/${id}`;
}
6 changes: 4 additions & 2 deletions data/updater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isValidStringProperty } from "../validation/string";
import { buildObjectsPath } from "./path";

export default class Updater {
constructor(client) {
Expand All @@ -25,7 +26,7 @@ export default class Updater {
if (!isValidStringProperty(this.className)) {
this.errors = [
...this.errors,
"className must be set - set with withId(id)",
"className must be set - use withClassName(className)",
];
}
};
Expand Down Expand Up @@ -58,7 +59,8 @@ export default class Updater {
new Error("invalid usage: " + this.errors.join(", "))
);
}
const path = `/objects/${this.id}`;

const path = buildObjectsPath(this.id, this.className);
return this.client.put(path, this.payload());
};
}
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: '3.4'
services:
weaviate:
image: semitechnologies/weaviate:1.13.2
# TODO: temporarily use this version until next release
image: semitechnologies/weaviate:latest@sha256:248a1e1f6f0ba817c00ead4edeecf9d19961d482a3c432165d95762bd44e3a0c
restart: on-failure:0
ports:
- "8080:8080"
Expand Down
16 changes: 16 additions & 0 deletions misc/journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,20 @@ describe("misc endpoints", () => {
})
.catch((e) => fail("it should not have errord: " + e));
});

it("fetches the server version", async () => {
let version = await client.misc.metaGetter()
.do()
.then(res => {
return res.version;
})
.catch((e) => fail("it should not have errord: " + e));

return client.misc.metaGetter()
.fetchVersion()
.then(res => {
expect(res).toEqual(version);
})
.catch((e) => fail("it should not have errord: " + e));
});
});
10 changes: 10 additions & 0 deletions misc/metaGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ export default class MetaGetter {
do = () => {
return this.client.get("/meta", true);
};

fetchVersion = () => {
return this.client.get("/meta", true)
.then(res => {
return res.version;
})
.catch(err => {
return Promise.reject(err);
});
}
}