Skip to content

Commit

Permalink
Fixes image upload testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Dec 24, 2024
1 parent 6807554 commit ff427d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ class ImageUploadTesting {
val result =
BlossomUploader()
.uploadImage(
inputStream,
initialHash,
paylod.size,
"filename.png",
"image/png",
inputStream = inputStream,
hash = initialHash,
length = paylod.size,
baseFileName = "filename.png",
contentType = "image/png",
alt = null,
sensitiveContent = null,
server,
serverBaseUrl = server.baseUrl,
forceProxy = { false },
createBlossomUploadAuth = account::createBlossomUploadAuth,
httpAuth = account::createBlossomUploadAuth,
context = InstrumentationRegistry.getInstrumentation().targetContext,
)

assertEquals("image/png", result.type)
assertEquals(paylod.size.toLong(), result.size)
assertEquals(initialHash, result.sha256)
assertEquals("${server.baseUrl}/$initialHash", result.url)
assertEquals("${server.baseUrl}/$initialHash", result.url?.removeSuffix(".png"))

val imageData: ByteArray =
ImageDownloader().waitAndGetImage(result.url!!, false)
Expand All @@ -128,15 +128,15 @@ class ImageUploadTesting {
val result =
Nip96Uploader()
.uploadImage(
inputStream,
paylod.size.toLong(),
"image/png",
inputStream = inputStream,
length = paylod.size.toLong(),
contentType = "image/png",
alt = null,
sensitiveContent = null,
serverInfo,
server = serverInfo,
forceProxy = { false },
onProgress = {},
createHTTPAuthorization = account::createHTTPAuthorization,
httpAuth = account::createHTTPAuthorization,
context = InstrumentationRegistry.getInstrumentation().targetContext,
)

Expand All @@ -154,19 +154,23 @@ class ImageUploadTesting {
return
}

FileHeader.prepare(
imageData,
"image/png",
null,
onReady = {
val prepared =
FileHeader.prepare(
imageData,
"image/png",
null,
)

prepared.fold(
onSuccess = {
if (dim != null) {
assertEquals("${server.name}: Invalid dimensions", it.dim, dim)
assertEquals("${server.name}: Invalid dimensions", it.dim.toString(), dim.toString())
}
if (size != null) {
assertEquals("${server.name}: Invalid size", it.size.toString(), size)
}
},
onError = { fail("${server.name}: It should not fail") },
onFailure = { fail("${server.name}: It should not fail") },
)

// delay(1000)
Expand Down Expand Up @@ -225,6 +229,7 @@ class ImageUploadTesting {
}

@Test()
@Ignore("Returns invalid image size")
fun testNostrPic() =
runBlocking {
testBase(ServerName("nostpic.com", "https://nostpic.com", ServerType.NIP96))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ enum class ServerType {
val DEFAULT_MEDIA_SERVERS: List<ServerName> =
listOf(
ServerName("Nostr.Build", "https://nostr.build", ServerType.NIP96),
ServerName("NostrCheck.me", "https://nostrcheck.me", ServerType.NIP96),
ServerName("NostPic", "https://nostpic.com", ServerType.NIP96),
ServerName("NostrCheck.me (NIP-96)", "https://nostrcheck.me", ServerType.NIP96),
ServerName("Sovbit", "https://files.sovbit.host", ServerType.NIP96),
ServerName("Void.cat", "https://void.cat", ServerType.NIP96),
ServerName("Satellite (Paid)", "https://cdn.satellite.earth", ServerType.Blossom),
ServerName("NostrCheck.me (Blossom)", "https://cdn.nostrcheck.me", ServerType.Blossom),
ServerName("Primal", "https://blossom.primal.net", ServerType.Blossom),
ServerName("Nostr.Download", "https://nostr.download", ServerType.Blossom),
)

0 comments on commit ff427d0

Please sign in to comment.