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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object RulesEngine {
if (notificationExtension.isNullOrEmpty()) return true
val extensionsToBeChecked = notificationExtension.map { it.id }
val pluginVersions = actualPluginVersions.filterKeys { extensionsToBeChecked.contains(it) }
if (pluginVersions.isEmpty()) return false
return notificationExtension.all { extension ->
val actualVersion = pluginVersions[extension.id]
if (actualVersion == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class NotificationFormatUtilsTest {
val projectRule = ProjectRule()

private lateinit var mockSystemDetails: SystemDetails
private lateinit var mockSystemDetailsWithNoPlugin: SystemDetails
private lateinit var exampleNotification: InputStream

@BeforeEach
Expand All @@ -53,6 +54,18 @@ class NotificationFormatUtilsTest {
)
)

mockSystemDetailsWithNoPlugin = SystemDetails(
computeType = "Local",
computeArchitecture = "x86_64",
osType = "Linux",
osVersion = "5.4.0",
ideType = "IC",
ideVersion = "2023.1",
pluginVersions = mapOf(
"aws.toolkit" to "1.0",
)
)

exampleNotification = javaClass.getResource("/exampleNotification2.json")?.let {
Paths.get(it.toURI()).takeIf { f -> f.exists() }
}?.inputStream() ?: throw RuntimeException("Test not found")
Expand Down Expand Up @@ -98,6 +111,13 @@ class NotificationFormatUtilsTest {
}
}

@Test
fun `If plugin is not present, notification is not shown`() {
every { getCurrentSystemAndConnectionDetails() } returns mockSystemDetailsWithNoPlugin
val shouldShow = RulesEngine.displayNotification(projectRule.project, pluginNotPresentData)
assertThat(shouldShow).isFalse
}

@ParameterizedTest
@MethodSource("validNotifications")
fun `The notification is shown`(notification: String, expectedData: NotificationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,29 @@ val invalidIdeTypeAndVersionData = NotificationData(
)
)
)

val pluginNotPresentData = NotificationData(
id = "example_id_12344",
schedule = NotificationSchedule(type = "StartUp"),
severity = "Critical",
condition = NotificationDisplayCondition(
compute = null,
os = null,
ide = null,
extension = mutableListOf(
ExtensionType(
"amazon.q",
version = NotificationExpression.NotEqualsCondition("1.3334")
)
),
authx = null

),
actions = emptyList(),
content = NotificationContentDescriptionLocale(
NotificationContentDescription(
title = "Look at this!",
description = "Some bug is there"
)
)
)
Loading