package dev.ksan.etfoglasiserver.controller;

import dev.ksan.etfoglasiserver.model.RegisterTokenRequest;
import dev.ksan.etfoglasiserver.service.DeviceTokenService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetails;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class DeviceTokenControllerTest {

    @Mock
    DeviceTokenService deviceTokenService;

    @InjectMocks
    DeviceTokenController controller;

    @Test
    void register_savesNewToken() {

        UserDetails principal = mock(UserDetails.class);
        when(principal.getUsername()).thenReturn("test@test.com");

        RegisterTokenRequest req = new RegisterTokenRequest();
        req.setToken("fcm-123");

        ResponseEntity<Void> res = controller.register(req, principal);

        assertEquals(204, res.getStatusCode().value());

        verify(deviceTokenService).registerToken(
                "test@test.com",
                "fcm-123"
        );
    }
}