TestFormatBlocklist covers the response shaping for GET /user/blocklist: a nil blocklist yields an empty list (never null) and an empty dhash, and a populated blocklist stringifies every JID and passes the dhash through.
(t *testing.T)
| 13 | // a nil blocklist yields an empty list (never null) and an empty dhash, and a |
| 14 | // populated blocklist stringifies every JID and passes the dhash through. |
| 15 | func TestFormatBlocklist(t *testing.T) { |
| 16 | t.Run("nil yields empty list and dhash", func(t *testing.T) { |
| 17 | got := formatBlocklist(nil) |
| 18 | jids, ok := got["Blocklist"].([]string) |
| 19 | if !ok { |
| 20 | t.Fatalf("Blocklist is not []string: %T", got["Blocklist"]) |
| 21 | } |
| 22 | if len(jids) != 0 { |
| 23 | t.Errorf("len(Blocklist) = %d; want 0", len(jids)) |
| 24 | } |
| 25 | if got["DHash"] != "" { |
| 26 | t.Errorf("DHash = %v; want empty", got["DHash"]) |
| 27 | } |
| 28 | }) |
| 29 | |
| 30 | t.Run("stringifies JIDs and passes dhash through", func(t *testing.T) { |
| 31 | j1, ok1 := parseJID("5491155554445") |
| 32 | j2, ok2 := parseJID("5491155553935") |
| 33 | if !ok1 || !ok2 { |
| 34 | t.Fatalf("parseJID failed: ok1=%v ok2=%v", ok1, ok2) |
| 35 | } |
| 36 | bl := &types.Blocklist{DHash: "1234567890", JIDs: []types.JID{j1, j2}} |
| 37 | |
| 38 | got := formatBlocklist(bl) |
| 39 | jids := got["Blocklist"].([]string) |
| 40 | if len(jids) != len(bl.JIDs) { |
| 41 | t.Fatalf("len(Blocklist) = %d; want %d", len(jids), len(bl.JIDs)) |
| 42 | } |
| 43 | for i := range bl.JIDs { |
| 44 | if jids[i] != bl.JIDs[i].String() { |
| 45 | t.Errorf("Blocklist[%d] = %q; want %q", i, jids[i], bl.JIDs[i].String()) |
| 46 | } |
| 47 | } |
| 48 | if got["DHash"] != "1234567890" { |
| 49 | t.Errorf("DHash = %v; want %q", got["DHash"], "1234567890") |
| 50 | } |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | // TestGetBlocklistEndpoint exercises GET /user/blocklist through the real router |
| 55 | // and auth middleware. With no WhatsApp client connected in tests, the handler |
nothing calls this directly
no test coverage detected