Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package yakworks.rest

import gorm.tools.transaction.WithTrx
import grails.gorm.transactions.Rollback
import grails.gorm.transactions.Transactional
import okhttp3.Request
import okhttp3.RequestBody
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.springframework.http.HttpStatus

import spock.lang.Ignore
import spock.lang.IgnoreRest
import yakworks.rally.orgs.model.Location
import yakworks.rest.client.OkAuth
import yakworks.rest.client.OkHttpRestTrait
import grails.testing.mixin.integration.Integration
Expand Down Expand Up @@ -362,17 +364,27 @@ class OrgRestApiSpec extends Specification implements OkHttpRestTrait, WithTrx {
body.errors[0].message == 'must not be null'
}

@Transactional
void "testing put"() {
when:
Response resp = put(path, [name: "9Galt"], 67)
setup:
int countBefore = Location.count()
Location existing = Org.get(67).location

when:
Response resp = put(path, [name: "9Galt", location:[city:"test"], locations:[[:]]], 67)
Map body = bodyToMap(resp)
Location updated = Org.get(67).location
int countAfter = Location.count()

then:
resp.code() == HttpStatus.OK.value()
body.id
body.name == '9Galt'

and:
countBefore == countAfter
existing.id == updated.id
updated.city == "test"
}

void "test post with tags"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class OrgRepoTests extends Specification implements DomainIntTest {
location: [
city: 'Denver',
street1: '1st'
]
],
]
org = orgRepo.update(data)
flush()
Expand All @@ -278,6 +278,27 @@ class OrgRepoTests extends Specification implements DomainIntTest {
countBefore == countAfter
}

void "should not create empty locations"() {
setup:
Org org = Org.get(11)
int countBefore = Location.count()

when:
Map data = [
id: org.id,
locations:[
[:]
]
]
orgRepo.update(data)
flushAndClear()
int countAfter = Location.count()

then: "no new location should be added"
noExceptionThrown()
countBefore == countAfter
}

void "test insert with orgmembers"() {
given:
OrgDimensionTesting.setDimensions(['Branch', 'Division', 'Business'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ abstract class AbstractOrgRepo extends LongIdGormRepo<Org> {
*/
void persistToManyWithOrgId(Org org, GormRepo assocRepo, List<Map> assocList){
if(!assocList) return
//remove, if there are any empty maps.
assocList = assocList.findAll { Map it -> it.size() > 0}
assocList.each { it['orgId'] = org.getId()}
assocRepo.createOrUpdate(assocList)
}
Expand Down