Skip to content

Commit

Permalink
Merge pull request #45 from capcom6/issue/44-invalid-state-transition
Browse files Browse the repository at this point in the history
Fix message state with multiple recipients
  • Loading branch information
capcom6 authored Feb 25, 2024
2 parents 53f5653 + e552607 commit c2a6afc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
sed -i "s/versionName.*/versionName \"${VERSION_NAME#v}\"/" app/build.gradle
sed -i "s/versionCode.*/versionCode $(( ($(date +%s) - $(date -d "2022-06-15" +%s)) / 86400 ))/" app/build.gradle
- name: Test
run: ./gradlew test

#1
- name: Decode Keystore
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ data class MessageWithRecipients(
) {
val state: Message.State
get() = when {
recipients.any { it.state == Message.State.Pending } -> Message.State.Pending
recipients.any { it.state == Message.State.Processed } -> Message.State.Processed

recipients.all { it.state == Message.State.Failed } -> Message.State.Failed
recipients.all { it.state == Message.State.Delivered } -> Message.State.Delivered
recipients.all { it.state == Message.State.Sent } -> Message.State.Sent
recipients.any { it.state == Message.State.Pending } -> Message.State.Pending
else -> Message.State.Processed
else -> Message.State.Sent
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package me.capcom.smsgateway.data.entities

import me.capcom.smsgateway.modules.messages.data.MessageSource
import org.junit.Assert.assertEquals
import org.junit.Test

class MessageWithRecipientsTest {
@Test
fun testStatePending() {
val message = Message(
id = "1",
text = "Test message",
withDeliveryReport = true,
simNumber = 1,
validUntil = null,
isEncrypted = false,
source = MessageSource.Local,
state = Message.State.Pending,
createdAt = System.currentTimeMillis()
)
val recipients = listOf(
MessageRecipient("1", "1234567890", Message.State.Pending, null),
MessageRecipient("1", "9876543210", Message.State.Processed, null)
)
val messageWithRecipients = MessageWithRecipients(message, recipients)

assertEquals(Message.State.Pending, messageWithRecipients.state)
}

@Test
fun testStateSent() {
val message = Message(
id = "1",
text = "Test message",
withDeliveryReport = true,
simNumber = 1,
validUntil = null,
isEncrypted = false,
source = MessageSource.Local,
state = Message.State.Pending,
createdAt = System.currentTimeMillis()
)
val recipients = listOf(
MessageRecipient("1", "1234567890", Message.State.Delivered, null),
MessageRecipient("1", "9876543210", Message.State.Sent, null)
)
val messageWithRecipients = MessageWithRecipients(message, recipients)

assertEquals(Message.State.Sent, messageWithRecipients.state)
}

@Test
fun testStateDelivered() {
val message = Message(
id = "2",
text = "Test message",
withDeliveryReport = true,
simNumber = 1,
validUntil = null,
isEncrypted = false,
source = MessageSource.Local,
state = Message.State.Pending,
createdAt = System.currentTimeMillis()
)
val recipients = listOf(
MessageRecipient("2", "1234567890", Message.State.Delivered, null),
MessageRecipient("2", "9876543210", Message.State.Delivered, null)
)
val messageWithRecipients = MessageWithRecipients(message, recipients)

assertEquals(Message.State.Delivered, messageWithRecipients.state)
}

// Add more test cases for other states
}

0 comments on commit c2a6afc

Please sign in to comment.