我有以下集成测试。本质上,它在我们的数据库中保存了一个“帐户”对象,该对象在 1:many 关系中限制为 3 个 SdkApplication 对象。我想通过运行集成测试来测试这在控制器中是否正确执行。唯一的问题是 sac.response.json 的最后一行每次都返回相同的内容,即使控制器呈现了不同的结果。
在集成测试中调用 grails 控制器之间是否需要调用一些响应清晰的方法?
void testAddTooManySdkApplicationBackOfficeUserFails() {
doTestLoginJasonBackofficeUser(sac)
def account = ObjectMother.account("TestCo")
account.maxAuthorized3rdPartyApps = 3
account.company.save(flush: true)
account.save(flush: true, failOnError: true)
3.times {
setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
sac.addSdkApplication()
assertSDKAddedCorrectly(sac.response.json as JSONObject)
}
setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
sac.addSdkApplication()
def resp = sac.response.json as JSONObject
assertFalse("Should have failed to add an SDKApplication as the limit was reached", resp.success)
}