import gleam/option.{None, Some} import gleam/string import gleeunit import gleamview/jetstream import gleamview/lexicon import gleamview/oauth import gleamview/util pub fn main() { gleeunit.main() } pub fn lexicon_parse_record_test() { let raw = "{ \"lexicon\": 1, \"id\": \"com.example.post\", \"defs\": { \"main\": { \"type\": \"record\", \"key\": \"tid\", \"record\": { \"type\": \"object\", \"properties\": {} } } } }" let assert Ok(parsed) = lexicon.parse(raw, 1, None, lexicon.Upsert, None) assert parsed.id == "com.example.post" assert parsed.lexicon_type == lexicon.Record assert parsed.record_key == Some("tid") } pub fn lexicon_parse_query_test() { let raw = "{ \"lexicon\": 1, \"id\": \"com.example.getPosts\", \"defs\": { \"main\": { \"type\": \"query\", \"parameters\": { \"type\": \"params\", \"properties\": {} }, \"output\": { \"encoding\": \"application/json\" } } } }" let assert Ok(parsed) = lexicon.parse(raw, 1, Some("com.example.post"), lexicon.Upsert, None) assert parsed.lexicon_type == lexicon.Query assert parsed.target_collection == Some("com.example.post") } pub fn procedure_action_parse_test() { let assert Ok(lexicon.Create) = lexicon.action_from_optional(Some("create")) let assert Ok(lexicon.Upsert) = lexicon.action_from_optional(None) let assert Error(_) = lexicon.action_from_optional(Some("nope")) } pub fn jetstream_url_test() { let url = jetstream.build_subscribe_url("wss://jetstream.example.com", [ "app.bsky.feed.post", ]) assert string.contains(url, "wantedCollections=app.bsky.feed.post") assert string.contains(url, "com.atproto.lexicon.schema") assert string.contains(url, "/subscribe?") } pub fn at_uri_test() { assert util.at_uri("did:plc:abc", "com.example.post", "3k2y") == "at://did:plc:abc/com.example.post/3k2y" } pub fn rkey_from_uri_test() { let assert Ok("3k2y") = util.rkey_from_uri("at://did:plc:abc/com.example.post/3k2y") } pub fn sha256_hex_stable_test() { let a = util.sha256_hex("hello") let b = util.sha256_hex("hello") assert a == b assert string.length(a) == 64 } pub fn oauth_loopback_client_id_test() { let id = oauth.loopback_client_id( "https://gleamview.boxd.sh/oauth/callback", oauth.default_scope, ) assert string.starts_with(id, "http://localhost?") assert string.contains(id, "redirect_uri=") assert string.contains(id, "scope=") }