Skip to content

Commit f5d7b07

Browse files
Merge remote-tracking branch 'origin/refactor/test-cases' into feature/sub-tasks
2 parents ef528b7 + 1eaf708 commit f5d7b07

37 files changed

Lines changed: 1481 additions & 1077 deletions

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
3333
testImplementation("com.google.truth:truth:1.4.2")
3434
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
35+
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
3536
}
3637

3738
tasks.test {

src/main/kotlin/data/csv_data/csv_parser/UserCsvParser.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,19 @@ class UserCsvParser : CsvParser<UserDto> {
1818
name = it[NAME],
1919
hashedPassword = it[HASHED_PASSWORD],
2020
role = it[ROLE],
21-
projectIds = it[PROJECT_IDS].toProjectIds(),
22-
taskIds = it[Task_IDS].toTaskIds()
21+
projectIds = it[PROJECT_IDS].toStringList(),
22+
taskIds = it[Task_IDS].toStringList()
2323
)
2424
}
2525
}
2626

27-
private fun String.toProjectIds(): List<String> {
27+
private fun String.toStringList(): List<String> {
2828
if (this.isBlank() || this == "[]") {
2929
return emptyList()
3030
}
3131

32-
return this.removeSurrounding("[", "]")
33-
.split(",")
34-
.filter { it.trim().isNotBlank() }
35-
.map { it.trim() }
36-
}
37-
private fun String.toTaskIds(): List<String> {
38-
if (this.isBlank() || this == "[]") {
39-
return emptyList()
40-
}
41-
42-
return this.removeSurrounding("[", "]")
32+
return this.removePrefix("[")
33+
.removeSuffix("]")
4334
.split(",")
4435
.filter { it.trim().isNotBlank() }
4536
.map { it.trim() }

src/test/kotlin/data/csv_parser/UserCsvParserTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ class UserCsvParserTest {
9494
@Test
9595
fun `should return empty list when serialize and parse user with empty project ids string`() {
9696
// Given
97-
val user = createUser("test-id", "TestUser", "password123", MATE, emptyList())
98-
val serialized = listOf("id,name,hashedPassword,role,projectIds", "test-id,TestUser,password123,${MATE},[]")
97+
val user = createUser("test-id", "TestUser", "password123", MATE, emptyList(), emptyList())
98+
val serialized =
99+
listOf("id,name,hashedPassword,role,projectIds,taskIds", "test-id,TestUser,password123,${MATE},[],[]")
99100

100101
// When
101102
val parsedResult = parser.parse(serialized)
@@ -117,7 +118,7 @@ class UserCsvParserTest {
117118

118119
// Then
119120
Truth.assertThat(result).containsExactly(
120-
createUser("test-id", "TestUser", "password123", MATE, emptyList())
121+
createUser("test-id", "TestUser", "password123", MATE, emptyList(), emptyList())
121122
)
122123
}
123124

@@ -134,7 +135,7 @@ class UserCsvParserTest {
134135

135136
// Then
136137
Truth.assertThat(result).containsExactly(
137-
createUser("test-id", "TestUser", "password123", MATE, emptyList())
138+
createUser("test-id", "TestUser", "password123", MATE, emptyList(), emptyList())
138139
)
139140
}
140141
}

src/test/kotlin/data/mongodb_data/datasource/UserDataSourceImplTest.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,139 @@
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

1818
class 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

Comments
 (0)