|
| 1 | +package com.github.swent.echo.data.repository.datasources |
| 2 | + |
| 3 | +import com.github.swent.echo.data.model.Association |
| 4 | +import com.github.swent.echo.data.model.Event |
| 5 | +import com.github.swent.echo.data.model.Location |
| 6 | +import com.github.swent.echo.data.model.Tag |
| 7 | +import com.github.swent.echo.data.model.UserProfile |
| 8 | +import com.github.swent.echo.data.repository.datasources.Supabase as SupabaseSource |
| 9 | +import io.github.jan.supabase.SupabaseClient |
| 10 | +import io.github.jan.supabase.createSupabaseClient |
| 11 | +import io.github.jan.supabase.exceptions.UnauthorizedRestException |
| 12 | +import io.github.jan.supabase.gotrue.Auth |
| 13 | +import io.github.jan.supabase.postgrest.Postgrest |
| 14 | +import java.util.Arrays |
| 15 | +import java.util.Date |
| 16 | +import kotlinx.coroutines.runBlocking |
| 17 | +import kotlinx.serialization.SerializationException |
| 18 | +import org.junit.Assert.* |
| 19 | +import org.junit.Before |
| 20 | +import org.junit.Test |
| 21 | +import org.junit.function.ThrowingRunnable |
| 22 | + |
| 23 | +class SupabaseTest { |
| 24 | + private val supabaseUrl = "ulejnivguxeiibkbpwnb.supabase.co" |
| 25 | + private val supabasePublicKey = |
| 26 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVsZWpuaXZndXhlaWlia2Jwd25iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTA4MzgxODQsImV4cCI6MjAyNjQxNDE4NH0.9Hkj-Gox2XHcHfs_U2GyQFc9sZ_nu2Xs16-KYBri32g" |
| 27 | + private lateinit var supabaseClient: SupabaseClient |
| 28 | + private lateinit var source: SupabaseSource |
| 29 | + |
| 30 | + private val association = |
| 31 | + Association( |
| 32 | + "b0122e3e-82ed-4409-83f9-dbfb9761db20", |
| 33 | + "Dummy Assoc", |
| 34 | + "DO NOT DELETE/MODIFY: tests in repository.datasources.SupabaseTest will fail" |
| 35 | + ) |
| 36 | + private val tag = Tag("daba142a-a276-4b7e-824d-43ca088633ff", "Dummy Tag") |
| 37 | + private val event = |
| 38 | + Event( |
| 39 | + "3bcf6f25-81d4-4a14-9caa-c05feb593da0", |
| 40 | + "e65e9435-a9f2-4474-be11-9054305f1a54", |
| 41 | + "b0122e3e-82ed-4409-83f9-dbfb9761db20", |
| 42 | + "Dummy Event", |
| 43 | + "blabla description", |
| 44 | + Location("testLocation", 0.0, 0.0), |
| 45 | + Date(0), |
| 46 | + Date(1), |
| 47 | + HashSet<Tag>(Arrays.asList(tag)) |
| 48 | + ) |
| 49 | + private val userProfile = UserProfile("b0122e3e-82ed-4409-83f9-dbfb9761db20", "Dummy User") |
| 50 | + |
| 51 | + @Before |
| 52 | + fun setUp() { |
| 53 | + supabaseClient = |
| 54 | + createSupabaseClient(supabaseUrl, supabasePublicKey) { |
| 55 | + install(Auth) |
| 56 | + install(Postgrest) |
| 57 | + } |
| 58 | + source = SupabaseSource(supabaseClient) |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + fun getAssociationTest() { |
| 63 | + assertThrows( |
| 64 | + NoSuchElementException::class.java, |
| 65 | + ThrowingRunnable { |
| 66 | + runBlocking { source.getAssociation("b0122e3e-82ed-4409-83f9-dbfb9761db20") } |
| 67 | + } |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + fun setAssociationTest() { |
| 73 | + assertThrows( |
| 74 | + UnauthorizedRestException::class.java, |
| 75 | + ThrowingRunnable { runBlocking { source.setAssociation(association) } } |
| 76 | + ) |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + fun getAllAssociationsTest() { |
| 81 | + val associations = runBlocking { source.getAllAssociations() } |
| 82 | + assertNotNull(associations) |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + fun getEventTest() { |
| 87 | + assertThrows( |
| 88 | + NoSuchElementException::class.java, |
| 89 | + ThrowingRunnable { |
| 90 | + runBlocking { source.getEvent("3bcf6f25-81d4-4a14-9caa-c05feb593da0") } |
| 91 | + } |
| 92 | + ) |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + fun setEventTest() { |
| 97 | + assertThrows( |
| 98 | + SerializationException::class.java, |
| 99 | + ThrowingRunnable { runBlocking { source.setEvent(event) } } |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + fun getAllEventsTest() { |
| 105 | + val associations = runBlocking { source.getAllEvents() } |
| 106 | + assertNotNull(associations) |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + fun getTagTest() { |
| 111 | + assertThrows( |
| 112 | + NoSuchElementException::class.java, |
| 113 | + ThrowingRunnable { |
| 114 | + runBlocking { source.getTag("daba142a-a276-4b7e-824d-43ca088633ff") } |
| 115 | + } |
| 116 | + ) |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + fun setTagTest() { |
| 121 | + assertThrows( |
| 122 | + UnauthorizedRestException::class.java, |
| 123 | + ThrowingRunnable { runBlocking { source.setTag(tag) } } |
| 124 | + ) |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + fun getAllTagsTest() { |
| 129 | + val associations = runBlocking { source.getAllTags() } |
| 130 | + assertNotNull(associations) |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + fun getUserProfileTest() { |
| 135 | + assertThrows( |
| 136 | + NoSuchElementException::class.java, |
| 137 | + ThrowingRunnable { |
| 138 | + runBlocking { source.getUserProfile("b0122e3e-82ed-4409-83f9-dbfb9761db20") } |
| 139 | + } |
| 140 | + ) |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + fun setUserProfileTest() { |
| 145 | + assertThrows( |
| 146 | + UnauthorizedRestException::class.java, |
| 147 | + ThrowingRunnable { runBlocking { source.setUserProfile(userProfile) } } |
| 148 | + ) |
| 149 | + } |
| 150 | +} |
0 commit comments