Skip to content

Commit

Permalink
Recurrent card : add a control in the code to forbid negative number …
Browse files Browse the repository at this point in the history
…for "minutes to remind before task" (#5483)

Signed-off-by: vlo-rte <valerie.longa@rte-france.com>
  • Loading branch information
vlo-rte authored and quinarygio committed Dec 11, 2023
1 parent afd6bad commit 0c002b6
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
Expand Up @@ -309,6 +309,8 @@ public static EasyRandom instantiateEasyRandom() {
.scanClasspathForConcreteTypes(true)
.overrideDefaultInitialization(false)
.ignoreRandomizationErrors(true)
.excludeField(predicate->predicate.getName().equals("durationInMinutes"))
.excludeField(predicate->predicate.getName().equals("secondsBeforeTimeSpanForReminder"))
.excludeField(predicate->predicate.getName().equals("usersAcks"))
.excludeField(predicate->predicate.getName().equals("usersReads"))
.excludeField(predicate->predicate.getName().equals("entitiesAcks"));
Expand Down
3 changes: 3 additions & 0 deletions services/cards-publication/src/main/modeling/swagger.yaml
Expand Up @@ -191,6 +191,7 @@ definitions:
durationInMinutes:
description: Duration in minutes of the event
type: integer
minimum: 0
TimeSpan:
type: object
description: An object to define a business time span
Expand Down Expand Up @@ -229,6 +230,7 @@ definitions:
durationInMinutes:
description: Duration in minutes of the event
type: integer
minimum: 0
required:
- hoursAndMinutes
HoursAndMinutes:
Expand Down Expand Up @@ -404,6 +406,7 @@ definitions:
description: Contains projection ex. 'EPSG:4326'
secondsBeforeTimeSpanForReminder:
type: integer
minimum: 0
toNotify:
type: boolean
description: Is false if the card must not be displayed in the feed and in monitoring screen
Expand Down
76 changes: 76 additions & 0 deletions src/test/api/karate/cards/cardsWithTimespans.feature
Expand Up @@ -90,6 +90,80 @@ Feature: Cards with timespans
}
"""


* def cardToTestBadRequest4 =
"""
{
"publisher" : "operator1_fr",
"processVersion" : "1",
"process" :"api_test",
"processInstanceId" : "processTimeSpan",
"state": "messageState",
"groupRecipients": ["Dispatcher"],
"severity" : "INFORMATION",
"startDate" : 1553186770681,
"summary" : {"key" : "defaultProcess.summary"},
"title" : {"key" : "defaultProcess.title"},
"data" : {"message":"a message"},
"secondsBeforeTimeSpanForReminder" :1000,
"timeSpans" : [
{"start" : 1553186770681 ,"end" :1553186770682 , "recurrence" :
{
"timeZone":"test",
"daysOfWeek":[2,3],
"hoursAndMinutes": {"hours":10,"minutes":20},
"durationInMinutes": -10
}
},
{"start" : 1553186770681 ,"end" :1553186770682 , "recurrence" :
{
"timeZone":"test",
"daysOfWeek":[4,5],
"hoursAndMinutes": {"hours":12,"minutes":22}
}
},
{"start" : 1553186770678}
]
}
"""


* def cardToTestBadRequest5 =
"""
{
"publisher" : "operator1_fr",
"processVersion" : "1",
"process" :"api_test",
"processInstanceId" : "processTimeSpan",
"state": "messageState",
"groupRecipients": ["Dispatcher"],
"severity" : "INFORMATION",
"startDate" : 1553186770681,
"summary" : {"key" : "defaultProcess.summary"},
"title" : {"key" : "defaultProcess.title"},
"data" : {"message":"a message"},
"secondsBeforeTimeSpanForReminder" :-1000,
"timeSpans" : [
{"start" : 1553186770681 ,"end" :1553186770682 , "recurrence" :
{
"timeZone":"test",
"daysOfWeek":[2,3],
"hoursAndMinutes": {"hours":10,"minutes":20},
"durationInMinutes": 10
}
},
{"start" : 1553186770681 ,"end" :1553186770682 , "recurrence" :
{
"timeZone":"test",
"daysOfWeek":[4,5],
"hoursAndMinutes": {"hours":12,"minutes":22}
}
},
{"start" : 1553186770678}
]
}
"""

Scenario: Post a card with timepans and recurrence

* def card =
Expand Down Expand Up @@ -303,6 +377,8 @@ Scenario: When post a card with no timeZone in timespan recurrence , it set the
| cardToTestBadRequest1 | "constraint violation : TimeSpan.Recurrence.HoursAndMinutes must be filled" |
| cardToTestBadRequest2 | "constraint violation : TimeSpan.Recurrence.daysOfWeek must be filled with values from 1 to 7" |
| cardToTestBadRequest3 | "constraint violation : TimeSpan.Recurrence.months must be filled with values from 0 to 11" |
| cardToTestBadRequest4 | "timeSpans[0].recurrence.durationInMinutes: must be greater than or equal to 0" |
| cardToTestBadRequest5 | "secondsBeforeTimeSpanForReminder: must be greater than or equal to 0" |


Scenario: delete perimeter created previously
Expand Down
37 changes: 37 additions & 0 deletions src/test/api/karate/cards/postCardWithRRuleRecurrence.feature
Expand Up @@ -66,6 +66,34 @@ Feature: postCardWithRRuleRecurrence
}
"""


* def cardWithRRuleObjectButDurationInMinutesNegative =
"""
{
"publisher" : "operator1_fr",
"processVersion" : "1",
"process" :"api_test",
"processInstanceId" : "process_cardWithRRuleObject",
"state": "messageState",
"groupRecipients": ["Dispatcher"],
"severity" : "ALARM",
"startDate" : 1583943924000,
"endDate" : 1584943924000,
"summary" : {"key" : "defaultProcess.summary"},
"title" : {"key" : "defaultProcess.title"},
"data" : {"message" : "a message with RRule recurrence object"},
"rRule": {
"freq" : "WEEKLY",
"count" : 10,
"byweekday" : ["TU", "FR"],
"byminute" : [10, 30],
"byhour" : [14, 16],
"bymonth" : [1, 12],
"durationInMinutes" : -120
}
}
"""

* def perimeter =
"""
{
Expand Down Expand Up @@ -207,6 +235,15 @@ Feature: postCardWithRRuleRecurrence
And match response.card.rRule.durationInMinutes == 90
And def cardUid = response.card.uid

# Push card to test BAD REQUEST in case of durationInMinutes negative
Given url opfabPublishCardUrl + 'cards'
And header Authorization = 'Bearer ' + authToken
And request cardWithRRuleObjectButDurationInMinutesNegative
When method post
Then status 400
And match response.message == 'Constraint violation in the request'
And match response.errors[0] == 'RRule.durationInMinutes: must be greater than or equal to 0'

#delete perimeter created previously
Given url opfabUrl + 'users/perimeters/perimeter'
And header Authorization = 'Bearer ' + authTokenAdmin
Expand Down

0 comments on commit 0c002b6

Please sign in to comment.