Lexicon-driven ATProto AppView in Gleam — port of HappyView
0

Configure Feed

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

gleamview / test / gleamview_test.gleam
2.6 kB 93 lines
1import gleam/option.{None, Some} 2import gleam/string 3import gleeunit 4import gleamview/jetstream 5import gleamview/lexicon 6import gleamview/oauth 7import gleamview/util 8 9pub fn main() { 10 gleeunit.main() 11} 12 13pub fn lexicon_parse_record_test() { 14 let raw = 15 "{ 16 \"lexicon\": 1, 17 \"id\": \"com.example.post\", 18 \"defs\": { 19 \"main\": { 20 \"type\": \"record\", 21 \"key\": \"tid\", 22 \"record\": { \"type\": \"object\", \"properties\": {} } 23 } 24 } 25 }" 26 let assert Ok(parsed) = lexicon.parse(raw, 1, None, lexicon.Upsert, None) 27 assert parsed.id == "com.example.post" 28 assert parsed.lexicon_type == lexicon.Record 29 assert parsed.record_key == Some("tid") 30} 31 32pub fn lexicon_parse_query_test() { 33 let raw = 34 "{ 35 \"lexicon\": 1, 36 \"id\": \"com.example.getPosts\", 37 \"defs\": { 38 \"main\": { 39 \"type\": \"query\", 40 \"parameters\": { \"type\": \"params\", \"properties\": {} }, 41 \"output\": { \"encoding\": \"application/json\" } 42 } 43 } 44 }" 45 let assert Ok(parsed) = 46 lexicon.parse(raw, 1, Some("com.example.post"), lexicon.Upsert, None) 47 assert parsed.lexicon_type == lexicon.Query 48 assert parsed.target_collection == Some("com.example.post") 49} 50 51pub fn procedure_action_parse_test() { 52 let assert Ok(lexicon.Create) = lexicon.action_from_optional(Some("create")) 53 let assert Ok(lexicon.Upsert) = lexicon.action_from_optional(None) 54 let assert Error(_) = lexicon.action_from_optional(Some("nope")) 55} 56 57pub fn jetstream_url_test() { 58 let url = 59 jetstream.build_subscribe_url("wss://jetstream.example.com", [ 60 "app.bsky.feed.post", 61 ]) 62 assert string.contains(url, "wantedCollections=app.bsky.feed.post") 63 assert string.contains(url, "com.atproto.lexicon.schema") 64 assert string.contains(url, "/subscribe?") 65} 66 67pub fn at_uri_test() { 68 assert util.at_uri("did:plc:abc", "com.example.post", "3k2y") 69 == "at://did:plc:abc/com.example.post/3k2y" 70} 71 72pub fn rkey_from_uri_test() { 73 let assert Ok("3k2y") = 74 util.rkey_from_uri("at://did:plc:abc/com.example.post/3k2y") 75} 76 77pub fn sha256_hex_stable_test() { 78 let a = util.sha256_hex("hello") 79 let b = util.sha256_hex("hello") 80 assert a == b 81 assert string.length(a) == 64 82} 83 84pub fn oauth_loopback_client_id_test() { 85 let id = 86 oauth.loopback_client_id( 87 "https://gleamview.boxd.sh/oauth/callback", 88 oauth.default_scope, 89 ) 90 assert string.starts_with(id, "http://localhost?") 91 assert string.contains(id, "redirect_uri=") 92 assert string.contains(id, "scope=") 93}