Skip to content

Commit

Permalink
api: Add test for new flow
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Apr 22, 2024
1 parent 2f5f413 commit cf2cb9e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/api/src/controllers/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,33 @@ describe("controllers/stream", () => {
const stream = await res.json();

// Mark stream as active
await db.stream.update(stream.id, { isActive: true });
await db.stream.update(stream.id, {
isActive: true,
lastSeen: Date.now(),
});

// Requesting pull lock should fail, because the stream is active (so it should be replicated instead of being pulled)
const reslockPull = await client.post(`/stream/${stream.id}/lockPull`);
expect(reslockPull.status).toBe(423);
});

it("should still lock pull for an active stream that got lost", async () => {
// Create stream pull
const res = await client.put("/stream/pull", postMockPullStream);
expect(res.status).toBe(201);
const stream = await res.json();

// Mark stream as active
await db.stream.update(stream.id, {
isActive: true,
lastSeen: Date.now() - 24 * 60 * 60 * 1000,
});

// Requesting pull lock should work, because the stream is not actually active (outdated lastSeen)
const reslockPull = await client.post(`/stream/${stream.id}/lockPull`);
expect(reslockPull.status).toBe(204);
});

it("should not lock pull for already locked pull", async () => {
// Create stream pull
const res = await client.put("/stream/pull", postMockPullStream);
Expand Down

0 comments on commit cf2cb9e

Please sign in to comment.