Skip to content

Commit

Permalink
#1322 Fixing backward compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 10, 2024
1 parent c68c340 commit acc692a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,30 @@ class EventSubscriptionMutations(
}
val entity: ProjectEntity = type.loadByNames(structureService, names)
?: throw EntityNotFoundByNameException(type, names)
// Extracting the fields

// Creates the payload
val name = getMutationInputField<String>(env, SubscribeToEventsInput::name.name)
val channel = getRequiredMutationInputField<String>(env, SubscribeToEventsInput::channel.name)
val channelConfig =
getRequiredMutationInputField<JsonNode>(env, SubscribeToEventsInput::channelConfig.name)
val events = getRequiredMutationInputField<List<String>>(env, SubscribeToEventsInput::events.name)
val keywords = getMutationInputField<String?>(env, SubscribeToEventsInput::keywords.name)
val contentTemplate = getMutationInputField<String?>(env, SubscribeToEventsInput::contentTemplate.name)
val payload = createEventSubscriptionPayload(
projectEntity = entity,
name = getRequiredMutationInputField(env, SubscribeToEventsInput::name.name),
channel = getRequiredMutationInputField(env, SubscribeToEventsInput::channel.name),
channelConfig = getRequiredMutationInputField(env, SubscribeToEventsInput::channelConfig.name),
events = getRequiredMutationInputField(env, SubscribeToEventsInput::events.name),
keywords = getMutationInputField(env, SubscribeToEventsInput::keywords.name),
contentTemplate = getMutationInputField(env, SubscribeToEventsInput::contentTemplate.name),
name = name ?: EventSubscription.computeName(
events = events,
keywords = keywords,
channel = channel,
channelConfig = channelConfig,
contentTemplate = contentTemplate,
),
channel = channel,
channelConfig = channelConfig,
events = events,
keywords = keywords,
contentTemplate = contentTemplate,
)
// OK
return mapOf("subscription" to payload)
Expand Down Expand Up @@ -295,7 +310,7 @@ data class SubscribeToEventsInput(
@TypeRef(embedded = true, suffix = "Input")
val projectEntity: ProjectEntityID?,
@APIDescription("Unique name of the channel in its scope (null for backward compatibility, will be required in V5)")
val name: String?,
val name: String? = null,
@APIDescription("Channel to send this event to")
val channel: String,
@APIDescription("Channel configuration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,67 @@ class EventSubscriptionMutationsIT : AbstractNotificationTestSupport() {
}
}

@Test
fun `Subscription name is not required yet and can be omitted`() {
asAdmin {
project {
branch {
run(
"""
mutation {
subscribeBranchToEvents(input: {
project: "${project.name}",
branch: "$name",
channel: "mock",
channelConfig: {
target: "#test"
},
events: [
"new_promotion_run"
],
keywords: "GOLD",
}) {
errors {
message
exception
}
subscription {
id
name
}
}
}
"""
) { data ->
checkGraphQLUserErrors(data, "subscribeBranchToEvents") { payload ->
val id = payload.getRequiredJsonField("subscription").getRequiredTextField("id")
val name = payload.getRequiredJsonField("subscription").getRequiredTextField("name")
assertEquals(name, id)
val subscription: EventSubscription =
eventSubscriptionService.getSubscriptionByName(this, name)
assertEquals(
setOf(
"new_promotion_run"
),
subscription.events
)
assertEquals(this, subscription.projectEntity)
assertEquals("GOLD", subscription.keywords)
assertEquals(
"mock",
subscription.channel
)
assertEquals(
mapOf("target" to "#test").asJson(),
subscription.channelConfig
)
}
}
}
}
}
}

@Test
fun `Settings subscriptions using the promotion level mutation`() {
asAdmin {
Expand Down

0 comments on commit acc692a

Please sign in to comment.