mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 21:57:45 +03:00
Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
This commit is contained in:
parent
61efe5330e
commit
23cfd1b4d0
3 changed files with 29 additions and 3 deletions
|
@ -872,8 +872,8 @@ local function archive_itemstore(archive, config, user, node)
|
||||||
truncate = size;
|
truncate = size;
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
function get_set:tail()
|
function get_set:head()
|
||||||
-- This should conveniently return the last item
|
-- This should conveniently return the most recent item
|
||||||
local item = self:get(nil);
|
local item = self:get(nil);
|
||||||
if item then
|
if item then
|
||||||
return item.attr.id, item;
|
return item.attr.id, item;
|
||||||
|
|
|
@ -285,4 +285,30 @@ describe("util.pubsub", function ()
|
||||||
end);
|
end);
|
||||||
end);
|
end);
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
describe("item API", function ()
|
||||||
|
local service;
|
||||||
|
before_each(function ()
|
||||||
|
service = pubsub.new();
|
||||||
|
service:create("test", true, { publish_model = "subscribers" });
|
||||||
|
end);
|
||||||
|
describe("get_last_item()", function ()
|
||||||
|
it("succeeds with nil on empty nodes", function ()
|
||||||
|
local ok, id, item = service:get_last_item("test", true);
|
||||||
|
assert.is_true(ok);
|
||||||
|
assert.is_nil(id);
|
||||||
|
assert.is_nil(item);
|
||||||
|
end);
|
||||||
|
it("succeeds and returns the last item", function ()
|
||||||
|
service:publish("test", true, "one", "hello world");
|
||||||
|
service:publish("test", true, "two", "hello again");
|
||||||
|
service:publish("test", true, "three", "hey");
|
||||||
|
service:publish("test", true, "one", "bye");
|
||||||
|
local ok, id, item = service:get_last_item("test", true);
|
||||||
|
assert.is_true(ok);
|
||||||
|
assert.equal("one", id);
|
||||||
|
assert.equal("bye", item);
|
||||||
|
end);
|
||||||
|
end);
|
||||||
|
end);
|
||||||
end);
|
end);
|
||||||
|
|
|
@ -604,7 +604,7 @@ function service:get_last_item(node, actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns success, id, item
|
-- Returns success, id, item
|
||||||
return true, self.data[node]:tail();
|
return true, self.data[node]:head();
|
||||||
end
|
end
|
||||||
|
|
||||||
function service:get_nodes(actor)
|
function service:get_nodes(actor)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue