Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Feb 7, 2025
1 parent c30a4a5 commit 3880d33
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 21 deletions.
92 changes: 75 additions & 17 deletions integration-tests/lts/insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,82 @@ describe("insert", () => {
});

test("insert many-to-one and select one", async () => {
e.params(
{
name: e.str,
nemeses: e.array(e.tuple({ name: e.str })),
},
(params) => {
const hero = e.insert(e.Hero, {
name: params.name,
});
const villains = e.for(e.array_unpack(params.nemeses), (nemesis) => {
return e.insert(e.Villain, {
name: nemesis.name,
nemesis: hero,
const edgeql = e
.params(
{
name: e.str,
nemeses: e.array(e.tuple({ name: e.str })),
},
(params) => {
const hero = e.insert(e.Hero, {
name: params.name,
});
const villains = e.for(e.array_unpack(params.nemeses), (nemesis) => {
return e.insert(e.Villain, {
name: nemesis.name,
nemesis: hero,
});
});
});

return e.with([villains], e.select(hero));
},
).toEdgeQL();
return e.with([villains], e.select(hero));
},
)
.toEdgeQL();

// Also test including `hero` in the `with` refs
assert.equal(
edgeql,
e
.params(
{
name: e.str,
nemeses: e.array(e.tuple({ name: e.str })),
},
(params) => {
const hero = e.insert(e.Hero, {
name: params.name,
});
const villains = e.for(
e.array_unpack(params.nemeses),
(nemesis) => {
return e.insert(e.Villain, {
name: nemesis.name,
nemesis: hero,
});
},
);

return e.with([hero, villains], e.select(hero));
},
)
.toEdgeQL(),
);
assert.equal(
edgeql,
e
.params(
{
name: e.str,
nemeses: e.array(e.tuple({ name: e.str })),
},
(params) => {
const hero = e.insert(e.Hero, {
name: params.name,
});
const villains = e.for(
e.array_unpack(params.nemeses),
(nemesis) => {
return e.insert(e.Villain, {
name: nemesis.name,
nemesis: hero,
});
},
);

return e.with([villains, hero], e.select(hero));
},
)
.toEdgeQL(),
);
});
});
32 changes: 32 additions & 0 deletions integration-tests/lts/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ describe("update", () => {
}).toEdgeQL();
});

test("nested update and explicit with, unwrapped select should fail", async () => {
assert.throws(
() =>
e
.params({ movieId: e.uuid }, (params) => {
const movie = e.select(e.Movie, (m) => ({
filter: e.op(m.id, "=", params.movieId),
}));

const updateChar = e.update(movie.characters, (c) => ({
set: {
name: e.str_lower(c.name),
},
}));

const updateProfile = e.update(movie.profile, (p) => ({
set: {
a: e.str_upper(p.a),
},
}));

return e.with([updateChar, updateProfile], movie);
})
.toEdgeQL(),
{
message:
`Ref expressions in with() cannot reference the expression to which the ` +
`'WITH' block is being attached. Consider wrapping the expression in a select.`,
},
);
});

test("scoped update", async () => {
const query = e.update(e.Hero, (hero) => ({
filter_single: e.op(hero.name, "=", data.spidey.name),
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/lts/with.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ SELECT {
`WITH
__withVar_0 := (
WITH
__withVar_1 := { <std::int64>1, <std::int64>2, <std::int64>3 },
__withVar_2 := __withVar_1
__withVar_2 := { <std::int64>1, <std::int64>2, <std::int64>3 },
__withVar_3 := __withVar_2
SELECT {
multi numbers := assert_exists(__withVar_1),
multi numbersAlias := assert_exists(__withVar_2)
multi numbers := assert_exists(__withVar_2),
multi numbersAlias := assert_exists(__withVar_3)
}
)
SELECT {
Expand Down

0 comments on commit 3880d33

Please sign in to comment.