@@ -4,11 +4,16 @@ import io.kotest.matchers.shouldBe
4
4
import io.vertx.core.Vertx
5
5
import io.vertx.kotlin.core.json.jsonObjectOf
6
6
import io.vertx.kotlin.coroutines.await
7
+ import me.sujanpoudel.playdeals.Constants
7
8
import me.sujanpoudel.playdeals.IntegrationTest
9
+ import me.sujanpoudel.playdeals.domain.NewDeal
10
+ import me.sujanpoudel.playdeals.domain.entities.DealType
8
11
import me.sujanpoudel.playdeals.get
12
+ import me.sujanpoudel.playdeals.repositories.DealRepository
9
13
import org.jobrunr.jobs.states.StateName
10
14
import org.jobrunr.storage.StorageProvider
11
15
import org.junit.jupiter.api.Test
16
+ import java.time.OffsetDateTime
12
17
import java.util.UUID
13
18
14
19
class NewDealApiTest (vertx : Vertx ) : IntegrationTest(vertx) {
@@ -53,4 +58,37 @@ class NewDealApiTest(vertx: Vertx) : IntegrationTest(vertx) {
53
58
54
59
response.statusCode() shouldBe 200
55
60
}
61
+
62
+ @Test
63
+ fun `should should 200 if the app already exists` () = runTest {
64
+ di.get<StorageProvider >()
65
+ val repository = di.get<DealRepository >()
66
+
67
+ val packageName = " com.example.app"
68
+
69
+ val newDeal = NewDeal (
70
+ id = packageName,
71
+ name = " name" ,
72
+ icon = " icon" ,
73
+ images = listOf (" img0" , " img1" ),
74
+ normalPrice = 12f ,
75
+ currentPrice = 12f ,
76
+ currency = " USD" ,
77
+ storeUrl = " store_url" ,
78
+ category = " unknown" ,
79
+ downloads = " 12+" ,
80
+ rating = " 12" ,
81
+ offerExpiresIn = OffsetDateTime .now(),
82
+ type = DealType .ANDROID_APP ,
83
+ source = Constants .DealSources .APP_DEAL_SUBREDDIT
84
+ )
85
+
86
+ repository.upsert(newDeal)
87
+
88
+ val response = httpClient.post(" /api/deals" )
89
+ .sendJson(jsonObjectOf(" packageName" to packageName))
90
+ .await()
91
+
92
+ response.statusCode() shouldBe 200
93
+ }
56
94
}
0 commit comments