Skip to content

Commit

Permalink
Implemented missing tests. (#105)
Browse files Browse the repository at this point in the history
* Changed default gitHub runner name.
  • Loading branch information
marcin-cebo authored Oct 22, 2024
1 parent cd0571f commit 44b6a03
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commands-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Process command
if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
steps:
- name: Check referred user
id: user-check
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Check release required
if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
outputs:
release: ${{ steps.check.outputs.ready }}
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
needs: check-release
if: needs.check-release.outputs.release == 'true'
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
tests:
name: Integration and Unit tests
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
name: Tests
needs: [tests]
runs-on:
group: Default
group: organization/Default
steps:
- name: Tests summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
6 changes: 3 additions & 3 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pubnub-yml:
name: "Validate .pubnub.yml"
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -37,7 +37,7 @@ jobs:
build-validation:
name: Validate build
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -61,7 +61,7 @@ jobs:
name: Validations
needs: [pubnub-yml, build-validation]
runs-on:
group: Default
group: organization/Default
steps:
- name: Validations summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed"
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ benmanes-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech" }
gradle-nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }
kotlinx-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.16.2" }
mokkery = { id = "dev.mokkery", version = "2.3.0" }
mokkery = { id = "dev.mokkery", version = "2.4.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ interface Message {
* @param channelId Unique identifier of the channel to which you want to forward the message. You can forward a message to the same channel on which it was published or to any other.
* @return [PNFuture] containing [PNPublishResult] that holds the timetoken of the forwarded message.
*/
fun forward(channelId: String): PNFuture<PNPublishResult> // todo add test
fun forward(channelId: String): PNFuture<PNPublishResult>

/**
* Attach this message to its channel.
*
* @return `PNFuture` containing the updated channel metadata
*/
fun pin(): PNFuture<Channel> // todo add test

// todo do we have test for this?
fun pin(): PNFuture<Channel>

/**
* Flag and report an inappropriate message to the admin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing [ThreadChannel]
*/
override fun unpinMessage(): PNFuture<ThreadChannel> // todo add test
override fun unpinMessage(): PNFuture<ThreadChannel>

/**
* Returns historical messages for the [ThreadChannel]
Expand All @@ -56,7 +56,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing the updated [Channel] with the pinned message metadata.
*/
fun pinMessageToParentChannel(message: ThreadMessage): PNFuture<Channel> // todo add test
fun pinMessageToParentChannel(message: ThreadMessage): PNFuture<Channel>

/**
* Unpins the currently pinned message from the parent channel. This updates the parent channel's metadata by removing
Expand All @@ -66,7 +66,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing the updated [Channel] after the message is unpinned.
*/
fun unpinMessageFromParentChannel(): PNFuture<Channel> // todo add test
fun unpinMessageFromParentChannel(): PNFuture<Channel>

companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ class ChatImpl(
}
}

// todo do we have test for this?
override fun forwardMessage(message: Message, channelId: String): PNFuture<PNPublishResult> {
if (!isValidId(channelId)) {
return log.logErrorAndReturnException(CHANNEL_ID_IS_REQUIRED).asFuture()
Expand Down Expand Up @@ -688,7 +687,6 @@ class ChatImpl(
return subscription
}

// todo do we have test for this method?
override fun setRestrictions(
restriction: Restriction
): PNFuture<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract class BaseChannel<C : Channel, M : Message>(
val messageFactory: (ChatInternal, PNFetchMessageItem, channelId: String) -> M,
) : Channel {
private val suggestedMemberships = mutableMapOf<String, Set<Membership>>()
private var typingSent: Instant? = null
internal var typingSent: Instant? = null
private val sendTextRateLimiter by lazy {
ExponentialRateLimiter(
type?.let { typeNotNull -> chat.config.rateLimitPerChannel[typeNotNull] } ?: Duration.ZERO,
Expand Down Expand Up @@ -750,10 +750,6 @@ abstract class BaseChannel<C : Channel, M : Message>(
).then { }
}

internal fun setTypingSent(value: Instant) {
typingSent = value
}

internal abstract fun copyWithStatusDeleted(): C

private fun toPNChannelMetadata(): PNChannelMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() {
lateinit var someUser02: User
lateinit var userPamServer: User
lateinit var userPamClient: User
var cleanup: MutableList<suspend () -> Unit> = mutableListOf() // todo is this used?

@BeforeTest
override fun before() {
Expand Down Expand Up @@ -125,7 +124,6 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() {
pubnub.removeChannelMetadata(channel02.id).await()
pubnub.removeChannelMetadata(threadChannel.id).await()
pubnub.removeChannelMetadata(channelPam.id).await()
cleanup.forEach { it.invoke() }
}

internal suspend fun delayInMillis(timeMillis: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.pubnub.chat.listenForEvents
import com.pubnub.chat.membership.MembershipsResponse
import com.pubnub.chat.message.GetUnreadMessagesCounts
import com.pubnub.chat.message.MarkAllMessageAsReadResponse
import com.pubnub.chat.restrictions.Restriction
import com.pubnub.chat.restrictions.RestrictionType
import com.pubnub.chat.types.ChannelMentionData
import com.pubnub.chat.types.EmitEventMethod
import com.pubnub.chat.types.EventContent
Expand All @@ -47,6 +49,7 @@ import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.seconds

class ChatIntegrationTest : BaseChatIntegrationTest() {
@Test
Expand Down Expand Up @@ -574,6 +577,39 @@ class ChatIntegrationTest : BaseChatIntegrationTest() {
chat.destroy()
}

@Test
fun setRestrictionThenUnset() = runTest(timeout = 10.seconds) {
val userId = someUser.id
val channelId = channel01.id
val banned = CompletableDeferred<Unit>()
val unbanned = CompletableDeferred<Unit>()
val restrictionBan = Restriction(userId = userId, channelId = channelId, ban = true, reason = "rude")
val restrictionUnban = Restriction(userId = userId, channelId = channelId, ban = false, mute = false, reason = "ok")
pubnub.test(backgroundScope, checkAllEvents = false) {
var removeListenerAndUnsubscribe: AutoCloseable? = null
pubnub.awaitSubscribe(channels = listOf(userId)) {
removeListenerAndUnsubscribe = chat.listenForEvents(
type = EventContent.Moderation::class,
channelId = userId
) { event: Event<EventContent.Moderation> ->
val restrictionType: RestrictionType = event.payload.restriction
if (restrictionType == RestrictionType.BAN) {
banned.complete(Unit)
} else {
unbanned.complete(Unit)
}
}
}

chat.setRestrictions(restrictionBan).await()
banned.await()
chat.setRestrictions(restrictionUnban).await()
unbanned.await()

removeListenerAndUnsubscribe?.close()
}
}

private suspend fun assertPushChannels(expectedNumberOfChannels: Int) {
val pushChannels = chat.getPushChannels().await()
assertEquals(expectedNumberOfChannels, pushChannels.size)
Expand Down
Loading

0 comments on commit 44b6a03

Please sign in to comment.