package com.suno.android.common_data.repos import arrow.core.Either import arrow.retrofit.adapter.either.networkhandling.CallError import com.suno.android.common_networking.remote.entities.RemoteFollowArtistProfileBody import com.suno.android.common_networking.remote.profiles.ProfilesService import io.mockk.coEvery import io.mockk.coVerify import io.mockk.mockk import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test class DefaultProfilesRepositoryTest { private val profilesService = mockk() private val subject = DefaultProfilesRepository(profilesService) @Test fun `given currently following creator when followArtistProfile called then sends unfollow action`() = runTest { val handle = "test_handle" val currentlyFollowing = true coEvery { profilesService.followArtistProfile(any()) } returns Either.Right(Unit) val result = subject.followArtistProfile( handle = handle, unfollow = currentlyFollowing, recommendationMetadata = null, ) assertTrue(result.isRight()) coVerify { profilesService.followArtistProfile( RemoteFollowArtistProfileBody( handle = handle, unfollow = true, recommendationMetadata = null, ), ) } } @Test fun `given currently not following creator when followArtistProfile called then sends follow action`() = runTest { val handle = "test_handle" val currentlyFollowing = false coEvery { profilesService.followArtistProfile(any()) } returns Either.Right(Unit) val result = subject.followArtistProfile( handle = handle, unfollow = currentlyFollowing, recommendationMetadata = null, ) assertTrue(result.isRight()) coVerify { profilesService.followArtistProfile( RemoteFollowArtistProfileBody( handle = handle, unfollow = false, recommendationMetadata = null, ), ) } } @Test fun `given error when followArtistProfile called then returns error`() = runTest { val handle = "test_handle" val currentlyFollowing = false val expectedError = mockk() coEvery { profilesService.followArtistProfile(any()) } returns Either.Left(expectedError) val result = subject.followArtistProfile( handle = handle, unfollow = currentlyFollowing, recommendationMetadata = null, ) assertTrue(result.isLeft()) assertEquals(expectedError, result.leftOrNull()) } }