package ru.ulstu.is.cbapp;

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 ru.ulstu.is.cbapp.models.Student;
import ru.ulstu.is.cbapp.models.Category;
import ru.ulstu.is.cbapp.service.StudentService;
import ru.ulstu.is.cbapp.service.CategoryService;

@SpringBootTest
public class CategoryServiceTests {
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private StudentService studentService;


    @Test
    public void testAddStudent() {
        studentService.deleteAllStudents();
        categoryService.deleteAllCategories();

        Category p = categoryService.addCategory("Category");
        Student e = studentService.addStudent("1", "2", "33");

        studentService.addCategory(e.getId(), p);
        Assertions.assertTrue(studentService.findStudent(e.getId()).getCategories().contains(p));
        Assertions.assertTrue(categoryService.findCategory(p.getId()).getStudents().contains(e));

        studentService.deleteAllStudents();
        categoryService.deleteAllCategories();

    }

    @Test
    public void testDeleteStudent() {
        studentService.deleteAllStudents();
        categoryService.deleteAllCategories();

        Category p = categoryService.addCategory("Category");
        Student e1 = studentService.addStudent("1", "2", "33");

        studentService.addCategory(e1.getId(), p);
        studentService.deleteCategory(e1.getId(), p);
        Assertions.assertFalse(studentService.findStudent(e1.getId()).getCategories().contains(p));
        Assertions.assertFalse(categoryService.findCategory(p.getId()).getStudents().contains(e1));

        studentService.deleteAllStudents();
        categoryService.deleteAllCategories();

    }
}
