mail based rss feed aggregator
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

mostly me fiddling with selectors to get a proper grasp on em

ollie 95fcfe53 cb6eaa8e

+193 -13
+1
gleam.toml
··· 37 37 38 38 [dev_dependencies] 39 39 gleeunit = ">= 1.0.0 and < 2.0.0" 40 + simplifile = ">= 2.4.0 and < 3.0.0"
+1
manifest.toml
··· 70 70 lustre_portal = { version = ">= 1.0.1 and < 2.0.0" } 71 71 parrot = { version = ">= 2.2.1 and < 3.0.0" } 72 72 parsed_it = { version = ">= 0.1.1 and < 1.0.0" } 73 + simplifile = { version = ">= 2.4.0 and < 3.0.0" } 73 74 sqlight = { version = ">= 1.0.3 and < 2.0.0" } 74 75 woof = { version = ">= 1.2.0 and < 2.0.0" } 75 76 youid = { version = ">= 1.6.0 and < 2.0.0" }
+191
test/eater_test.gleam
··· 1 + import eater/feed/rss 2 + import eater/pubsub 3 + import eater/sender 4 + import eater/smtp 5 + import eater/user 6 + import gleam/erlang/process 7 + import gleam/int 8 + import gleam/option 9 + import gleam/otp/static_supervisor 10 + import gleam/string 11 + import gleam/uri 12 + import gleeunit 13 + import group_registry 14 + import simplifile 15 + import sqlight 16 + import youid/uuid 17 + 18 + pub fn main() -> Nil { 19 + gleeunit.main() 20 + } 21 + 22 + type PubsubWrapper { 23 + PubsubWrapper(pubsub.Message) 24 + } 25 + 26 + fn selector_test() { 27 + echo "selector_test start" 28 + 29 + let subject_a: process.Subject(String) = process.new_subject() 30 + let subject_b: process.Subject(Int) = process.new_subject() 31 + 32 + let selector = 33 + process.new_selector() 34 + |> process.select(subject_a) 35 + 36 + process.send(subject_a, "something") 37 + 38 + let selector = 39 + selector 40 + |> process.select_map(subject_b, int.to_string) 41 + 42 + process.send(subject_b, 123) 43 + 44 + let assert Ok("something") = process.selector_receive(selector, 100) 45 + let assert Ok("123") = process.selector_receive(selector, 100) 46 + 47 + echo "selector_test end" 48 + } 49 + 50 + fn subscription_test() { 51 + echo "subscription_test start" 52 + let self = process.self() 53 + let feed = rss.new_location(uri.empty) 54 + 55 + let registry = process.new_name("registry") 56 + 57 + let assert Ok(_) = pubsub.start(registry) 58 + 59 + let selector = process.new_selector() 60 + 61 + let selector = 62 + pubsub.select_feed( 63 + feed:, 64 + in: registry, 65 + self:, 66 + selector:, 67 + handler: PubsubWrapper, 68 + ) 69 + 70 + pubsub.publish_feed_update(feed_update("1"), feed, registry) 71 + 72 + let selector = 73 + pubsub.select_feed( 74 + feed:, 75 + in: registry, 76 + self:, 77 + selector:, 78 + handler: PubsubWrapper, 79 + ) 80 + 81 + pubsub.publish_feed_update(feed_update(""), feed, registry) 82 + 83 + let assert Ok(PubsubWrapper(pubsub.FeedUpdate(update:))) = 84 + process.selector_receive(selector, 1000) 85 + 86 + assert update == feed_update("1") 87 + 88 + let assert Ok(PubsubWrapper(pubsub.FeedUpdate(update:))) = 89 + process.selector_receive(selector, 1000) 90 + 91 + assert update == feed_update("") 92 + echo "subscription_test end" 93 + } 94 + 95 + pub fn sender_subscription_test() { 96 + echo "sender_subscription_test start" 97 + 98 + let _ = simplifile.delete_file("db/data/test-db.sqlite3") 99 + let assert Ok(_) = 100 + simplifile.copy_file( 101 + "db/data/test-db.sqlite3.bak", 102 + "db/data/test-db.sqlite3", 103 + ) 104 + 105 + use database <- sqlight.with_connection("db/data/test-db.sqlite3") 106 + 107 + let feed = rss.new_location(uri.empty) 108 + let user = user.new("test", <<>>) 109 + 110 + let registry = process.new_name("registry") 111 + let factory = process.new_name("factory") 112 + 113 + let assert Ok(_) = 114 + static_supervisor.new(static_supervisor.RestForOne) 115 + |> static_supervisor.add(pubsub.supervised(registry)) 116 + |> static_supervisor.add(sender.factory( 117 + factory, 118 + registry:, 119 + database:, 120 + smtp_environment: test_smtp_env(), 121 + )) 122 + |> static_supervisor.start() 123 + as "failed to start supervisor" 124 + 125 + let assert Ok(_) = 126 + sender.start_new( 127 + factory, 128 + sender.Start( 129 + database:, 130 + registry:, 131 + user:, 132 + smtp_environment: test_smtp_env(), 133 + ), 134 + ) 135 + 136 + pubsub.publish_feed_update(feed_update("0"), feed, registry) 137 + 138 + process.sleep(200) 139 + 140 + pubsub.publish_subscribed_to_feed(user, feed, registry) 141 + 142 + process.sleep(200) 143 + 144 + pubsub.publish_feed_update(feed_update("1"), feed, registry) 145 + 146 + process.sleep(200) 147 + 148 + pubsub.publish_unsubscribed_from_feed(user, feed, registry) 149 + 150 + process.sleep(200) 151 + 152 + pubsub.publish_feed_update(feed_update("2"), feed, registry) 153 + 154 + process.sleep(200) 155 + 156 + pubsub.publish_subscribed_to_feed(user, feed, registry) 157 + 158 + process.sleep(200) 159 + 160 + pubsub.publish_feed_update(feed_update("3"), feed, registry) 161 + 162 + process.sleep(200) 163 + 164 + echo "sender_subscription_test end" 165 + } 166 + 167 + fn test_smtp_env() -> smtp.SmtpEnvironment { 168 + smtp.SmtpEnvironment( 169 + host: "", 170 + port: 0, 171 + username: "", 172 + password: "", 173 + sender_email: option.None, 174 + sender_name: option.None, 175 + ) 176 + } 177 + 178 + fn feed_update(diff) { 179 + rss.FeedUpdate( 180 + rss.Item(title: "test", link: "test" <> diff, description: "test"), 181 + channel: rss.ChannelDetails( 182 + title: "test", 183 + link: "test", 184 + description: "test", 185 + ), 186 + ) 187 + } 188 + 189 + fn feed_channel(feed: rss.Location) -> String { 190 + feed.id |> uuid.to_string() 191 + }
-13
test/server_test.gleam
··· 1 - import gleeunit 2 - 3 - pub fn main() -> Nil { 4 - gleeunit.main() 5 - } 6 - 7 - // gleeunit test functions end in `_test` 8 - pub fn hello_world_test() { 9 - let name = "Joe" 10 - let greeting = "Hello, " <> name <> "!" 11 - 12 - assert greeting == "Hello, Joe!" 13 - }