Skip to content

Commit e459bec

Browse files
Added more unit tests for GET requests
1 parent c284968 commit e459bec

File tree

6 files changed

+138
-48
lines changed

6 files changed

+138
-48
lines changed

src/main/kotlin/io/github/chapeco/DataTypes/Milestone.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ import kotlinx.serialization.json.JSON
99
data class Milestone
1010
(
1111
//GET
12-
@Transient var completedOn: Timestamp? = null,
13-
val id: Int? = null,
14-
val milestones: Array<Milestone>? = null,
15-
@SerialName("project_id") val projectId: Int? = null,
16-
@Transient var startedOn: Timestamp? = null,
17-
val url: String? = null,
12+
@Optional @Transient var completedOn: Timestamp? = null,
13+
@Optional val id: Int? = null,
14+
@Optional val milestones: List<Milestone>? = null,
15+
@Optional @SerialName("project_id") val projectId: Int? = null,
16+
@Optional @Transient var startedOn: Timestamp? = null,
17+
@Optional val url: String? = null,
1818

1919
//ADD/UPDATE
20-
var name: String? = null,
21-
var description: String? = null,
22-
@Transient var dueOn: Timestamp? = null,
23-
@SerialName("parent_id") var parentId: Int? = null,
24-
@Transient var startOn: Timestamp? = null,
20+
@Optional var name: String? = null,
21+
@Optional var description: String? = null,
22+
@Optional @Transient var dueOn: Timestamp? = null,
23+
@Optional @SerialName("parent_id") var parentId: Int? = null,
24+
@Optional @Transient var startOn: Timestamp? = null,
2525

2626
//UPDATE
27-
@SerialName("is_completed") var isCompleted: Boolean? = null,
28-
@SerialName("is_started") var isStarted: Boolean? = null
27+
@Optional @SerialName("is_completed") var isCompleted: Boolean? = null,
28+
@Optional @SerialName("is_started") var isStarted: Boolean? = null
2929
)
3030
{
3131
@Optional @SerialName("completed_on") private val completedOnActual: Long? = completedOn.toString().toLongOrNull()

src/main/kotlin/io/github/chapeco/DataTypes/Plan.kt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ import kotlinx.serialization.json.JSON
99
data class Plan
1010
(
1111
//GET
12-
@SerialName("assignedto_id") val assignedToId: Int? = null,
13-
@SerialName("blocked_count") val blockedCount: Int? = null,
14-
@Transient var completedOn: Timestamp? = null,
15-
@SerialName("created_by") val createdBy: Int? = null,
16-
@Transient var createdOn: Timestamp? = null,
12+
@Optional @SerialName("assignedto_id") val assignedToId: Int? = null,
13+
@Optional @SerialName("blocked_count") val blockedCount: Int? = null,
14+
@Optional @Transient var completedOn: Timestamp? = null,
15+
@Optional @SerialName("created_by") val createdBy: Int? = null,
16+
@Optional @Transient var createdOn: Timestamp? = null,
1717
//TODO Add status count 1-7
18-
@SerialName("custom_status?_count") val customStatusCount: Int? = null,
19-
@SerialName("failed_count") val failedCount: Int? = null,
20-
val id: Int? = null,
21-
@SerialName("is_completed") val isCompleted: Boolean? = null,
22-
@SerialName("passed_count") val passedCount: Int? = null,
23-
@SerialName("project_id") val projectId: Int? = null,
24-
@SerialName("retest_count") val retestCount: Int? = null,
25-
@SerialName("untested_count") val untestedCount: Int? = null,
26-
val url: String? = null,
18+
@Optional @SerialName("custom_status1_count") val customStatus1Count: Int? = null,
19+
@Optional @SerialName("custom_status2_count") val customStatus2Count: Int? = null,
20+
@Optional @SerialName("custom_status3_count") val customStatus3Count: Int? = null,
21+
@Optional @SerialName("custom_status4_count") val customStatus4Count: Int? = null,
22+
@Optional @SerialName("custom_status5_count") val customStatus5Count: Int? = null,
23+
@Optional @SerialName("custom_status6_count") val customStatus6Count: Int? = null,
24+
@Optional @SerialName("custom_status7_count") val customStatus7Count: Int? = null,
25+
@Optional @SerialName("failed_count") val failedCount: Int? = null,
26+
@Optional val id: Int? = null,
27+
@Optional @SerialName("is_completed") val isCompleted: Boolean? = null,
28+
@Optional @SerialName("passed_count") val passedCount: Int? = null,
29+
@Optional @SerialName("project_id") val projectId: Int? = null,
30+
@Optional @SerialName("retest_count") val retestCount: Int? = null,
31+
@Optional @SerialName("untested_count") val untestedCount: Int? = null,
32+
@Optional val url: String? = null,
2733

2834
//ADD/UPDATE
29-
var name: String? = null,
30-
var description: String? = null,
31-
@SerialName("milestone_id") var milestoneId: Int? = null,
32-
var entries: Array<PlanEntry>? = null
35+
@Optional var name: String? = null,
36+
@Optional var description: String? = null,
37+
@Optional @SerialName("milestone_id") var milestoneId: Int? = null,
38+
@Optional var entries: List<PlanEntry>? = null
3339
)
3440
{
3541
@Optional @SerialName("completed_on") val completedOnActual: Long? = completedOn.toString().toLongOrNull()

src/test/kotlin/io/github/chapeco/DataTypes/ConfigurationTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.chapeco.DataTypes
22

33
import kotlinx.serialization.json.JSON
4+
import kotlinx.serialization.list
45
import org.junit.jupiter.api.Assertions
56
import org.junit.jupiter.api.Test
67

@@ -45,7 +46,10 @@ class ConfigurationTest
4546
@Test
4647
fun getConfigsTest()
4748
{
48-
49+
val expectedConfigurationsList = listOf<Configuration>()
50+
val actualConfigurationsList = Configuration().getConfigs(1)
51+
println(JSON.unquoted.stringify(Configuration.serializer().list,actualConfigurationsList))
52+
Assertions.assertEquals(expectedConfigurationsList,actualConfigurationsList)
4953
}
5054

5155
@Test

src/test/kotlin/io/github/chapeco/DataTypes/MilestoneTest.kt

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github.chapeco.DataTypes
22

33
import io.github.chapeco.Utilities.Timestamp
44
import kotlinx.serialization.json.JSON
5+
import kotlinx.serialization.list
56
import org.junit.jupiter.api.Assertions
67
import org.junit.jupiter.api.Test
78

@@ -15,7 +16,7 @@ class MilestoneTest
1516
time = 1000
1617
),
1718
id = 1,
18-
milestones = Array<Milestone>(1) { Milestone() },
19+
milestones = List<Milestone>(1) { Milestone() },
1920
projectId = 1,
2021
startedOn = Timestamp(
2122
time = 500
@@ -38,7 +39,7 @@ class MilestoneTest
3839
time = 1000
3940
),
4041
id = 1,
41-
milestones = Array<Milestone>(1) { Milestone() },
42+
milestones = List<Milestone>(1) { Milestone() },
4243
projectId = 1,
4344
startedOn = Timestamp(
4445
time = 500
@@ -68,7 +69,7 @@ class MilestoneTest
6869
time = 1000
6970
),
7071
id = 1,
71-
milestones = Array<Milestone>(1) { Milestone() },
72+
milestones = List<Milestone>(1) { Milestone() },
7273
projectId = 1,
7374
startedOn = Timestamp(
7475
time = 500
@@ -98,7 +99,7 @@ class MilestoneTest
9899
time = 1000
99100
),
100101
id = 1,
101-
milestones = Array<Milestone>(1) { Milestone() },
102+
milestones = List<Milestone>(1) { Milestone() },
102103
projectId = 1,
103104
startedOn = Timestamp(
104105
time = 500
@@ -122,13 +123,42 @@ class MilestoneTest
122123
@Test
123124
fun getMilestoneTest()
124125
{
125-
126+
val expectedMilestone = Milestone(
127+
id = 1,
128+
milestones = listOf<Milestone>(),
129+
projectId = 1,
130+
url = "https://techdemo4.testrail.io/index.php?/milestones/view/1",
131+
name = "API TEST Milestone",
132+
description = "This is my description",
133+
isCompleted = false,
134+
isStarted = false,
135+
dueOn = Timestamp(1546387200),
136+
startOn = Timestamp(1542758400)
137+
)
138+
val actualMilestone = Milestone().getMilestone(1)
139+
println(JSON.unquoted.stringify(actualMilestone))
140+
Assertions.assertEquals(expectedMilestone,actualMilestone)
126141
}
127142

128143
@Test
129144
fun getMilestonesTest()
130145
{
131-
146+
val expectedMilestonesList = listOf(
147+
Milestone(
148+
id = 1,
149+
projectId = 1,
150+
url = "https://techdemo4.testrail.io/index.php?/milestones/view/1",
151+
name = "API TEST Milestone",
152+
description = "This is my description",
153+
isCompleted = false,
154+
isStarted = false,
155+
dueOn = Timestamp(1546387200),
156+
startOn = Timestamp(1542758400)
157+
)
158+
)
159+
val actualMilestonesList = Milestone().getMilestones(1)
160+
println(JSON.unquoted.stringify(Milestone.serializer().list,actualMilestonesList))
161+
Assertions.assertEquals(expectedMilestonesList,actualMilestonesList)
132162
}
133163

134164
@Test

src/test/kotlin/io/github/chapeco/DataTypes/PlanTest.kt

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github.chapeco.DataTypes
22

33
import io.github.chapeco.Utilities.Timestamp
44
import kotlinx.serialization.json.JSON
5+
import kotlinx.serialization.list
56
import org.junit.jupiter.api.Assertions
67
import org.junit.jupiter.api.Test
78

@@ -30,7 +31,7 @@ class PlanTest
3031
name = "some name",
3132
description = "some description",
3233
milestoneId = 1,
33-
entries = Array<PlanEntry>(1) { PlanEntry() }
34+
entries = List<PlanEntry>(1) { PlanEntry() }
3435

3536
)
3637
val actualPlan = Plan(
@@ -53,7 +54,7 @@ class PlanTest
5354
name = "some name",
5455
description = "some description",
5556
milestoneId = 1,
56-
entries = Array<PlanEntry>(1) {PlanEntry()}
57+
entries = List<PlanEntry>(1) {PlanEntry()}
5758
)
5859
Assertions.assertEquals(expectedPlan.toString(),actualPlan.toString())
5960
}
@@ -82,7 +83,7 @@ class PlanTest
8283
name = "some name",
8384
description = "some description",
8485
milestoneId = 1,
85-
entries = Array<PlanEntry>(1) {PlanEntry()}
86+
entries = List<PlanEntry>(1) {PlanEntry()}
8687
)
8788
println(JSON.unquoted.stringify(actualPlan))
8889
Assertions.assertEquals(expectedPlan,JSON.unquoted.stringify(actualPlan))
@@ -111,21 +112,74 @@ class PlanTest
111112
name = "some name",
112113
description = "some description",
113114
milestoneId = 1,
114-
entries = Array<PlanEntry>(1) {PlanEntry()}
115+
entries = List<PlanEntry>(1) {PlanEntry()}
115116
)
116117
Assertions.assertEquals(expectedPlan.toString(),JSON.unquoted.parse<Plan>("{assignedto_id:1,blocked_count:1,created_by:1,custom_status?_count:null,failed_count:1,id:null,is_completed:false,passed_count:1,project_id:1,retest_count:1,untested_count:1,url:\"some url\",name:\"some name\",description:\"some description\",milestone_id:1,entries:[{suite_id:null,config_ids:null,runs:null,name:null,description:null,assignedto_id:null,include_all:null,case_ids:null}],completed_on:1000,created_on:1000}").toString())
117118
}
118119

119120
@Test
120121
fun getPlanTest()
121122
{
122-
123+
val expectedPlan = Plan(
124+
blockedCount = 0,
125+
createdBy = 1,
126+
customStatus1Count = 0,
127+
customStatus2Count = 0,
128+
customStatus3Count = 0,
129+
customStatus4Count = 0,
130+
customStatus5Count = 0,
131+
customStatus6Count = 0,
132+
customStatus7Count = 0,
133+
failedCount = 0,
134+
id = 2,
135+
isCompleted = false,
136+
passedCount = 0,
137+
projectId = 1,
138+
retestCount = 0,
139+
untestedCount = 0,
140+
url = "https://techdemo4.testrail.io/index.php?/plans/view/2",
141+
name = "API TEST Plan",
142+
description = "My plan description.",
143+
milestoneId = 1,
144+
entries = listOf<PlanEntry>(),
145+
createdOn = Timestamp(1542820883)
146+
)
147+
val actualPlan = Plan().getPlan(2)
148+
println(JSON.unquoted.stringify(actualPlan))
149+
Assertions.assertEquals(expectedPlan,actualPlan)
123150
}
124151

125152
@Test
126153
fun getPlansTest()
127154
{
128-
155+
val expectedPlansList = listOf(
156+
Plan(
157+
blockedCount = 0,
158+
createdBy = 1,
159+
customStatus1Count = 0,
160+
customStatus2Count = 0,
161+
customStatus3Count = 0,
162+
customStatus4Count = 0,
163+
customStatus5Count = 0,
164+
customStatus6Count = 0,
165+
customStatus7Count = 0,
166+
failedCount = 0,
167+
id = 2,
168+
isCompleted = false,
169+
passedCount = 0,
170+
projectId = 1,
171+
retestCount = 0,
172+
untestedCount = 0,
173+
url = "https://techdemo4.testrail.io/index.php?/plans/view/2",
174+
name = "API TEST Plan",
175+
description = "My plan description.",
176+
milestoneId = 1,
177+
createdOn = Timestamp(1542820883)
178+
)
179+
)
180+
val actualPlansList = Plan().getPlans(1)
181+
println(JSON.unquoted.stringify(Plan.serializer().list,actualPlansList))
182+
Assertions.assertEquals(expectedPlansList,actualPlansList)
129183
}
130184

131185
@Test

src/test/kotlin/io/github/chapeco/DataTypes/PriorityTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class PriorityTest
5858
@Test
5959
fun getPrioritiesTest()
6060
{
61-
// {id:1,is_default:false,name:Low,priority:1,short_name:Low},
62-
// {id:2,is_default:true,name:Medium,priority:2,short_name:Medium},
63-
// {id:3,is_default:false,name:High,priority:3,short_name:High},
64-
// {id:4,is_default:false,name:Critical,priority:4,short_name:Critical}
6561
val expectedPrioritiesList = listOf(
6662
Priority(1,false,"Low",1,"Low"),
6763
Priority(2,true,"Medium",2,"Medium"),

0 commit comments

Comments
 (0)