Skip to content

Commit db6bfa1

Browse files
author
Oleksandr Dzhychko
committed
fix(model-client): use the correct HTTP method when loading versions
1 parent 445b7d7 commit db6bfa1

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class ModelClientV2(
168168
@Deprecated("repository ID is required for permission checks")
169169
@DeprecationInfo("3.7.0", "May be removed with the next major release. Also remove the endpoint from the model-server.")
170170
override suspend fun loadVersion(versionHash: String, baseVersion: IVersion?): IVersion {
171-
val response = httpClient.post {
171+
val response = httpClient.get {
172172
url {
173173
takeFrom(baseUrl)
174174
appendPathSegments("versions", versionHash)
@@ -186,7 +186,7 @@ class ModelClientV2(
186186
versionHash: String,
187187
baseVersion: IVersion?,
188188
): IVersion {
189-
val response = httpClient.post {
189+
val response = httpClient.get {
190190
url {
191191
takeFrom(baseUrl)
192192
appendPathSegments("repositories", repositoryId.id, "versions", versionHash)

model-server/src/test/kotlin/org/modelix/model/server/ModelClientV2Test.kt

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ class ModelClientV2Test {
6161
block()
6262
}
6363

64+
private suspend fun ApplicationTestBuilder.createModelClient(): ModelClientV2 {
65+
val url = "http://localhost/v2"
66+
val modelClient = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
67+
return modelClient
68+
}
69+
6470
@Test
6571
fun test_t1() = runTest {
66-
val url = "http://localhost/v2"
67-
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
72+
val client = createModelClient()
6873

6974
val repositoryId = RepositoryId("repo1")
7075
val initialVersion = client.initRepository(repositoryId)
@@ -101,9 +106,7 @@ class ModelClientV2Test {
101106

102107
@Test
103108
fun modelqlSmokeTest() = runTest {
104-
val url = "http://localhost/v2"
105-
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
106-
109+
val client = createModelClient()
107110
val repositoryId = RepositoryId("repo1")
108111
val branchRef = repositoryId.getBranchReference()
109112
val initialVersion = client.initRepository(repositoryId)
@@ -116,9 +119,7 @@ class ModelClientV2Test {
116119

117120
@Test
118121
fun testSlashesInPathSegmentsFromRepositoryIdAndBranchId() = runTest {
119-
val url = "http://localhost/v2"
120-
val client = ModelClientV2.builder().url(url).client(client).build()
121-
client.init()
122+
val client = createModelClient()
122123
val repositoryId = RepositoryId("repo/v1")
123124
val initialVersion = client.initRepository(repositoryId)
124125
val branchId = repositoryId.getBranchReference("my-branch/v1")
@@ -131,14 +132,7 @@ class ModelClientV2Test {
131132

132133
@Test
133134
fun `user id can be provided to client after creation`() = runTest {
134-
val url = "http://localhost/v2"
135-
val modelClient = ModelClientV2
136-
.builder()
137-
.url(url)
138-
.client(client)
139-
.build()
140-
.also { it.init() }
141-
135+
val modelClient = createModelClient()
142136
val userId = "a_user_id"
143137
modelClient.setClientProvideUserId(userId)
144138

@@ -148,23 +142,24 @@ class ModelClientV2Test {
148142
@Test
149143
fun `user id provided by client can be removed`() = runTest {
150144
val url = "http://localhost/v2"
145+
val userId = "a_user_id"
151146
val modelClient = ModelClientV2
152147
.builder()
153148
.url(url)
154149
.client(client)
155-
.userId("a_user_id")
150+
.userId(userId)
156151
.build()
157-
.also { it.init() }
152+
modelClient.init()
158153

154+
assertEquals(userId, modelClient.getUserId())
159155
modelClient.setClientProvideUserId(null)
160156

161157
assertEquals("localhost", modelClient.getUserId())
162158
}
163159

164160
@Test
165161
fun `newly created repository can be removed`() = runTest {
166-
val url = "http://localhost/v2"
167-
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
162+
val client = createModelClient()
168163
val repositoryId = RepositoryId(UUID.randomUUID().toString())
169164
client.initRepository(repositoryId)
170165

@@ -177,8 +172,7 @@ class ModelClientV2Test {
177172

178173
@Test
179174
fun `non-existing repository cannot be removed`() = runTest {
180-
val url = "http://localhost/v2"
181-
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
175+
val client = createModelClient()
182176
val repositoryId = RepositoryId(UUID.randomUUID().toString())
183177

184178
val success = client.deleteRepository(repositoryId)
@@ -191,9 +185,8 @@ class ModelClientV2Test {
191185
@Test
192186
fun `pulling existing versions pulls all referenced objects`() = runTest {
193187
// Arrange
194-
val url = "http://localhost/v2"
195-
val modelClientForArrange = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
196-
val modelClientForAssert = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
188+
val modelClientForArrange = createModelClient()
189+
val modelClientForAssert = createModelClient()
197190
val repositoryId = RepositoryId("repo1")
198191
val branchId = repositoryId.getBranchReference("my-branch")
199192
modelClientForArrange.runWrite(branchId) { root ->
@@ -221,8 +214,7 @@ class ModelClientV2Test {
221214
@Test
222215
fun `writing no data does not create empty versions`() = runTest {
223216
// Arrange
224-
val url = "http://localhost/v2"
225-
val modelClient = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
217+
val modelClient = createModelClient()
226218
val repositoryId = RepositoryId("repo1")
227219
val branchId = repositoryId.getBranchReference("master")
228220
modelClient.initRepository(repositoryId)
@@ -237,4 +229,26 @@ class ModelClientV2Test {
237229
val versionAfterRunWrite = modelClient.pullIfExists(branchId)!!
238230
assertEquals(versionAfterBeforeWrite.getContentHash(), versionAfterRunWrite.getContentHash())
239231
}
232+
233+
@Test
234+
fun `client can load version`() = runTest {
235+
val modelClient = createModelClient()
236+
val repositoryId = RepositoryId("aRepo")
237+
val initialVersion = modelClient.initRepository(repositoryId)
238+
239+
val loadedVersion = modelClient.loadVersion(repositoryId, initialVersion.getContentHash(), initialVersion)
240+
241+
assertEquals(initialVersion.getContentHash(), loadedVersion.getContentHash())
242+
}
243+
244+
@Test
245+
fun `client can load version (deprecated endpoint without repository)`() = runTest {
246+
val modelClient = createModelClient()
247+
val repositoryId = RepositoryId("aRepo")
248+
val initialVersion = modelClient.initRepository(repositoryId)
249+
250+
val loadedVersion = modelClient.loadVersion(initialVersion.getContentHash(), initialVersion)
251+
252+
assertEquals(initialVersion.getContentHash(), loadedVersion.getContentHash())
253+
}
240254
}

0 commit comments

Comments
 (0)