(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func TestGetAllUsers(t *testing.T) { |
| 112 | t.Run("success with multiple users", func(t *testing.T) { |
| 113 | db := testutils.InitMemoryDB(t) |
| 114 | |
| 115 | user1 := testutils.SetupUserData(db, "alice@example.com", "password123") |
| 116 | user2 := testutils.SetupUserData(db, "bob@example.com", "password123") |
| 117 | user3 := testutils.SetupUserData(db, "charlie@example.com", "password123") |
| 118 | |
| 119 | a := NewTest() |
| 120 | a.DB = db |
| 121 | |
| 122 | users, err := a.GetAllUsers() |
| 123 | |
| 124 | assert.Equal(t, err, nil, "should not error") |
| 125 | assert.Equal(t, len(users), 3, "should return 3 users") |
| 126 | |
| 127 | // Verify all users are returned |
| 128 | emails := make(map[string]bool) |
| 129 | for _, user := range users { |
| 130 | emails[user.Email.String] = true |
| 131 | } |
| 132 | assert.Equal(t, emails["alice@example.com"], true, "alice should be in results") |
| 133 | assert.Equal(t, emails["bob@example.com"], true, "bob should be in results") |
| 134 | assert.Equal(t, emails["charlie@example.com"], true, "charlie should be in results") |
| 135 | |
| 136 | // Verify user details match |
| 137 | for _, user := range users { |
| 138 | if user.Email.String == "alice@example.com" { |
| 139 | assert.Equal(t, user.ID, user1.ID, "alice ID mismatch") |
| 140 | } else if user.Email.String == "bob@example.com" { |
| 141 | assert.Equal(t, user.ID, user2.ID, "bob ID mismatch") |
| 142 | } else if user.Email.String == "charlie@example.com" { |
| 143 | assert.Equal(t, user.ID, user3.ID, "charlie ID mismatch") |
| 144 | } |
| 145 | } |
| 146 | }) |
| 147 | |
| 148 | t.Run("empty database", func(t *testing.T) { |
| 149 | db := testutils.InitMemoryDB(t) |
| 150 | |
| 151 | a := NewTest() |
| 152 | a.DB = db |
| 153 | |
| 154 | users, err := a.GetAllUsers() |
| 155 | |
| 156 | assert.Equal(t, err, nil, "should not error") |
| 157 | assert.Equal(t, len(users), 0, "should return 0 users") |
| 158 | }) |
| 159 | |
| 160 | t.Run("single user", func(t *testing.T) { |
| 161 | db := testutils.InitMemoryDB(t) |
| 162 | |
| 163 | user := testutils.SetupUserData(db, "alice@example.com", "password123") |
| 164 | |
| 165 | a := NewTest() |
| 166 | a.DB = db |
| 167 | |
| 168 | users, err := a.GetAllUsers() |
nothing calls this directly
no test coverage detected