package com.github.nullptroma.wallenc.ui.screens.main.screens.storage.twofa

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class OtpAuthUriParserTest {

    @Test
    fun parsesStandardTotpUri() {
        val uri = "otpauth://totp/GitHub:user@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub&digits=6&period=30"
        val parsed = parseOtpAuthTotpUri(uri)
        assertNotNull(parsed)
        assertEquals("GitHub", parsed!!.issuer)
        assertEquals("user@example.com", parsed.account)
        assertEquals("JBSWY3DPEHPK3PXP", parsed.secret)
        assertEquals(6, parsed.digits)
        assertEquals(30, parsed.periodSeconds)
        assertEquals("SHA1", parsed.algorithm)
    }

    @Test
    fun rejectsNonOtpauthScheme() {
        assertNull(parseOtpAuthTotpUri("https://example.com"))
    }

    @Test
    fun rejectsMissingSecret() {
        assertNull(parseOtpAuthTotpUri("otpauth://totp/Test:account"))
    }
}
