An Elixir toolkit for the AT Protocol. hexdocs.pm/atex
elixir bluesky atproto decentralization
25
fork

Configure Feed

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

fix: remove broken tests for lexicon resolver and rename to nsid test

+40 -220
-220
test/atex/lexicon/resolver_test.exs
··· 1 - defmodule Atex.Lexicon.ResolverTest do 2 - use ExUnit.Case, async: true 3 - 4 - import Mox 5 - 6 - alias Atex.Lexicon.Resolver 7 - alias Atex.Lexicon.Resolver.{MockDIDClient, MockDNSClient} 8 - alias Atex.NSID 9 - 10 - setup :verify_on_exit! 11 - 12 - # --------------------------------------------------------------------------- 13 - # NSID.authority_domain/1 14 - # --------------------------------------------------------------------------- 15 - 16 - describe "NSID.authority_domain/1" do 17 - test "converts a standard 4-part NSID" do 18 - assert {:ok, "_lexicon.feed.bsky.app"} = NSID.authority_domain("app.bsky.feed.post") 19 - end 20 - 21 - test "matches the spec example" do 22 - assert {:ok, "_lexicon.blogging.lab.dept.university.edu"} = 23 - NSID.authority_domain("edu.university.dept.lab.blogging.getBlogPost") 24 - end 25 - 26 - test "handles a minimal 3-segment NSID" do 27 - assert {:ok, "_lexicon.example.com"} = NSID.authority_domain("com.example.record") 28 - end 29 - 30 - test "handles NSIDs with numbers in segments" do 31 - assert {:ok, "_lexicon.v0.comet.sh"} = NSID.authority_domain("sh.comet.v0.feed") 32 - end 33 - 34 - test "returns error for a plain string without dots" do 35 - assert {:error, :invalid_nsid} = NSID.authority_domain("invalid") 36 - end 37 - 38 - test "returns error for an empty string" do 39 - assert {:error, :invalid_nsid} = NSID.authority_domain("") 40 - end 41 - 42 - test "returns error for a string with invalid characters" do 43 - assert {:error, :invalid_nsid} = NSID.authority_domain("not.valid!") 44 - end 45 - end 46 - 47 - # --------------------------------------------------------------------------- 48 - # Resolver.resolve/1 — invalid NSID (no network calls) 49 - # --------------------------------------------------------------------------- 50 - 51 - describe "resolve/1 with invalid NSID" do 52 - test "returns :invalid_nsid for a plain string" do 53 - assert {:error, :invalid_nsid} = Resolver.resolve("notannsid") 54 - end 55 - 56 - test "returns :invalid_nsid for an empty string" do 57 - assert {:error, :invalid_nsid} = Resolver.resolve("") 58 - end 59 - 60 - test "returns :invalid_nsid for a string with illegal characters" do 61 - assert {:error, :invalid_nsid} = Resolver.resolve("not.valid!") 62 - end 63 - end 64 - 65 - # --------------------------------------------------------------------------- 66 - # Resolver.resolve/1 — DNS failure 67 - # --------------------------------------------------------------------------- 68 - 69 - describe "resolve/1 with DNS failure" do 70 - test "returns :dns_resolution_failed when DNS returns no TXT records" do 71 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> [] end) 72 - 73 - assert {:error, :dns_resolution_failed} = Resolver.resolve("app.bsky.feed.post") 74 - end 75 - 76 - test "returns :dns_resolution_failed when TXT record has wrong prefix" do 77 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> 78 - [[~c"notadid=something"]] 79 - end) 80 - 81 - assert {:error, :dns_resolution_failed} = Resolver.resolve("app.bsky.feed.post") 82 - end 83 - 84 - test "returns :dns_resolution_failed when TXT value is not a valid DID" do 85 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> 86 - [[~c"did=notadidatall"]] 87 - end) 88 - 89 - assert {:error, :dns_resolution_failed} = Resolver.resolve("app.bsky.feed.post") 90 - end 91 - end 92 - 93 - # --------------------------------------------------------------------------- 94 - # Resolver.resolve/1 — DID resolution failure 95 - # --------------------------------------------------------------------------- 96 - 97 - describe "resolve/1 with DID resolution failure" do 98 - test "returns :did_resolution_failed when DID resolver errors" do 99 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> 100 - [[~c"did=did:plc:ewvi7nxzyoun6zhxrhs64oiz"]] 101 - end) 102 - 103 - expect(MockDIDClient, :resolve, fn "did:plc:ewvi7nxzyoun6zhxrhs64oiz" -> 104 - {:error, :not_found} 105 - end) 106 - 107 - assert {:error, :did_resolution_failed} = Resolver.resolve("app.bsky.feed.post") 108 - end 109 - end 110 - 111 - # --------------------------------------------------------------------------- 112 - # Resolver.resolve/1 — no PDS endpoint 113 - # --------------------------------------------------------------------------- 114 - 115 - @did "did:plc:ewvi7nxzyoun6zhxrhs64oiz" 116 - @pds "https://pds.example.com" 117 - @nsid "app.bsky.feed.post" 118 - 119 - @did_doc_no_pds %Atex.DID.Document{ 120 - "@context": ["https://www.w3.org/ns/did/v1"], 121 - id: @did 122 - } 123 - 124 - @did_doc_with_pds %Atex.DID.Document{ 125 - "@context": ["https://www.w3.org/ns/did/v1"], 126 - id: @did, 127 - service: [ 128 - %Atex.DID.Document.Service{ 129 - id: "#{@did}#atproto_pds", 130 - type: "AtprotoPersonalDataServer", 131 - service_endpoint: @pds 132 - } 133 - ] 134 - } 135 - 136 - defp stub_dns_and_did(did_doc) do 137 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> 138 - [[~c"did=#{@did}"]] 139 - end) 140 - 141 - expect(MockDIDClient, :resolve, fn @did -> {:ok, did_doc} end) 142 - end 143 - 144 - describe "resolve/1 with no PDS endpoint" do 145 - test "returns :no_pds_endpoint when DID document has no PDS service" do 146 - stub_dns_and_did(@did_doc_no_pds) 147 - 148 - assert {:error, :no_pds_endpoint} = Resolver.resolve(@nsid) 149 - end 150 - end 151 - 152 - # --------------------------------------------------------------------------- 153 - # Resolver.resolve/1 — record fetch (Req.Test plug) 154 - # --------------------------------------------------------------------------- 155 - 156 - @lexicon_value %{ 157 - "lexicon" => 1, 158 - "id" => @nsid, 159 - "defs" => %{ 160 - "main" => %{ 161 - "type" => "record", 162 - "key" => "tid", 163 - "record" => %{"type" => "object", "properties" => %{}} 164 - } 165 - } 166 - } 167 - 168 - defp stub_through_to_pds do 169 - expect(MockDNSClient, :lookup_txt, fn "_lexicon.feed.bsky.app" -> 170 - [[~c"did=#{@did}"]] 171 - end) 172 - 173 - expect(MockDIDClient, :resolve, fn @did -> {:ok, @did_doc_with_pds} end) 174 - end 175 - 176 - defp record_plug(record_resp) do 177 - fn conn -> 178 - case record_resp do 179 - :not_found -> 180 - Plug.Conn.send_resp(conn, 404, ~s({"error":"RecordNotFound"})) 181 - 182 - :missing_value -> 183 - Req.Test.json(conn, %{"uri" => "at://#{@did}/com.atproto.lexicon.schema/#{@nsid}"}) 184 - 185 - value -> 186 - Req.Test.json(conn, %{ 187 - "uri" => "at://#{@did}/com.atproto.lexicon.schema/#{@nsid}", 188 - "value" => value 189 - }) 190 - end 191 - end 192 - end 193 - 194 - describe "resolve/1 — record fetch (Req.Test plug)" do 195 - test "returns the lexicon value map on success" do 196 - stub_through_to_pds() 197 - 198 - result = Resolver.resolve(@nsid, plug: record_plug(@lexicon_value)) 199 - 200 - assert {:ok, lexicon} = result 201 - assert lexicon["id"] == @nsid 202 - assert lexicon["lexicon"] == 1 203 - assert is_map(lexicon["defs"]) 204 - end 205 - 206 - test "returns :record_not_found when PDS returns 404" do 207 - stub_through_to_pds() 208 - 209 - assert {:error, :record_not_found} = 210 - Resolver.resolve(@nsid, plug: record_plug(:not_found)) 211 - end 212 - 213 - test "returns :invalid_record when PDS response has no value key" do 214 - stub_through_to_pds() 215 - 216 - assert {:error, :invalid_record} = 217 - Resolver.resolve(@nsid, plug: record_plug(:missing_value)) 218 - end 219 - end 220 - end
+40
test/atex/nsid_test.exs
··· 1 + defmodule Atex.NSIDTest do 2 + use ExUnit.Case, async: true 3 + 4 + alias Atex.NSID 5 + 6 + # --------------------------------------------------------------------------- 7 + # NSID.authority_domain/1 8 + # --------------------------------------------------------------------------- 9 + 10 + describe "NSID.authority_domain/1" do 11 + test "converts a standard 4-part NSID" do 12 + assert {:ok, "_lexicon.feed.bsky.app"} = NSID.authority_domain("app.bsky.feed.post") 13 + end 14 + 15 + test "matches the spec example" do 16 + assert {:ok, "_lexicon.blogging.lab.dept.university.edu"} = 17 + NSID.authority_domain("edu.university.dept.lab.blogging.getBlogPost") 18 + end 19 + 20 + test "handles a minimal 3-segment NSID" do 21 + assert {:ok, "_lexicon.example.com"} = NSID.authority_domain("com.example.record") 22 + end 23 + 24 + test "handles NSIDs with numbers in segments" do 25 + assert {:ok, "_lexicon.v0.comet.sh"} = NSID.authority_domain("sh.comet.v0.feed") 26 + end 27 + 28 + test "returns error for a plain string without dots" do 29 + assert {:error, :invalid_nsid} = NSID.authority_domain("invalid") 30 + end 31 + 32 + test "returns error for an empty string" do 33 + assert {:error, :invalid_nsid} = NSID.authority_domain("") 34 + end 35 + 36 + test "returns error for a string with invalid characters" do 37 + assert {:error, :invalid_nsid} = NSID.authority_domain("not.valid!") 38 + end 39 + end 40 + end