mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
test(environment): consolidate item write coverage (#11980)
This commit is contained in:
1 parent
8c8f37c200
commit
222122fb79
2 files changed
+38
-53
No files matched your search
@@ -13,6 +13,24 @@ import { servedFrom } from "../../../tests/fixtures/environmentStateServing.js";
|
||||
describe("served item writes", () => {
|
||||
it("answers a create with the parent and tags its ids name, in the order sent", () => {
|
||||
const items = servedFrom(ITEM_REFERENCES_ROWS);
|
||||
expect(items.state.writes.get("post_items")).toMatchObject({
|
||||
served: true,
|
||||
rules: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
field: "parent",
|
||||
rule: "reference",
|
||||
member: "parentId",
|
||||
type: "/api/locations",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
field: "tags",
|
||||
rule: "reference",
|
||||
member: "tagIds",
|
||||
type: "/api/tags",
|
||||
many: true,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
const body = items.answer("post_items", {
|
||||
body: {
|
||||
name: "Snow shovel",
|
||||
@@ -27,7 +45,7 @@ describe("served item writes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("answers a create naming no parent and no tags with none", () => {
|
||||
it("answers creates with no parent or tags whether the ids were omitted or sent empty", () => {
|
||||
const items = servedFrom(ITEM_REFERENCES_ROWS);
|
||||
expect(
|
||||
items.answer("post_items", { body: { name: "Spare fuse" } }).body,
|
||||
@@ -36,19 +54,25 @@ describe("served item writes", () => {
|
||||
parent: null,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("answers a create sending no parent and no tags as a recorded create sent them", () => {
|
||||
const items = servedFrom(ITEM_REFERENCES_ROWS);
|
||||
expect(
|
||||
items.answer("post_items", {
|
||||
body: { name: "Spare fuse", parentId: null, tagIds: [] },
|
||||
body: { name: "Spare bulb", parentId: null, tagIds: [] },
|
||||
}).body,
|
||||
).toMatchObject({ name: "Spare fuse", parent: null, tags: [] });
|
||||
).toMatchObject({ name: "Spare bulb", parent: null, tags: [] });
|
||||
});
|
||||
|
||||
it("answers a create leaving out a parent the first create left out with none, and one sending null with null", () => {
|
||||
const items = servedFrom(ADDED_EMPTY_REFERENCE_ROWS);
|
||||
expect(items.state.writes.get("post_items")).toMatchObject({
|
||||
served: true,
|
||||
rules: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
field: "parent",
|
||||
rule: "reference",
|
||||
member: "parentId",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
const left = items.answer("post_items", { body: { name: "Spare fuse" } })
|
||||
.body as Record<string, unknown>;
|
||||
expect(left).toMatchObject({ name: "Spare fuse" });
|
||||
@@ -86,6 +110,13 @@ describe("served item writes", () => {
|
||||
|
||||
it("flips an entry's flag on each body-less call", () => {
|
||||
const entries = servedFrom(BOOKMARK_TOGGLE_ROWS);
|
||||
expect(
|
||||
entries.state.writes.get("put_entries_bookmark_by_id"),
|
||||
).toMatchObject({
|
||||
served: true,
|
||||
address: { by: "action", segment: "bookmark" },
|
||||
rules: expect.arrayContaining([{ field: "starred", rule: "toggle" }]),
|
||||
});
|
||||
const starred = () =>
|
||||
(
|
||||
entries.answer("get_entries_by_id", { id: "2" }).body as {
|
||||
|
||||
@@ -5,10 +5,8 @@ import {
|
||||
type TimedCaptureRow,
|
||||
} from "../../../tests/fixtures/analysisView.js";
|
||||
import {
|
||||
ADDED_EMPTY_REFERENCE_ROWS,
|
||||
BOOKMARK_TOGGLE_ROWS,
|
||||
CREATES_BY_TITLE_ROWS,
|
||||
ITEM_REFERENCES_ROWS,
|
||||
NULL_THEN_STARRED_ROWS,
|
||||
RANKED_AFTER_DELETE_ROWS,
|
||||
REFUTED_TITLE_SORT_ROWS,
|
||||
@@ -42,50 +40,6 @@ describe("item writes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("serves a create sending no parent after an earlier create added the parent reference", () => {
|
||||
const plan = planOf(ADDED_EMPTY_REFERENCE_ROWS, "post_items");
|
||||
expect(plan).toMatchObject({ served: true });
|
||||
expect(plan.rules).toContainEqual(
|
||||
expect.objectContaining({
|
||||
field: "parent",
|
||||
rule: "reference",
|
||||
member: "parentId",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("serves a create whose parent and tags a call names by id, one call naming none", () => {
|
||||
const plan = planOf(ITEM_REFERENCES_ROWS, "post_items");
|
||||
expect(plan).toMatchObject({ served: true });
|
||||
expect(plan.rules).toContainEqual(
|
||||
expect.objectContaining({
|
||||
field: "parent",
|
||||
rule: "reference",
|
||||
member: "parentId",
|
||||
type: "/api/locations",
|
||||
}),
|
||||
);
|
||||
expect(plan.rules).toContainEqual(
|
||||
expect.objectContaining({
|
||||
field: "tags",
|
||||
rule: "reference",
|
||||
member: "tagIds",
|
||||
type: "/api/tags",
|
||||
many: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("serves a body-less action that calls show flipping its flag both ways", () => {
|
||||
expect(
|
||||
planOf(BOOKMARK_TOGGLE_ROWS, "put_entries_bookmark_by_id"),
|
||||
).toMatchObject({
|
||||
served: true,
|
||||
address: { by: "action", segment: "bookmark" },
|
||||
rules: expect.arrayContaining([{ field: "starred", rule: "toggle" }]),
|
||||
});
|
||||
});
|
||||
|
||||
it("serves no action whose calls flipped its flag one way only", () => {
|
||||
const starred = feedEntry(1, true, "2026-10-17T18:00:03.120000Z");
|
||||
expect(
|
||||
|
||||
Reference in new issue
Block a user