Skip to content

Commit

Permalink
SST-49 feat: tests coverage for new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitars committed Dec 26, 2024
1 parent dd5a058 commit bf489b6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Feature: Main feature for all GET requests with path 'list/entity/site'
"tags":[],
"rooms":
[
{"id":1,"name":"room1","customFields":{},"seatedCapacity":25,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null},
{"id":2,"name":"room2","customFields":{},"seatedCapacity":50,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null}
{"id":1,"name":"room1","customFields":{},"seatedCapacity":25,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null },
{"id":2,"name":"room2","customFields":{},"seatedCapacity":50,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null}
],
"documents":[],
"rules":[],
Expand Down Expand Up @@ -127,8 +127,8 @@ Feature: Main feature for all GET requests with path 'list/entity/site'
"tags":[],
"rooms":
[
{"id":1,"name":"room1","customFields":{},"seatedCapacity":25,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null},
{"id":2,"name":"room2","customFields":{},"seatedCapacity":50,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null}
{"id":1,"name":"room1","customFields":{},"seatedCapacity":25,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null},
{"id":2,"name":"room2","customFields":{},"seatedCapacity":50,"siteId":201,"siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null}
],
"documents":[],
"rules":[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Feature: Main feature for all POST requests with path 'list/entity/site'
"customFields":{},
"rooms":
[
{"id":"#number","name":"room001","customFields":{},"seatedCapacity":100,"siteId":"#number","siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null},
{"id":"#number","name":"room001","customFields":{},"seatedCapacity":100,"siteId":"#number","siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null},
],
"documents":[],
"rules":[{"id":"#ignore","description":"www","startDate":null,"endDate":null,"startDateTime":"2019-12-01T09:07:00.000Z","endDateTime":"2025-12-31T09:07:00.000Z","repeat":"year","repeatEnd":"onDate","repeatEndAfter":null,"repeatOn":"2024-02-12","created":"#ignore","modified":"#ignore"}],
Expand Down Expand Up @@ -162,7 +162,7 @@ Feature: Main feature for all POST requests with path 'list/entity/site'
"publicTransportDirections":"A3A5A7A9A12A15A18A21A24A27A30A33A36A39A42A45A48A51A54A57A60A63A66A69A72A75A78A81A84A87A90A93A96A100A104A108A112A116A120A124A128A132A136A140A144A148A152A156A160A164A168A172A176A180A184A188A192A196A200A204A208A212A216A220A224A228A232A236A240A244A248A252A256A",
"specialInstructions":"A3A5A7A9A12A15A18A21A24A27A30A33A36A39A42A45A48A51A54A57A60A63A66A69A72A75A78A81A84A87A90A93A96A100A104A108A112A116A120A124A128A132A136A140A144A148A152A156A160A164A168A172A176A180A184A188A192A196A200A204A208A212A216A220A224A228A232A236A240A244A248A252A256A",
"tags":[],
"rooms":[{"documents":[],"customFields":{},"rules":[],"siteTimeZone":null,"createdOn":null,"tags":[],"modifiedOn":null,"directions":null,"seatedCapacity":0,"name":"testSite_2A15A18A21A24A27A30A33A36A39A42A45A48A51A54A57A60A63A66A69A72A75A78A81A84A87A90A93A96A100A104A108A112A116A120A124A128A132A136A140A144A148A150","siteId":"#ignore","kioskUrl":null,"id":"#ignore","facilities":null}],
"rooms":[{"documents":[],"customFields":{},"rules":[],"siteTimeZone":null,"createdOn":null,"tags":[],"modifiedOn":null,"directions":null,"seatedCapacity":0,"name":"testSite_2A15A18A21A24A27A30A33A36A39A42A45A48A51A54A57A60A63A66A69A72A75A78A81A84A87A90A93A96A100A104A108A112A116A120A124A128A132A136A140A144A148A150","siteId":"#ignore","kioskUrl":null,"id":"#ignore","facilities":null,"virtualRoomUrl":null}],
"documents":[],
"rules":[],
"customFields":{}
Expand Down Expand Up @@ -439,6 +439,78 @@ Feature: Main feature for all POST requests with path 'list/entity/site'
And match $.errorMessage == "Timezone is required."


Scenario: (-) Create non-virtual Site with virtual room url

* def newSite =
"""
{
"isAdministrationCentre":true,
"isVirtual":false,
"isShownOnWeb":true,
"kioskUrl":null,
"name":"someSite444",
"street":"Frome Rd",
"suburb":"Adelaide",
"state":"SA",
"timezone":"Australia/Sydney",
"postcode":"5000",
"country":{"id":1,"isoCodeAlpha3":null,"isoCodeNumeric":null,"name":"Australia","saccCode":null},
"longitude":138.60569150,
"latitude":-34.91638480,
"drivingDirections":"someDrivingDirections",
"publicTransportDirections":"somePublicTransportDirections",
"specialInstructions":"someSpecialInstructions",
"tags":[],
"rooms":[{"siteId":null,"customFields":{},"name":"room001","seatedCapacity":"100", "virtualRoomUrl":"https://someUrl.com"}],
"documents":[],
"customFields":{},
"rules":[]
}
"""

Given path ishPath
And request newSite
When method POST
Then status 400
And match $.errorMessage == "Room named room001 cannot have virtual room url if site is not virtual"


Scenario: (-) Create virtual Site with incorrect virtual room url

* def newSite =
"""
{
"isAdministrationCentre":true,
"isVirtual":true,
"isShownOnWeb":true,
"kioskUrl":null,
"name":"someSite444",
"street":"Frome Rd",
"suburb":"Adelaide",
"state":"SA",
"timezone":"Australia/Sydney",
"postcode":"5000",
"country":{"id":1,"isoCodeAlpha3":null,"isoCodeNumeric":null,"name":"Australia","saccCode":null},
"longitude":138.60569150,
"latitude":-34.91638480,
"drivingDirections":"someDrivingDirections",
"publicTransportDirections":"somePublicTransportDirections",
"specialInstructions":"someSpecialInstructions",
"tags":[],
"rooms":[{"siteId":null,"customFields":{},"name":"room001","seatedCapacity":"100", "virtualRoomUrl":"w3t34tf"}],
"documents":[],
"customFields":{},
"rules":[]
}
"""

Given path ishPath
And request newSite
When method POST
Then status 400
And match $.errorMessage == "The virtual room url is incorrect."




# Scenario: (-) Create Site with Suburb >50 symbols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Main feature for all PUT requests with path 'list/entity/site'
"""
{
"isAdministrationCentre":false,
"isVirtual":false,
"isVirtual":true,
"isShownOnWeb":false,
"kioskUrl":null,
"name":"someSite100",
Expand Down Expand Up @@ -57,7 +57,7 @@ Feature: Main feature for all PUT requests with path 'list/entity/site'
"""
{"id":"#(id)",
"isAdministrationCentre":true,
"isVirtual":false,
"isVirtual":true,
"isShownOnWeb":true,
"kioskUrl":null,
"name":"someSite100_upd",
Expand Down Expand Up @@ -92,7 +92,7 @@ Feature: Main feature for all PUT requests with path 'list/entity/site'
{
"id":"#number",
"isAdministrationCentre":true,
"isVirtual":false,
"isVirtual":true,
"isShownOnWeb":true,
"kioskUrl":null,
"name":"someSite100_upd",
Expand All @@ -108,7 +108,7 @@ Feature: Main feature for all PUT requests with path 'list/entity/site'
"publicTransportDirections":"somePublicTransportDirections_upd",
"specialInstructions":"someSpecialInstructions_upd",
"tags":[208],
"rooms":[{"id":"#number","name":"room1","seatedCapacity":75,"siteId":"#number","siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"customFields":{},"documents":[],"rules":[],"createdOn":null,"modifiedOn":null}],
"rooms":[{"id":"#number","name":"room1","seatedCapacity":75,"siteId":"#number","siteTimeZone":null,"kioskUrl":null,"directions":null,"facilities":null,"tags":[],"customFields":{},"documents":[],"rules":[],"createdOn":null,"modifiedOn":null,"virtualRoomUrl":null}],
"documents":[],
"rules":[{"id":"#ignore","description":"fff","startDate":"2020-01-01","endDate":"2020-02-29","startDateTime":null,"endDateTime":null,"repeat":"hour","repeatEnd":"never","repeatEndAfter":null,"repeatOn":null,"created":"#ignore","modified":"#ignore"}],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ class SiteApiService extends TaggableApiService<SiteDTO, Site, SiteDao> {
if (dbRoom.seatedCapacity != room.seatedCapacity) {
dbRoom.seatedCapacity = room.seatedCapacity
}
dbRoom.virtualRoomUrl = room.virtualRoomUrl
} else {
context.newObject(Room).with { it ->
it.site = site
it.name = trimToNull(room.name)
it.seatedCapacity = room.seatedCapacity
it.virtualRoomUrl = room.virtualRoomUrl
}
}
}
Expand Down Expand Up @@ -201,7 +203,7 @@ class SiteApiService extends TaggableApiService<SiteDTO, Site, SiteDao> {
RoomFunctions.validateForSave(room, context, room.id, validator, id != null)

if(!siteDTO.isVirtual && trimToNull(room.virtualRoomUrl) != null)
validator.throwClientErrorException(siteDTO?.id, "rooms[$i]name", "Room named ${duplicates[0].name} cannot have virtual room url if site is not virtual")
validator.throwClientErrorException(siteDTO?.id, "rooms[$i]name", "Room named ${room.name} cannot have virtual room url if site is not virtual")
}

TagFunctions.validateTagForSave(Site, context, siteDTO.tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ class RoomFunctions {
.where(Site.ID.eq(roomDTO.siteId))
.selectOne(context)

String virtualRoomUrl = StringUtils.trimToNull(roomDTO.virtualRoomUrl)
if (isSiteExists) {
if (!site?.id) {
validator.throwClientErrorException(site?.id, 'siteId', "Can't bind room to nonexistent site")
}

String virtualRoomUrl = StringUtils.trimToNull(roomDTO.virtualRoomUrl)
if(virtualRoomUrl != null) {
if(!site.isVirtual)
validator.throwClientErrorException(virtualRoomUrl, 'virtualRoomUrl', "Cannot set virtual room url for not virtual site")
if (!site.isVirtual && virtualRoomUrl != null)
validator.throwClientErrorException(virtualRoomUrl, 'virtualRoomUrl', "Cannot set virtual room url for not virtual site")
}

if(!ValidationUtil.isValidUrl(virtualRoomUrl))
validator.throwClientErrorException(roomDTO?.virtualRoomUrl, 'virtualRoomUrl', 'The virtual room url is incorrect.')
}
if (virtualRoomUrl != null) {
if (!ValidationUtil.isValidUrl(virtualRoomUrl))
validator.throwClientErrorException(roomDTO?.virtualRoomUrl, 'virtualRoomUrl', 'The virtual room url is incorrect.')
}

Long roomId = ObjectSelect.query(Room)
Expand Down

0 comments on commit bf489b6

Please sign in to comment.