@@ -2,6 +2,7 @@ package com.opendatamask.controller
22
33import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
44import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
5+ import com.opendatamask.dto.PostJobActionRequest
56import com.opendatamask.model.ActionType
67import com.opendatamask.model.PostJobAction
78import com.opendatamask.security.JwtAuthenticationFilter
@@ -51,12 +52,13 @@ class PostJobActionControllerTest {
5152
5253 @Test
5354 fun `POST create action returns 201` () {
54- val action = PostJobAction (workspaceId = 1L , actionType = ActionType .WEBHOOK , config = """ {"url":"http://example.com"}""" )
55- whenever(service.createAction(any<PostJobAction >())).thenReturn(action.copy(id = 1L ))
55+ val request = PostJobActionRequest (actionType = ActionType .WEBHOOK , config = """ {"url":"http://example.com"}""" )
56+ val saved = PostJobAction (id = 1L , workspaceId = 1L , actionType = ActionType .WEBHOOK , config = """ {"url":"http://example.com"}""" )
57+ whenever(service.createAction(any<PostJobAction >())).thenReturn(saved)
5658 mockMvc.perform(
5759 post(" /api/workspaces/1/actions" )
5860 .contentType(MediaType .APPLICATION_JSON )
59- .content(mapper.writeValueAsString(action ))
61+ .content(mapper.writeValueAsString(request ))
6062 ).andExpect(status().isCreated)
6163 }
6264
@@ -66,4 +68,30 @@ class PostJobActionControllerTest {
6668 .andExpect(status().isNoContent)
6769 verify(service).deleteAction(42L )
6870 }
71+
72+ @Test
73+ fun `PUT update action returns 200 with correct response body` () {
74+ val request = PostJobActionRequest (
75+ actionType = ActionType .WEBHOOK ,
76+ config = """ {"url":"http://example.com"}"""
77+ )
78+ val returned = PostJobAction (
79+ id = 42L ,
80+ workspaceId = 1L ,
81+ actionType = ActionType .WEBHOOK ,
82+ config = """ {"url":"http://example.com"}"""
83+ )
84+ whenever(service.updateAction(eq(1L ), eq(42L ), any<PostJobActionRequest >())).thenReturn(returned)
85+ mockMvc.perform(
86+ put(" /api/workspaces/1/actions/42" )
87+ .contentType(MediaType .APPLICATION_JSON )
88+ .content(mapper.writeValueAsString(request))
89+ )
90+ .andExpect(status().isOk)
91+ .andExpect(jsonPath(" $.id" ).value(42 ))
92+ .andExpect(jsonPath(" $.workspaceId" ).value(1 ))
93+ .andExpect(jsonPath(" $.actionType" ).value(" WEBHOOK" ))
94+ .andExpect(jsonPath(" $.config" ).value(""" {"url":"http://example.com"}""" ))
95+ verify(service).updateAction(eq(1L ), eq(42L ), any<PostJobActionRequest >())
96+ }
6997}
0 commit comments