Hello, Is it possible to mock supabase plugins ? I...
# supabase-kt
t
Hello, Is it possible to mock supabase plugins ? I tried this :
Copy code
declareMock<SupabaseClient> {
            every { auth } returns mockk {
                coEvery {
                    signInWith(Email) {
                        this.email = any()
                        this.password = any()
                    }
                } throws HttpRequestTimeoutException("<http://www.website.com|www.website.com>", 1000)
            }
        }
but got this error :
Copy code
java.lang.IllegalStateException: Plugin auth not installed or not of type Auth. Consider installing Auth within your SupabaseClientBuilder
	at io.github.jan.supabase.gotrue.AuthKt.getAuth(Auth.kt:409)
Thanks
Turns out it is possible by mocking the pluginManager :
Copy code
declareMock<SupabaseClient> {
            every { pluginManager } returns mockk {
                every { installedPlugins[Auth.key] } returns mockk<Auth> {
                    coEvery {
                        signInWith(Email) {
                            this.email = any()
                            this.password = any()
                        }
                    } throws HttpRequestTimeoutException("<http://www.website.com|www.website.com>", 1000)
                }
            }
        }
😮 1
j
Yea, the
auth
property only has a getter which calls
pluginManager.getPlugin(Auth)
. So that would be your best solution
t
Turns out the code wasn't really working, Here a better one for anyone looking for it :
Copy code
declareMock<SupabaseClient> {
            every { pluginManager } returns mockk {
                every { installedPlugins[Auth.key] } returns mockk<Auth> {
                    every { config } returns mockk<AuthConfig> {
                        every { defaultRedirectUrl } returns "<http://www.redirect.com|www.redirect.com>"
                    }
                    coEvery {
                        signInWith(Email, any(), any())
                    } throws BadRequestRestException("invalid_grant", mockk<HttpResponse> {
                        every { request } returns mockk<HttpRequest> {
                            every { url } returns Url("<http://www.website.com|www.website.com>")
                            every { headers } returns Headers.Empty
                            every { method } returns HttpMethod.Get
                        }
                    })
                }
            }
        }