1
1
# pylint: disable=redefined-outer-name
2
+ import datetime as dt
3
+
2
4
import pytest
3
5
4
6
from tests .api .namespace .use_case import common
5
7
from tests .factories .use_case_factory import UseCaseFactory
8
+ from tests .factories .use_case_version_factory import UseCaseVersionFactory
6
9
from tests .fixtures .valid_flow_json import * # noqa: F401, F403, pylint: disable=wildcard-import,unused-wildcard-import
7
10
from use_case_executor .domain .flow .schema_version import SchemaVersion
8
11
@@ -84,7 +87,7 @@ def test_publish_use_case_sets_latest_flow_as_production(
84
87
assert response .json () == {
85
88
"meta" : {
86
89
"has_pending_changes" : False ,
87
- "last_published_date" : common .add_utc_tz (published_version .created_at ),
90
+ "last_published_date" : common .add_utc_tz (published_version .published_at ),
88
91
"latest_version_date" : common .add_utc_tz (published_version .created_at ),
89
92
},
90
93
"data" : common .make_flow_variant (
@@ -94,3 +97,27 @@ def test_publish_use_case_sets_latest_flow_as_production(
94
97
95
98
session .expire_all ()
96
99
assert use_case .production_version_id == versions [- 1 ].id
100
+
101
+
102
+ def test_publish_use_case_updates_published_at_even_if_the_use_case_is_already_published (
103
+ non_debug_client ,
104
+ use_case ,
105
+ session ,
106
+ params ,
107
+ ):
108
+ initial_published_at = dt .datetime .utcnow ()
109
+ UseCaseVersionFactory (
110
+ use_case = use_case , published_at = initial_published_at , is_production_version = True
111
+ )
112
+ assert initial_published_at == use_case .production_version .published_at
113
+
114
+ response = non_debug_client .post (
115
+ f"/use_cases/{ use_case .uuid } /flows/latest/publish" , params = params
116
+ )
117
+
118
+ assert response .status_code == 200
119
+ published_at = response .json ()["meta" ]["last_published_date" ]
120
+ assert published_at != initial_published_at
121
+
122
+ session .expire_all ()
123
+ assert published_at == common .add_utc_tz (use_case .production_version .published_at )
0 commit comments