Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for session use case #40

Merged
merged 8 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/callhub/connect/entities/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Document("sessions")
public class Session {
Expand Down Expand Up @@ -51,4 +52,11 @@ public void setInactive(){
this.active = false;
}

public boolean getIsActive() {
return this.active;
}

public List<String> getDocuments() {
return this.documents;
}
}

This file was deleted.

95 changes: 95 additions & 0 deletions src/test/java/callhub/connect/session/SessionControllerTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package callhub.connect.session;

import callhub.connect.data_access.DocumentRepository;
import callhub.connect.data_access.SessionRepository;
import callhub.connect.entities.FileDocument;
import callhub.connect.entities.Session;
import callhub.connect.interface_adapter.session.SessionController;
import callhub.connect.use_case.session.SessionInputBoundary;
import callhub.connect.use_case.session.SessionInputData;
import callhub.connect.use_case.session.SessionInteractor;
import callhub.connect.use_case.session.*;
import org.bson.types.Binary;
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.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.ResponseEntity;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.RequestBuilder;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import java.time.LocalDate;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@SpringBootTest
@AutoConfigureMockMvc
public class SessionControllerTests {

@Autowired
MockMvc mockMvc;

@MockBean
public SessionRepository sessionRepository;


@Test
public void createSessionTest() throws Exception {
when(sessionRepository.save(any())).thenReturn(new Session(
true,
"ABCDEF"
));

RequestBuilder request = get("/session/new-session?code=ABCDEF");
mockMvc.perform(request).andExpect(status().isOk());
}

@Test
void testJoinSession() throws Exception {
Session mockSession = new Session(true, "ABCDEF");

when(sessionRepository.getSessionsByActiveAndCode(anyBoolean(), anyString())).thenReturn(mockSession);

// Perform the request and verify the response
mockMvc.perform(get("/session/join/ABCDEF"))
.andExpect(status().isOk());
}

@Test
void testEndSession() throws Exception {
Session mockSession = new Session(true, "ABCDEF");
when(sessionRepository.getSessionsByActiveAndCode(anyBoolean(), anyString())).thenReturn(mockSession);

// Perform the request and verify the response
mockMvc.perform(get("/session/end-session/ABCDEF"))
.andExpect(status().isOk());
assert !mockSession.getIsActive();
}


@Test
void testAllSession() throws Exception {
Session mockSession = new Session(true, "ABCDEF");

when(sessionRepository.getSessionsByActiveAndCode(anyBoolean(), anyString())).thenReturn(mockSession);
when(sessionRepository.save(any())).thenReturn(mockSession);

RequestBuilder newRequest = get("/session/new-session?code=ABCDEF");
mockMvc.perform(newRequest).andExpect(status().isOk());

RequestBuilder joinRequest = get("/session/join/ABCDEF");
mockMvc.perform(joinRequest).andExpect(status().isOk());

RequestBuilder endRequest = get("/session/end-session/ABCDEF");
mockMvc.perform(endRequest).andExpect(status().isOk());
}
}
Loading