1- package data.repositories
2-
3- import com.google.common.truth.Truth.assertThat
4- import data.csv_data.datasource.AuditLogDataSource
5- import data.csv_data.mappers.toDto
6- import data.csv_data.repositories.AuditRepositoryImpl
7- import domain.models.AuditLog
8- import domain.models.AuditLog.AuditType
9- import io.mockk.every
10- import io.mockk.mockk
11- import io.mockk.verify
12- import kotlinx.datetime.LocalDateTime
13- import org.junit.jupiter.api.Assertions.assertTrue
14- import org.junit.jupiter.api.BeforeEach
15- import org.junit.jupiter.api.Test
16- import java.util.*
1+ package data.csv_data. repositories
2+
3+ import com.google.common.truth.Truth.assertThat
4+ import data.csv_data.datasource.AuditLogDataSource
5+ import data.csv_data.mappers.toDto
6+ import domain.models.AuditLog
7+ import domain.models.AuditLog.AuditType
8+ import io.mockk.every
9+ import io.mockk.mockk
10+ import io.mockk.verify
11+ import kotlinx.coroutines.test.runTest
12+ import kotlinx.datetime.LocalDateTime
13+ import org.junit.jupiter.api.Assertions.assertTrue
14+ import org.junit.jupiter.api.BeforeEach
15+ import org.junit.jupiter.api.Test
16+ import java.util.*
1717
1818class AuditRepositoryImplTest {
19- private lateinit var auditLogDataSource: AuditLogDataSource
20- private lateinit var repository: AuditRepositoryImpl
21-
22- private val testTaskId = UUID .fromString(" 00000000-0000-0000-0000-000000000100" )
23- private val testProjectId = UUID .fromString(" 00000000-0000-0000-0000-000000000101" )
24- private val initialLogs = mutableListOf (
25- AuditLog (
26- id = UUID .fromString(" 00000000-0000-0000-0000-000000000001" ),
27- action = " Created" ,
28- auditType = AuditType .TASK ,
29- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
30- entityId = testTaskId,
31- ),
32- AuditLog (
33- id = UUID .fromString(" 00000000-0000-0000-0000-000000000002" ),
34- action = " Created" ,
35- auditType = AuditType .PROJECT ,
36- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
37- entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000011" ),
38- ),
39- AuditLog (
40- id = UUID .fromString(" 00000000-0000-0000-0000-000000000003" ),
41- action = " Updated" ,
42- auditType = AuditType .PROJECT ,
43- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
44- entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000012" ),
45- ),
46- AuditLog (
47- id = UUID .fromString(" 00000000-0000-0000-0000-000000000004" ),
48- action = " Updated" ,
49- auditType = AuditType .TASK ,
50- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
51- entityId = testTaskId,
52- ),
53- AuditLog (
54- id = UUID .fromString(" 00000000-0000-0000-0000-000000000005" ),
55- action = " Deleted" ,
56- auditType = AuditType .TASK ,
57- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
58- entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000013" ),
59- ),
60- AuditLog (
61- id = UUID .fromString(" 00000000-0000-0000-0000-000000000006" ),
62- action = " Created" ,
63- auditType = AuditType .PROJECT ,
64- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
65- entityId = testProjectId,
66- ),
67- AuditLog (
68- id = UUID .fromString(" 00000000-0000-0000-0000-000000000007" ),
69- action = " Updated" ,
70- auditType = AuditType .PROJECT ,
71- timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
72- entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000012" ),
73- )
19+ private lateinit var auditLogDataSource: AuditLogDataSource
20+ private lateinit var repository: AuditRepositoryImpl
21+
22+ private val testTaskId = UUID .fromString(" 00000000-0000-0000-0000-000000000100" )
23+ private val testProjectId = UUID .fromString(" 00000000-0000-0000-0000-000000000101" )
24+ private val initialLogs = mutableListOf (
25+ AuditLog (
26+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000001" ),
27+ action = " Created" ,
28+ auditType = AuditType .TASK ,
29+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
30+ entityId = testTaskId,
31+ ),
32+ AuditLog (
33+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000002" ),
34+ action = " Created" ,
35+ auditType = AuditType .PROJECT ,
36+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
37+ entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000011" ),
38+ ),
39+ AuditLog (
40+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000003" ),
41+ action = " Updated" ,
42+ auditType = AuditType .PROJECT ,
43+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
44+ entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000012" ),
45+ ),
46+ AuditLog (
47+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000004" ),
48+ action = " Updated" ,
49+ auditType = AuditType .TASK ,
50+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
51+ entityId = testTaskId,
52+ ),
53+ AuditLog (
54+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000005" ),
55+ action = " Deleted" ,
56+ auditType = AuditType .TASK ,
57+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
58+ entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000013" ),
59+ ),
60+ AuditLog (
61+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000006" ),
62+ action = " Created" ,
63+ auditType = AuditType .PROJECT ,
64+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
65+ entityId = testProjectId,
66+ ),
67+ AuditLog (
68+ id = UUID .fromString(" 00000000-0000-0000-0000-000000000007" ),
69+ action = " Updated" ,
70+ auditType = AuditType .PROJECT ,
71+ timestamp = LocalDateTime (2023 , 12 , 31 , 23 , 59 , 59 ),
72+ entityId = UUID .fromString(" 00000000-0000-0000-0000-000000000012" ),
7473 )
74+ )
7575
76- @BeforeEach
77- fun setUp () {
78- auditLogDataSource = mockk(relaxed = true )
79- every { auditLogDataSource.fetch() } returns initialLogs.map { it.toDto() }
80-
81- repository = AuditRepositoryImpl (auditLogDataSource)
82- }
83-
84- @Test
85- fun `should load logs from data source when creating an instance of the repository` () {
86- verify { auditLogDataSource.fetch() }
87- }
88-
89- @Test
90- fun `getAllLogsByTaskId should return empty list when no matching logs exist` () {
91- val nonExistentTaskId = UUID .fromString(" 00000000-0000-0000-0000-000000000111" )
92- val result = repository.getAllLogsByTaskId(nonExistentTaskId)
93-
94- assertTrue(result.isEmpty(), " Expected empty list for non-existent task ID" )
95- }
96-
97- @Test
98- fun `getAllLogsByTaskId should return only logs for specified task ID` () {
99- val result = repository.getAllLogsByTaskId(testTaskId)
100- val resultIds = result.map { it.id.toString() }
101-
102- assertThat(resultIds).containsExactly(
103- " 00000000-0000-0000-0000-000000000001" ,
104- " 00000000-0000-0000-0000-000000000004"
105- )
106- }
107-
108- @Test
109- fun `getAllLogsByTaskId should return only TASK type logs` () {
110- val result = repository.getAllLogsByTaskId(testTaskId)
111- val resultAuditTypes = result.map { it.auditType }.toSet()
112-
113- assertThat(resultAuditTypes).containsExactly(AuditType .TASK )
114- }
115-
116- @Test
117- fun `getAllLogsByProjectId should return empty list when no matching logs exist` () {
118- val nonExistentProjectId = UUID .randomUUID()
119- val result = repository.getAllLogsByProjectId(nonExistentProjectId)
120-
121- assertTrue(result.isEmpty())
122- }
123-
124- @Test
125- fun `getAllLogsByProjectId should return only logs for specified project ID` () {
126- val result = repository.getAllLogsByProjectId(testProjectId)
127- val resultIds = result.map { it.id.toString() }
128-
129- assertThat(resultIds).containsExactly(" 00000000-0000-0000-0000-000000000006" )
130- }
131-
132- @Test
133- fun `getAllLogsByProjectId should return only PROJECT type logs` () {
134- val result = repository.getAllLogsByProjectId(testProjectId)
135- val resultAuditTypes = result.map { it.auditType }.toSet()
136-
137- assertThat(resultAuditTypes).containsExactly(AuditType .PROJECT )
138- }
76+ @BeforeEach
77+ fun setUp () {
78+ auditLogDataSource = mockk(relaxed = true )
79+ every { auditLogDataSource.fetch() } returns initialLogs.map { it.toDto() }
80+
81+ repository = AuditRepositoryImpl (auditLogDataSource)
82+ }
83+
84+ @Test
85+ fun `should load logs from data source when creating an instance of the repository` () {
86+ verify { auditLogDataSource.fetch() }
87+ }
88+
89+ @Test
90+ fun `getAllLogsByTaskId should return empty list when no matching logs exist` () = runTest {
91+ val nonExistentTaskId = UUID .fromString(" 00000000-0000-0000-0000-000000000111" )
92+ val result = repository.getAllLogsByTaskId(nonExistentTaskId)
93+
94+ assertTrue(result.isEmpty(), " Expected empty list for non-existent task ID" )
95+ }
96+
97+ @Test
98+ fun `getAllLogsByTaskId should return only logs for specified task ID` (): Unit = runTest {
99+ val result = repository.getAllLogsByTaskId(testTaskId)
100+ val resultIds = result.map { it.id.toString() }
101+
102+ assertThat(resultIds).containsExactly(
103+ " 00000000-0000-0000-0000-000000000001" ,
104+ " 00000000-0000-0000-0000-000000000004"
105+ )
106+ }
107+
108+ @Test
109+ fun `getAllLogsByTaskId should return only TASK type logs` (): Unit = runTest {
110+ val result = repository.getAllLogsByTaskId(testTaskId)
111+ val resultAuditTypes = result.map { it.auditType }.toSet()
112+
113+ assertThat(resultAuditTypes).containsExactly(AuditType .TASK )
114+ }
115+
116+ @Test
117+ fun `getAllLogsByProjectId should return empty list when no matching logs exist` () = runTest {
118+ val nonExistentProjectId = UUID .randomUUID()
119+ val result = repository.getAllLogsByProjectId(nonExistentProjectId)
120+
121+ assertTrue(result.isEmpty())
122+ }
123+
124+ @Test
125+ fun `getAllLogsByProjectId should return only logs for specified project ID` (): Unit = runTest {
126+ val result = repository.getAllLogsByProjectId(testProjectId)
127+ val resultIds = result.map { it.id.toString() }
128+
129+ assertThat(resultIds).containsExactly(" 00000000-0000-0000-0000-000000000006" )
130+ }
131+
132+ @Test
133+ fun `getAllLogsByProjectId should return only PROJECT type logs` (): Unit = runTest {
134+ val result = repository.getAllLogsByProjectId(testProjectId)
135+ val resultAuditTypes = result.map { it.auditType }.toSet()
136+
137+ assertThat(resultAuditTypes).containsExactly(AuditType .PROJECT )
139138 }
139+ }
0 commit comments