package com.example.springip;

import com.example.springip.lab3.models.Employee;
import com.example.springip.lab3.models.Position;
import com.example.springip.lab3.service.EmployeeService;
import com.example.springip.lab3.service.PositionService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;

@SpringBootTest
public class PositionServiceTests {
    @Autowired
    private PositionService positionService;

    @Autowired
    private EmployeeService employeeService;


    @Test
    public void testAddEmployee() {
        employeeService.deleteAllEmployees();
        positionService.deleteAllPositions();

        Position p = positionService.addPosition("Position");
        Employee e = employeeService.addEmployee("1", "2", "33");

        employeeService.addPosition(e.getId(), p);
        Assertions.assertTrue(employeeService.findEmployee(e.getId()).getPositions().contains(p));
        Assertions.assertTrue(positionService.findPosition(p.getId()).getEmployees().contains(e));

        employeeService.deleteAllEmployees();
        positionService.deleteAllPositions();

    }

    @Test
    public void testDeleteEmployee() {
        employeeService.deleteAllEmployees();
        positionService.deleteAllPositions();

        Position p = positionService.addPosition("Position");
        Employee e = employeeService.addEmployee("1", "2", "33");

        employeeService.addPosition(e.getId(), p);
        employeeService.deletePosition(e.getId(), p);
        Assertions.assertFalse(employeeService.findEmployee(e.getId()).getPositions().contains(p));
        Assertions.assertFalse(positionService.findPosition(p.getId()).getEmployees().contains(e));

        employeeService.deleteAllEmployees();
        positionService.deleteAllPositions();

    }
}
