2019-10-10 00:43:23 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
RSpec.describe Pigeon::Storage do
|
2019-10-10 01:27:48 +00:00
|
|
|
LOGO_BLOB = File.read("./logo.png")
|
|
|
|
IDS = %w(@_TlC2z3FT4fimecC4eytrBhOwhLUZsVBZEZriBO9cWs=.ed25519
|
2019-10-12 19:43:27 +00:00
|
|
|
@28FyT7evjcYrrwngr8G2V1HZ0ODK0VPsFctDEZwfZJc=.ed25519)
|
2020-04-01 12:38:32 +00:00
|
|
|
|
|
|
|
before(:each) do
|
2020-03-08 16:18:05 +00:00
|
|
|
Pigeon::Storage.reset
|
2020-04-01 12:38:32 +00:00
|
|
|
Pigeon::LocalIdentity.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:s) do
|
2019-12-02 02:45:28 +00:00
|
|
|
Pigeon::Storage.current
|
|
|
|
end
|
2019-10-10 01:27:48 +00:00
|
|
|
|
2019-10-26 23:13:06 +00:00
|
|
|
it "deletes a config" do
|
2019-11-27 01:46:50 +00:00
|
|
|
s.set_config("FOO", "BAR")
|
|
|
|
value = s.get_config("FOO")
|
|
|
|
expect(value).to eq("BAR")
|
|
|
|
s.delete_config("FOO")
|
|
|
|
value = s.get_config("FOO")
|
|
|
|
expect(value).to eq(nil)
|
2019-10-26 23:13:06 +00:00
|
|
|
end
|
|
|
|
|
2019-10-10 01:27:48 +00:00
|
|
|
it "manages configs" do
|
2019-11-27 01:46:50 +00:00
|
|
|
s.set_config("FOO", "BAR")
|
|
|
|
value = s.get_config("FOO")
|
|
|
|
expect(value).to eq("BAR")
|
2019-10-10 01:27:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "manages blobs" do
|
2019-11-27 01:46:50 +00:00
|
|
|
logo_hash = s.set_blob(LOGO_BLOB)
|
|
|
|
expect(s.get_blob(logo_hash)).to eq(LOGO_BLOB)
|
2019-10-10 01:27:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "manages peers" do
|
2019-11-27 01:46:50 +00:00
|
|
|
s.add_peer(IDS[0])
|
|
|
|
s.add_peer(IDS[1])
|
|
|
|
expect(s.all_peers).to include(IDS[0])
|
|
|
|
expect(s.all_peers).to include(IDS[1])
|
|
|
|
|
|
|
|
s.remove_peer(IDS[0])
|
|
|
|
expect(s.all_peers).not_to include(IDS[0])
|
|
|
|
expect(s.all_blocks).not_to include(IDS[0])
|
|
|
|
|
|
|
|
s.block_peer(IDS[1])
|
|
|
|
expect(s.all_peers).not_to include(IDS[1])
|
|
|
|
expect(s.all_blocks).to include(IDS[1])
|
|
|
|
expect(s.all_blocks.count).to eq(1)
|
2019-10-10 00:43:23 +00:00
|
|
|
end
|
2020-03-31 12:46:11 +00:00
|
|
|
|
|
|
|
it "finds all authored by a particular feed" do
|
2020-04-01 13:41:41 +00:00
|
|
|
pending("Pigeon::Bundle.ingest is broke. Will fix after investigation.")
|
|
|
|
ingested_messages = Pigeon::Bundle.ingest("./spec/fixtures/normal.bundle")
|
2020-03-31 12:46:11 +00:00
|
|
|
author = ingested_messages.first.author.public_key
|
|
|
|
actual_messages = Pigeon::Storage.current.find_all(author)
|
|
|
|
search_results = Pigeon::Storage.current.find_all(author)
|
|
|
|
end
|
2020-04-02 12:24:43 +00:00
|
|
|
|
|
|
|
it "finds all messages" do
|
2020-04-02 12:32:21 +00:00
|
|
|
a = Pigeon::Helpers.create_message("a", { "b" => "c" })
|
|
|
|
d = Pigeon::Helpers.create_message("d", { "e" => "f" })
|
|
|
|
g = Pigeon::Helpers.create_message("g", { "h" => "i" })
|
|
|
|
results = Pigeon::Storage.current.find_all
|
|
|
|
expect(results.length).to eq(3)
|
|
|
|
expect(a.multihash).to eq(results[0])
|
|
|
|
expect(d.multihash).to eq(results[1])
|
|
|
|
expect(g.multihash).to eq(results[2])
|
2020-04-02 12:24:43 +00:00
|
|
|
end
|
2019-10-10 00:43:23 +00:00
|
|
|
end
|