A simple Ruby server using Sinatra that serves Bluesky custom feeds
at master 83 lines 2.4 kB view raw
1require 'spec_helper' 2 3describe BlueFactory do 4 before do 5 BlueFactory.instance_variable_get("@properties").each do |prop| 6 if BlueFactory.instance_variable_get("@#{prop}") 7 BlueFactory.remove_instance_variable("@#{prop}") 8 end 9 end 10 11 if BlueFactory.instance_variable_get("@interactions_handler") 12 BlueFactory.remove_instance_variable("@interactions_handler") 13 end 14 end 15 16 describe '.set' do 17 it 'should set hostname' do 18 BlueFactory.set :hostname, 'foo.example.com' 19 BlueFactory.hostname.should == 'foo.example.com' 20 end 21 22 it 'should set publisher_did' do 23 BlueFactory.set :publisher_did, 'did:plc:sdgfncjshfgnscjd' 24 BlueFactory.publisher_did.should == 'did:plc:sdgfncjshfgnscjd' 25 end 26 27 context 'with string keys' do 28 it 'should work the same' do 29 BlueFactory.set 'hostname', 'europa.eu' 30 BlueFactory.hostname.should == 'europa.eu' 31 32 BlueFactory.set 'publisher_did', 'did:plc:asdasdasdasd' 33 BlueFactory.publisher_did.should == 'did:plc:asdasdasdasd' 34 end 35 end 36 37 context 'with an unknown property' do 38 it 'should raise an error' do 39 expect { BlueFactory.set :foobar, 'value' }.to raise_error(NoMethodError) 40 end 41 end 42 end 43 44 describe '.service_did' do 45 it 'should return did:web based on the configured hostname' do 46 BlueFactory.set :hostname, 'myserver.com' 47 BlueFactory.service_did.should == 'did:web:myserver.com' 48 end 49 50 it "should raise an error if domain isn't configured" do 51 expect { BlueFactory.service_did }.to raise_error(BlueFactory::ConfigurationError) 52 end 53 end 54 55 describe '.on_interactions' do 56 it 'should set an interaction handler' do 57 called = nil 58 int = BlueFactory::Interaction.new({}) 59 60 BlueFactory.on_interactions do |x| 61 called = x 62 end 63 64 BlueFactory.interactions_handler.should be_a(Proc) 65 66 BlueFactory.interactions_handler.call(int) 67 called.should == int 68 end 69 end 70 71 describe '.interactions_handler=' do 72 it 'should set an interaction handler' do 73 called = nil 74 int = BlueFactory::Interaction.new({}) 75 76 BlueFactory.interactions_handler = proc { |x| called = x } 77 BlueFactory.interactions_handler.should be_a(Proc) 78 79 BlueFactory.interactions_handler.call(int) 80 called.should == int 81 end 82 end 83end