@@ -137,13 +137,38 @@ func TestService_DiscoverOnlyCreatorsWithPublicCarts(t *testing.T) {
137137 pc := publicCart (t , env .cartsSvc , privateOnly , "Bob Secret" )
138138 makePrivate (t , env .cartsSvc , privateOnly , pc .ID )
139139
140- rows , err := env .svc .DiscoverCreators (ctx , 50 , 0 )
140+ // viewerID 0 → anonymous → excludes nobody.
141+ rows , err := env .svc .DiscoverCreators (ctx , 0 , 50 , 0 )
141142 require .NoError (t , err )
142143 require .Len (t , rows , 1 )
143144 assert .Equal (t , withPublic , rows [0 ].ID )
144145 assert .Equal (t , int64 (1 ), rows [0 ].CartCount )
145146}
146147
148+ func TestService_DiscoverExcludesViewer (t * testing.T ) {
149+ env := setupSvc (t )
150+ ctx := context .Background ()
151+
152+ viewer := newUser (t , env .q , "g-dv1" , "viewer@example.com" , "Viewer" )
153+ other := newUser (t , env .q , "g-dv2" , "other@example.com" , "Other" )
154+ publicCart (t , env .cartsSvc , viewer , "Viewer Cart" )
155+ publicCart (t , env .cartsSvc , other , "Other Cart" )
156+
157+ // Logged-out (viewerID 0) sees both creators.
158+ anon , err := env .svc .DiscoverCreators (ctx , 0 , 50 , 0 )
159+ require .NoError (t , err )
160+ require .Len (t , anon , 2 )
161+ assert .True (t , containsID (anon , viewer ))
162+ assert .True (t , containsID (anon , other ))
163+
164+ // Logged-in viewer is excluded from their own discover list.
165+ rows , err := env .svc .DiscoverCreators (ctx , viewer , 50 , 0 )
166+ require .NoError (t , err )
167+ require .Len (t , rows , 1 )
168+ assert .Equal (t , other , rows [0 ].ID )
169+ assert .False (t , containsID (rows , viewer ), "viewer must not appear in their own discover list" )
170+ }
171+
147172func TestService_DiscoverOrderedBy7dViews (t * testing.T ) {
148173 env := setupSvc (t )
149174 ctx := context .Background ()
@@ -156,7 +181,7 @@ func TestService_DiscoverOrderedBy7dViews(t *testing.T) {
156181 seedViews (t , env .pool , lowCart .ID , 3 )
157182 seedViews (t , env .pool , highCart .ID , 99 )
158183
159- rows , err := env .svc .DiscoverCreators (ctx , 50 , 0 )
184+ rows , err := env .svc .DiscoverCreators (ctx , 0 , 50 , 0 )
160185 require .NoError (t , err )
161186 require .Len (t , rows , 2 )
162187 assert .Equal (t , high , rows [0 ].ID , "highest 7-day views should rank first" )
@@ -185,12 +210,35 @@ func TestService_SearchByHandleSubstring(t *testing.T) {
185210 publicCart (t , env .cartsSvc , other , "F Cart" )
186211
187212 // "eld" is a substring of the handle "zelda" but not of "frank".
188- rows , err := env .svc .SearchCreators (ctx , "eld" , 50 , 0 )
213+ rows , err := env .svc .SearchCreators (ctx , 0 , "eld" , 50 , 0 )
189214 require .NoError (t , err )
190215 require .Len (t , rows , 1 )
191216 assert .Equal (t , match , rows [0 ].ID )
192217}
193218
219+ func TestService_SearchExcludesViewer (t * testing.T ) {
220+ env := setupSvc (t )
221+ ctx := context .Background ()
222+
223+ // Both handles contain the "nova" token; the viewer must be excluded.
224+ viewer := newUser (t , env .q , "g-sv1" , "nova-me@example.com" , "Nova Me" )
225+ other := newUser (t , env .q , "g-sv2" , "nova-you@example.com" , "Nova You" )
226+ publicCart (t , env .cartsSvc , viewer , "Viewer Cart" )
227+ publicCart (t , env .cartsSvc , other , "Other Cart" )
228+
229+ // Logged-out (viewerID 0) matches both.
230+ anon , err := env .svc .SearchCreators (ctx , 0 , "nova" , 50 , 0 )
231+ require .NoError (t , err )
232+ require .Len (t , anon , 2 )
233+
234+ // Logged-in viewer is excluded from their own search results.
235+ rows , err := env .svc .SearchCreators (ctx , viewer , "nova" , 50 , 0 )
236+ require .NoError (t , err )
237+ require .Len (t , rows , 1 )
238+ assert .Equal (t , other , rows [0 ].ID )
239+ assert .False (t , containsID (rows , viewer ), "viewer must not appear in their own search results" )
240+ }
241+
194242func TestService_SearchByDisplayNameCaseInsensitive (t * testing.T ) {
195243 env := setupSvc (t )
196244 ctx := context .Background ()
@@ -202,7 +250,7 @@ func TestService_SearchByDisplayNameCaseInsensitive(t *testing.T) {
202250
203251 // Lowercase query matches the display name "Aurora Borealis" case-insensitively
204252 // (and does not match the handle "user1").
205- rows , err := env .svc .SearchCreators (ctx , "aurora" , 50 , 0 )
253+ rows , err := env .svc .SearchCreators (ctx , 0 , "aurora" , 50 , 0 )
206254 require .NoError (t , err )
207255 require .Len (t , rows , 1 )
208256 assert .Equal (t , match , rows [0 ].ID )
@@ -223,7 +271,7 @@ func TestService_SearchPrefixRanksAboveSubstring(t *testing.T) {
223271 seedViews (t , env .pool , prefixCart .ID , 1 )
224272 seedViews (t , env .pool , substrCart .ID , 99 )
225273
226- rows , err := env .svc .SearchCreators (ctx , "sun" , 50 , 0 )
274+ rows , err := env .svc .SearchCreators (ctx , 0 , "sun" , 50 , 0 )
227275 require .NoError (t , err )
228276 require .Len (t , rows , 2 )
229277 assert .Equal (t , prefix , rows [0 ].ID , "prefix match ranks above substring despite fewer views" )
@@ -245,7 +293,7 @@ func TestService_SearchExcludesPrivateOnlyAndBanned(t *testing.T) {
245293 publicCart (t , env .cartsSvc , banned , "Nova Banned Cart" )
246294 banUser (t , env .pool , banned )
247295
248- rows , err := env .svc .SearchCreators (ctx , "nova" , 50 , 0 )
296+ rows , err := env .svc .SearchCreators (ctx , 0 , "nova" , 50 , 0 )
249297 require .NoError (t , err )
250298 require .Len (t , rows , 1 , "only the creator with a public cart, not banned" )
251299 assert .Equal (t , withPublic , rows [0 ].ID )
@@ -263,14 +311,14 @@ func TestService_SearchEscapesWildcards(t *testing.T) {
263311 publicCart (t , env .cartsSvc , b , "Bravo Cart" )
264312
265313 // A bare "%" must be treated as a literal (escaped), not a match-all wildcard.
266- rows , err := env .svc .SearchCreators (ctx , "%" , 50 , 0 )
314+ rows , err := env .svc .SearchCreators (ctx , 0 , "%" , 50 , 0 )
267315 require .NoError (t , err )
268316 assert .Empty (t , rows , "literal %% should not match every creator" )
269317 assert .False (t , containsID (rows , a ))
270318 assert .False (t , containsID (rows , b ))
271319
272320 // "_" is likewise literal: it must not single-character-wildcard-match.
273- rows , err = env .svc .SearchCreators (ctx , "_" , 50 , 0 )
321+ rows , err = env .svc .SearchCreators (ctx , 0 , "_" , 50 , 0 )
274322 require .NoError (t , err )
275323 assert .Empty (t , rows , "literal _ should not match" )
276324}
@@ -299,10 +347,21 @@ func TestService_GetCreatorProfile(t *testing.T) {
299347 assert .Equal (t , 1 , profile .CartCount , "only the public, non-archived cart counts" )
300348 assert .Equal (t , 1 , profile .FollowerCount )
301349 assert .True (t , profile .IsFollowing )
350+ assert .False (t , profile .IsSelf , "a different viewer is not the profile owner" )
302351 require .Len (t , cartsJSON , 1 )
303352 assert .Equal (t , "Visible" , cartsJSON [0 ].Title )
304353 // Public context must not leak analytics.
305354 assert .Equal (t , 0 , cartsJSON [0 ].ViewsLast7d )
355+
356+ // Anonymous viewer (0) is never self.
357+ anon , _ , err := env .svc .GetCreatorProfile (ctx , "priya" , 0 )
358+ require .NoError (t , err )
359+ assert .False (t , anon .IsSelf , "anonymous viewer is never the profile owner" )
360+
361+ // The creator viewing their own profile → isSelf true.
362+ own , _ , err := env .svc .GetCreatorProfile (ctx , "priya" , creator )
363+ require .NoError (t , err )
364+ assert .True (t , own .IsSelf , "the owner viewing their own profile is self" )
306365}
307366
308367func TestService_GetCreatorProfile_UnknownHandle (t * testing.T ) {
0 commit comments