001package com.studentgui.apphelpers;
002
003import java.time.LocalDate;
004
005import static org.junit.jupiter.api.Assertions.assertEquals;
006import static org.junit.jupiter.api.Assertions.assertNotNull;
007import org.junit.jupiter.api.Test;
008
009/**
010 * Tests saving and retrieving contact log entries in the application's
011 * database layer.
012 */
013
014public class DatabaseContactLogTest {
015
016    @Test
017    /**
018     * Save a contact log entry and verify it can be retrieved from the DB.
019     */
020
021    public void testSaveAndFetchContactLog() throws Exception {
022        SqlGenerate.initializeDatabase();
023        String student = "Test Student";
024        int sid = Database.getOrCreateStudent(student);
025        int pt = Database.getOrCreateProgressType("ContactLog");
026        int sessionId = Database.createProgressSession(sid, pt, LocalDate.now());
027        Database.saveContactLog(sessionId, student, LocalDate.now().toString(), "Guardian A", "Phone", "+1234567890", "a@example.com", "Left voicemail", "General summary", "Specific item", "Detailed notes");
028    com.studentgui.apphelpers.dto.ContactPayload fetched = Database.fetchLatestContactLog(student);
029    assertNotNull(fetched);
030    assertEquals("Guardian A", fetched.guardian);
031    assertEquals("+1234567890", fetched.phone);
032    assertEquals("Detailed notes", fetched.notes);
033    }
034}