Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ on:
pull_request:
branches: [ master ]
workflow_call:
inputs:
require-current-artifact:
description: Require the server artifact from the current workflow run
required: false
type: boolean
default: false

env:
TEST: true
Expand All @@ -14,7 +20,7 @@ jobs:
test:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
os: [ ubuntu-latest, macos-26-intel, windows-latest ]

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -23,6 +29,8 @@ jobs:
repository: 'ZNotify/kt-sdk'

- uses: ZNotify/test-server-action@master
with:
require-current-artifact: ${{ inputs.require-current-artifact || false }}

- uses: actions/setup-java@v3
with:
Expand All @@ -45,3 +53,4 @@ jobs:
with:
concurrent: true
arguments: check --scan

25 changes: 12 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("UnstableApiUsage")

import com.codingfeline.buildkonfig.compiler.FieldSpec
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

group = "dev.zxilly"

Expand All @@ -13,16 +14,16 @@ repositories {
}

plugins {
val ktVersion = "2.1.21"
val ktVersion = "2.2.10"

kotlin("multiplatform") version ktVersion
kotlin("plugin.serialization") version ktVersion

id("com.android.library") version "8.3.2"
id("com.android.library") version "8.13.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("com.dorongold.task-tree") version "4.0.1"
id("com.codingfeline.buildkonfig") version "0.17.1"
id("dev.zxilly.gradle.keeper") version "0.0.5"
id("dev.zxilly.gradle.keeper") version "0.1.0"

id("maven-publish")
id("signing")
Expand All @@ -49,8 +50,8 @@ kotlin {
useJUnitPlatform()
}

compilations.all {
kotlinOptions.jvmTarget = "1.8"
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

Expand All @@ -61,19 +62,17 @@ kotlin {

androidTarget {
publishLibraryVariants("release", "debug")
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
linuxX64()
macosX64()
mingwX64()

sourceSets {
val ktorVersion = "3.2.3"
val serializationVersion = "1.8.1"
val ktorVersion = "3.3.0"
val serializationVersion = "1.9.0"
val coroutinesVersion = "1.10.2"

val commonMain by getting {
Expand Down Expand Up @@ -271,8 +270,8 @@ publishing {
}

signing {
val signingKey = secret.getBase64("signing.key")
val signingKey = secret.get("signing.key", dev.zxilly.gradle.keeper.decoders.Base64Decoder())
val signingPassword = secret.get("signing.password")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
}
55 changes: 55 additions & 0 deletions src/commonTest/kotlin/dev/zxilly/notify/sdk/SerializationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.zxilly.notify.sdk

import dev.zxilly.notify.sdk.entity.ErrorResponse
import dev.zxilly.notify.sdk.entity.Message
import dev.zxilly.notify.sdk.entity.Priority
import dev.zxilly.notify.sdk.entity.Response
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

internal class SerializationTest {
private val json = Json { ignoreUnknownKeys = true }

@Test
fun messageResponseRoundTripsWithWireNames() {
val response = Response(
200,
Message("message-1", "Hello 世界", "Title", "Long body", Priority.High, "2026-10-07T00:00:00Z")
)

val encoded = json.encodeToString(response)
assertTrue(encoded.contains("\"created_at\""))
assertTrue(encoded.contains("\"priority\":\"high\""))
assertEquals(response, json.decodeFromString<Response<Message>>(encoded))
}

@Test
fun responseAllowsUnknownFields() {
val encoded = """{"code":200,"body":{"id":"message-1","content":"Hello","title":"Title","long":"","priority":"normal","created_at":"2026-10-07T00:00:00Z","extra":true},"extra":"ignored"}"""
val response = json.decodeFromString<Response<Message>>(encoded)

assertEquals(200, response.code)
assertEquals(Priority.Normal, response.body.priority)
assertEquals("2026-10-07T00:00:00Z", response.body.createdAt)
}

@Test
fun booleanListAndErrorResponsesDecode() {
assertEquals(Response(200, true), json.decodeFromString<Response<Boolean>>("""{"code":200,"body":true}"""))
assertEquals(emptyList(), json.decodeFromString<Response<List<Message>>>("""{"code":200,"body":[]}""").body)
assertEquals(ErrorResponse(400, "Invalid input"), json.decodeFromString<ErrorResponse>("""{"code":400,"body":"Invalid input"}"""))
}

@Test
fun unsupportedPriorityIsRejected() {
assertFailsWith<SerializationException> {
json.decodeFromString<Priority>("\"urgent\"")
}
}
}
Loading