|
|
@@ -4696,3 +4696,63 @@ TEST_F(ApiFixture, AKeyWithNoOriginAllowListStillListsFromAnywhere) {
|
|
|
ASSERT_TRUE(res);
|
|
|
EXPECT_EQ(res->status, 200) << "an empty allow-list means ANY origin: " << res->body;
|
|
|
}
|
|
|
+
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
+// The PATCH write path reports an absent document ITSELF, with no exists()
|
|
|
+// probe in front of it.
|
|
|
+//
|
|
|
+// There used to be a `Client::exists` probe there, and it was removed because
|
|
|
+// `exists` cannot tell "no such document" from "the call failed" - so a
|
|
|
+// transport blip answered an UNRETRYABLE 404 for a document that exists. This
|
|
|
+// pins the pairing that made the deletion safe: the absent case must still be
|
|
|
+// 404 (so `patch()` really does report it), and the present case must still be
|
|
|
+// 200 (so nothing about the probe was load-bearing).
|
|
|
+//
|
|
|
+// It is deliberately a PAIR. The 404 half alone would pass equally well against
|
|
|
+// a route that refused everything, which is a worse defect than the one being
|
|
|
+// fixed.
|
|
|
+//
|
|
|
+// WHAT THIS TEST DOES NOT COVER, stated because it would otherwise read as
|
|
|
+// proof of the deletion and is not: it passes IDENTICALLY with the probe in
|
|
|
+// place, because the probe produced the same two answers. Nothing here can see
|
|
|
+// whether the probe exists - that would need a round-trip count or an injected
|
|
|
+// transport failure, and the fixture offers neither. What it pins is the FACT
|
|
|
+// the deletion rests on: that `patch()` reports the absent case itself. If a
|
|
|
+// later change broke that, this goes red and the deletion stands revealed as
|
|
|
+// unsafe, which is the useful direction.
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
+TEST_F(ApiFixture, PatchReportsAnAbsentDocumentWithoutAnExistenceProbe) {
|
|
|
+ auto c = admin();
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","noprobe"},{"kind","json"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ const std::string docs = base + "/noprobe/documents";
|
|
|
+
|
|
|
+ // Absent: still 404, and still the slug a caller branches on.
|
|
|
+ auto missing = c.Patch((docs + "/definitely-not-here").c_str(),
|
|
|
+ nlohmann::json::object().dump(), "application/json");
|
|
|
+ ASSERT_TRUE(missing);
|
|
|
+ EXPECT_EQ(missing->status, 404);
|
|
|
+ EXPECT_EQ(nlohmann::json::parse(missing->body)["error"]["code"], "not_found");
|
|
|
+
|
|
|
+ // Present: still 200. An EMPTY patch is used on purpose - that is the probe
|
|
|
+ // a consumer reached for when diagnosing a document that would not accept
|
|
|
+ // writes, so it is the exact shape worth pinning.
|
|
|
+ auto made = c.Post(docs.c_str(), nlohmann::json{{"v",1}}.dump(), "application/json");
|
|
|
+ ASSERT_TRUE(made); ASSERT_EQ(made->status, 201);
|
|
|
+ const std::string id = nlohmann::json::parse(made->body)["id"];
|
|
|
+ auto empty = c.Patch((docs + "/" + id).c_str(), nlohmann::json::object().dump(),
|
|
|
+ "application/json");
|
|
|
+ ASSERT_TRUE(empty);
|
|
|
+ EXPECT_EQ(empty->status, 200) << empty->body;
|
|
|
+
|
|
|
+ // And the merge still works, so the route was not reduced to a no-op.
|
|
|
+ auto merged = c.Patch((docs + "/" + id).c_str(), nlohmann::json{{"w",2}}.dump(),
|
|
|
+ "application/json");
|
|
|
+ ASSERT_TRUE(merged); ASSERT_EQ(merged->status, 200);
|
|
|
+ auto read = c.Get((docs + "/" + id).c_str());
|
|
|
+ ASSERT_TRUE(read); ASSERT_EQ(read->status, 200);
|
|
|
+ const nlohmann::json body = nlohmann::json::parse(read->body);
|
|
|
+ EXPECT_EQ(body["v"], 1) << "the empty patch or the merge dropped an existing field";
|
|
|
+ EXPECT_EQ(body["w"], 2);
|
|
|
+}
|