Skip to content

Commit

Permalink
Merge pull request #129 from craigatk/test-delete
Browse files Browse the repository at this point in the history
(chore) Adding test case for trying to add an attachment when it is disabled
  • Loading branch information
craigatk authored Sep 1, 2020
2 parents d594e7e + 26d62fc commit 6507e49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ open class ApplicationTestCase {

protected var publishToken: String? = null

protected var attachmentsEnabled: Boolean? = null
protected var attachmentsEnabled: Boolean = false
protected var attachmentsMaxSizeMB: BigDecimal? = null
protected var attachmentsAccessKey = "minio_access_key"
protected var attachmentsBucketName = "attachmentstesting"
Expand All @@ -89,7 +89,7 @@ open class ApplicationTestCase {

publishToken?.let { put("ktor.auth.publishToken", it) }

attachmentsEnabled?.let {
if (attachmentsEnabled) {
put("ktor.attachment.url", "http://localhost:9000")
put("ktor.attachment.bucketName", attachmentsBucketName)
put("ktor.attachment.autoCreateBucket", attachmentsAutoCreateBucket.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ class AddAttachmentApplicationTest : ApplicationTestCase() {
}
}
}

@Test
fun `when attachments not enabled should return 400 when trying to add attachment`() {
val publicId = randomPublicId()
attachmentsEnabled = false

val attachmentBytes = File("src/test/resources/test-attachment.txt").readBytes()

withTestApplication(::createTestApplication) {
handleRequest(HttpMethod.Post, "/run/$publicId/attachments/test-attachment.txt") {
testRunDBGenerator.createSimpleTestRun(publicId)

addHeader("content-length", attachmentBytes.size.toString())
setBody(attachmentBytes)
}.apply {
expectThat(response.status()).isEqualTo(HttpStatusCode.BadRequest)
}
}
}
}

0 comments on commit 6507e49

Please sign in to comment.