package com.flagship.abox.manager.domain

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class DomainResultTest {
    @Test
    fun successContainsTypedValue() {
        val result: DomainResult<SocketPowerState> = DomainResult.Success(SocketPowerState.ON)

        assertEquals(SocketPowerState.ON, (result as DomainResult.Success).value)
    }

    @Test
    fun failureKeepsExternalCodeWithoutSdkTypes() {
        val error = DomainError.DeviceOffline(externalCode = "20504")
        val result: DomainResult<Unit> = DomainResult.Failure(error)

        assertTrue(result is DomainResult.Failure)
        assertEquals("20504", (result as DomainResult.Failure).error.externalCode)
    }

    @Test
    fun credentialStringsDoNotExposePassword() {
        val plaintext = "secret-password"
        val password = Password(plaintext)
        val credentials = LoginCredentials(Username("demo"), password)

        assertFalse(password.toString().contains(plaintext))
        assertFalse(credentials.toString().contains(plaintext))
        assertTrue(credentials.toString().contains("Password(***)"))
    }
}
