-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retain deployId
query param from PUT
request
#86
Changes from 3 commits
14fce05
b977527
59a8147
4292bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.inngest.*; | ||
import com.inngest.springboot.InngestConfiguration; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.jupiter.api.*; | ||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStub; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; | ||
|
||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
|
||
@ExtendWith(SystemStubsExtension.class) | ||
public class SyncRequestTest { | ||
static class SyncInngestConfiguration extends InngestConfiguration { | ||
protected HashMap<String, InngestFunction> functions() { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
protected Inngest inngestClient() { | ||
return new Inngest("spring_test_registration"); | ||
} | ||
|
||
@Override | ||
protected ServeConfig serve(Inngest client) { | ||
return new ServeConfig(client); | ||
} | ||
|
||
@Bean | ||
protected CommHandler commHandler(@Autowired Inngest inngestClient) { | ||
ServeConfig serveConfig = new ServeConfig(inngestClient); | ||
return new CommHandler(functions(), inngestClient, serveConfig, SupportedFrameworkName.SpringBoot); | ||
} | ||
} | ||
|
||
@SystemStub | ||
private static EnvironmentVariables environmentVariables; | ||
|
||
public static MockWebServer mockWebServer; | ||
|
||
@Import(SyncInngestConfiguration.class) | ||
@WebMvcTest(DemoController.class) | ||
@Nested | ||
@EnabledIfSystemProperty(named = "test-group", matches = "unit-test") | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class InnerSpringTest { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@BeforeEach | ||
void BeforeEach() throws Exception { | ||
mockWebServer = new MockWebServer(); | ||
mockWebServer.start(); | ||
|
||
String serverUrl = mockWebServer.url("").toString(); | ||
|
||
environmentVariables.set("INNGEST_API_BASE_URL", serverUrl.substring(0, serverUrl.length() - 1)); | ||
KiKoS0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@AfterEach | ||
void afterEach() throws Exception { | ||
mockWebServer.shutdown(); | ||
} | ||
|
||
private void assertThatPayloadDoesNotContainDeployId(RecordedRequest recordedRequest) throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/inngest/inngest/blob/main/docs/SDK_SPEC.md#432-syncing
I could add a comment linking the spec doc but i'm not sure if it's a good idea. |
||
String requestBody = recordedRequest.getBody().readUtf8(); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode jsonNode = objectMapper.readTree(requestBody); | ||
|
||
assertFalse(jsonNode.has("deployId")); | ||
} | ||
|
||
@Test | ||
public void shouldIncludeDeployIdInSyncRequestIfPresent() throws Exception { | ||
mockWebServer.enqueue(new MockResponse().setBody("Success")); | ||
mockWebServer.enqueue(new MockResponse().setBody("Success")); | ||
mockWebServer.enqueue(new MockResponse().setBody("Success")); | ||
|
||
mockMvc.perform(put("/api/inngest") | ||
.header("Host", "localhost:8080") | ||
.param("deployId", "1")) | ||
.andExpect(status().isOk()); | ||
|
||
RecordedRequest recordedRequest = mockWebServer.takeRequest(); | ||
|
||
assertEquals("/fn/register", recordedRequest.getRequestUrl().encodedPath()); | ||
assertEquals("1", recordedRequest.getRequestUrl().queryParameter("deployId")); | ||
assertThatPayloadDoesNotContainDeployId(recordedRequest); | ||
|
||
mockMvc.perform(put("/api/inngest") | ||
.header("Host", "localhost:8080")) | ||
.andExpect(status().isOk()); | ||
|
||
recordedRequest = mockWebServer.takeRequest(); | ||
|
||
assertEquals("/fn/register", recordedRequest.getRequestUrl().encodedPath()); | ||
assertNull(recordedRequest.getRequestUrl().queryParameter("deployId")); | ||
assertThatPayloadDoesNotContainDeployId(recordedRequest); | ||
|
||
mockMvc.perform(put("/api/inngest") | ||
.header("Host", "localhost:8080") | ||
.param("deployId", "3")) | ||
.andExpect(status().isOk()); | ||
|
||
recordedRequest = mockWebServer.takeRequest(); | ||
|
||
assertEquals("/fn/register", recordedRequest.getRequestUrl().encodedPath()); | ||
assertEquals("3", recordedRequest.getRequestUrl().queryParameter("deployId")); | ||
assertThatPayloadDoesNotContainDeployId(recordedRequest); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.inngest | ||
|
||
enum class InngestQueryParamKey( | ||
val value: String, | ||
) { | ||
SyncId("deployId"), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to ask this on another PR, but what exactly does this do? Run it only in
make test
ormake itest
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It runs only on
make test
, the property is set in:inngest-kt/inngest-spring-boot-demo/build.gradle.kts
Line 49 in 59a8147
I'm open to better ways to accomplish this though.