test(nodejs): cover the accepted and inline view drop through connect()

Exercises `dropViewAsync` against the mock server both ways: a 202 carrying a
`job_id` surfaces that id, and a 200 -- nothing was bound to the name -- yields
an already-finished job with none.

The wire key is written as raw JSON rather than an object literal, which is what
the rest of this file does and what keeps `useNamingConvention` off a snake_case
field the server chooses.
This commit is contained in:
Jack Ye
2026-09-23 21:45:29 -07:00
parent 75ccb9f830
commit 60577a44cf
2 changed files with 32 additions and 4 deletions
+31
View File
@@ -161,6 +161,37 @@ describe("remote connection", () => {
);
});
it("reports the cleanup job when a view drop is accepted", async () => {
await withMockDatabase(
(req, res) => {
expect(req.method).toBe("POST");
expect(req.url).toBe("/v1/view/adults/drop");
res
.writeHead(202, { "content-type": "application/json" })
.end('{"job_id": "j1-do-abc"}');
},
async (db) => {
const job = await db.dropViewAsync("adults");
expect(job.id).toBe("j1-do-abc");
},
);
});
it("reports a finished job when a view drop had nothing to delete", async () => {
await withMockDatabase(
(req, res) => {
expect(req.url).toBe("/v1/view/adults/drop");
res.writeHead(200, { "content-type": "application/json" }).end("{}");
},
async (db) => {
// A 200 means the name was not bound, so there is no cleanup to wait on.
const job = await db.dropViewAsync("adults");
expect(job.id).toBeNull();
await job.wait();
},
);
});
it("should accept partial connection options", async () => {
await connect("db://test", {
apiKey: "fake",
+1 -4
View File
@@ -418,10 +418,7 @@ export abstract class Connection {
* The name is free before this resolves. When nothing was bound to it, the
* returned job is already finished and has no id.
*/
abstract dropViewAsync(
name: string,
namespacePath?: string[],
): Promise<Job>;
abstract dropViewAsync(name: string, namespacePath?: string[]): Promise<Job>;
/**
* The names of the views in one namespace.