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
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"fmt:fix": "deno fmt library/ tests/ www/ docs/",
"fmt:check": "deno fmt --check library/ tests/ www/ docs/",
"lint": "deno lint library/ tests/ www/ docs/",
"test": "deno test -A ./tests -- --nolog",
"test": "deno test -A --parallel ./tests -- --nolog",
"dnt": "deno run -A --importmap ./scripts/dnt_import_map.json ./scripts/dnt.ts",
"generate_api": "deno run -A ./scripts/generate_api.ts"
},
Expand Down
12 changes: 9 additions & 3 deletions library/lens/update_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UpdateHelper {
}

if (property["@array"]) {
this.processArrayProperty(entity, propertyName, value);
this.processArrayProperty(entity, propertyName, value, property);
} else {
this.processSingleProperty(entity, propertyName, value, property);
}
Expand Down Expand Up @@ -93,10 +93,11 @@ export class UpdateHelper {
entity: Entity,
propertyName: string,
propertyValue: unknown,
property: ExpandedProperty,
) {
const config = this.parseArrayUpdateConfig(propertyValue);
if (config.$set) {
this.processArraySet(entity, propertyName, config.$set);
this.processArraySet(entity, propertyName, config.$set, property);
} else {
this.processArrayAddRemove(
entity,
Expand All @@ -111,14 +112,19 @@ export class UpdateHelper {
entity: Entity,
propertyName: string,
propertyValue: unknown[],
property: ExpandedProperty,
) {
const deletePattern = {
$id: entity.$id,
[propertyName]: null,
};
const quadsToDelete = this.encode(deletePattern);
this.deleteQuads.push(...quadsToDelete);
this.whereQuads.push(...quadsToDelete);
if (property["@optional"]) {
this.whereQuads.push(OPTIONAL`${quadsToDelete}`);
} else {
this.whereQuads.push(...quadsToDelete);
}

const insertPattern = {
$id: entity.$id,
Expand Down
28 changes: 17 additions & 11 deletions tests/e2e/dbpedia.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const favouriteActors = [
"http://dbpedia.org/resource/Gal_Gadot",
];

Deno.test("E2E / DBpedia / Query single remote entity", async () => {
Deno.test.ignore("E2E / DBpedia / Query single remote entity", async () => {
const BradId = "http://dbpedia.org/resource/Brad_Pitt";
const BradName = "Brad Pitt";
const actor = await Actors.findByIri(favouriteActors[0]);
Expand All @@ -46,18 +46,24 @@ Deno.test("E2E / DBpedia / Query single remote entity", async () => {
assert(actor.name === BradName);
});

Deno.test("E2E / DBpedia / Query multiple specific remote entities", async () => {
const actors = await Actors.findByIris(favouriteActors);
assert(actors);
assert(actors.length === favouriteActors.length);
});
Deno.test.ignore(
"E2E / DBpedia / Query multiple specific remote entities",
async () => {
const actors = await Actors.findByIris(favouriteActors);
assert(actors);
assert(actors.length === favouriteActors.length);
},
);

Deno.test("E2E / DBpedia / Query multiple random remote entities", async () => {
const actors = await Actors.find({ take: 7 });
assert(actors.length == 7);
});
Deno.test.ignore(
"E2E / DBpedia / Query multiple random remote entities",
async () => {
const actors = await Actors.find({ take: 7 });
assert(actors.length == 7);
},
);

Deno.test("E2E / DBpedia / Query count", async () => {
Deno.test.ignore("E2E / DBpedia / Query count", async () => {
const count = await Actors.count({ max: 100 });
assert(count > 0);
});
56 changes: 56 additions & 0 deletions tests/e2e/optional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,62 @@ Deno.test("E2E / Optional / Insert with optional properties", async () => {
`);
});

Deno.test("E2E / Optional / Set to empty optional array property", async () => {
const { Entities, assertStore } = init();

await Entities.insert({
$id: x.Entity,
requiredString: "required",
optionalArray: [],
});

assertStore(`
x:Entity
a x:Entity ;
x:requiredString "required" .
`);

await Entities.update({
$id: x.Entity,
optionalArray: { $set: ["setArray"] },
});

assertStore(`
x:Entity
a x:Entity ;
x:requiredString "required" ;
x:optionalArray "setArray" .
`);
});

Deno.test("E2E / Optional / Add to empty optional array property", async () => {
const { Entities, assertStore } = init();

await Entities.insert({
$id: x.Entity,
requiredString: "required",
optionalArray: [],
});

assertStore(`
x:Entity
a x:Entity ;
x:requiredString "required" .
`);

await Entities.update({
$id: x.Entity,
optionalArray: { $add: ["addArray"] },
});

assertStore(`
x:Entity
a x:Entity ;
x:requiredString "required" ;
x:optionalArray "addArray" .
`);
});

Deno.test("E2E / Optional / Unset optional existing property", async () => {
const { Entities, assertStore } = init();

Expand Down