|
| 1 | +package clitests |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestAccountShow(t *testing.T) { |
| 9 | + assertOK(t, newHarness(t).Run("account", "show")) |
| 10 | +} |
| 11 | + |
| 12 | +func TestAccountSettingsUpdateWithCurrentName(t *testing.T) { |
| 13 | + h := newHarness(t) |
| 14 | + show := h.Run("account", "show") |
| 15 | + assertOK(t, show) |
| 16 | + currentName := show.GetDataString("name") |
| 17 | + if currentName == "" { |
| 18 | + t.Skip("account show returned no name") |
| 19 | + } |
| 20 | + assertOK(t, h.Run("account", "settings-update", "--name", currentName)) |
| 21 | + show = h.Run("account", "show") |
| 22 | + assertOK(t, show) |
| 23 | + if got := show.GetDataString("name"); got != currentName { |
| 24 | + t.Fatalf("expected account name %q after settings-update, got %q", currentName, got) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +func TestAccountEntropyWithCurrentValue(t *testing.T) { |
| 29 | + h := newHarness(t) |
| 30 | + show := h.Run("account", "show") |
| 31 | + assertOK(t, show) |
| 32 | + days := show.GetDataInt("auto_postpone_period_in_days") |
| 33 | + if days == 0 { |
| 34 | + days = 7 |
| 35 | + } |
| 36 | + assertOK(t, h.Run("account", "entropy", "--auto_postpone_period_in_days", strconv.Itoa(days))) |
| 37 | + show = h.Run("account", "show") |
| 38 | + assertOK(t, show) |
| 39 | + if got := show.GetDataInt("auto_postpone_period_in_days"); got != days { |
| 40 | + t.Fatalf("expected auto_postpone_period_in_days=%d, got %d", days, got) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +func TestAccountJoinCodeShow(t *testing.T) { |
| 45 | + assertOK(t, newHarness(t).Run("account", "join-code-show")) |
| 46 | +} |
| 47 | + |
| 48 | +func TestAccountExportCreateShow(t *testing.T) { |
| 49 | + h := newHarness(t) |
| 50 | + create := h.Run("account", "export-create") |
| 51 | + assertOK(t, create) |
| 52 | + exportID := create.GetDataString("id") |
| 53 | + if exportID == "" { |
| 54 | + exportID = mapValueString(create.GetDataMap(), "id") |
| 55 | + } |
| 56 | + if exportID == "" { |
| 57 | + t.Fatal("expected export ID in export-create response") |
| 58 | + } |
| 59 | + show := h.Run("account", "export-show", exportID) |
| 60 | + assertOK(t, show) |
| 61 | + if got := mapValueString(show.GetDataMap(), "id"); got != exportID { |
| 62 | + t.Fatalf("expected export-show id %q, got %q", exportID, got) |
| 63 | + } |
| 64 | + if got := mapValueString(show.GetDataMap(), "status"); got == "" { |
| 65 | + t.Fatal("expected export status in export-show response") |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +func TestUserList(t *testing.T) { |
| 70 | + result := newHarness(t).Run("user", "list") |
| 71 | + assertOK(t, result) |
| 72 | + if result.GetDataArray() == nil { |
| 73 | + t.Fatal("expected array response") |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestUserShowAndUpdateOwnProfile(t *testing.T) { |
| 78 | + h := newHarness(t) |
| 79 | + userID := currentUserID(t, h) |
| 80 | + show := h.Run("user", "show", userID) |
| 81 | + assertOK(t, show) |
| 82 | + currentName := show.GetDataString("name") |
| 83 | + if currentName == "" { |
| 84 | + t.Skip("user show returned no name") |
| 85 | + } |
| 86 | + assertOK(t, h.Run("user", "update", userID, "--name", currentName)) |
| 87 | + show = h.Run("user", "show", userID) |
| 88 | + assertOK(t, show) |
| 89 | + if got := show.GetDataString("name"); got != currentName { |
| 90 | + t.Fatalf("expected user name %q after update, got %q", currentName, got) |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +func TestUserAvatarUpdateAndRemove(t *testing.T) { |
| 95 | + h := newHarness(t) |
| 96 | + userID := currentUserID(t, h) |
| 97 | + fixturePath := fixtureFile(t, "test_image.png") |
| 98 | + |
| 99 | + show := h.Run("user", "show", userID) |
| 100 | + assertOK(t, show) |
| 101 | + avatarURL := show.GetDataString("avatar_url") |
| 102 | + if avatarURL == "" { |
| 103 | + t.Skip("user show returned no avatar_url") |
| 104 | + } |
| 105 | + initiallyAttached := avatarRedirects(t, avatarURL) |
| 106 | + if initiallyAttached { |
| 107 | + t.Cleanup(func() { |
| 108 | + assertOK(t, newHarness(t).Run("user", "update", userID, "--avatar", fixturePath)) |
| 109 | + if !avatarRedirects(t, avatarURL) { |
| 110 | + t.Fatal("expected avatar to be restored") |
| 111 | + } |
| 112 | + }) |
| 113 | + } |
| 114 | + |
| 115 | + assertOK(t, h.Run("user", "update", userID, "--avatar", fixturePath)) |
| 116 | + if !avatarRedirects(t, avatarURL) { |
| 117 | + t.Fatal("expected uploaded avatar endpoint to redirect to an image blob") |
| 118 | + } |
| 119 | + |
| 120 | + assertOK(t, h.Run("user", "avatar-remove", userID)) |
| 121 | + if avatarRedirects(t, avatarURL) { |
| 122 | + t.Fatal("expected avatar endpoint to fall back to generated SVG after removal") |
| 123 | + } |
| 124 | +} |
0 commit comments