Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Last active August 7, 2023 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A-pZ/60fff9c4e97be6fc0b8930bc09a54844 to your computer and use it in GitHub Desktop.
Save A-pZ/60fff9c4e97be6fc0b8930bc09a54844 to your computer and use it in GitHub Desktop.
取引先を新規登録するテストクラス
package com.github.apz.salesforcesample.repository
import com.github.apz.salesforcesample.model.Company
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification
@SpringBootTest
class SalesforceRegisterTest extends Specification {
@Autowired
SalesforceAuthentication authentication
@Autowired
CompanyRepository repository
def "登録"() {
when:
def company = new Company()
company.name = "テストコードから登録した会社"
company.recordTypeId = "0120o000001TahMAAS" // 取引先のレコードタイプを指定
def authenticationResult = authentication.authentication() // Salesforceの認証を行い、、、
def result = repository.register(company, authenticationResult) // 取引先を登録する
then:
noExceptionThrown()
result
result.success == true
result.errors.size() == 0
}
def "登録エラー"() {
when:
def company = new Company()
company.name = "エラー登録の例"
// company.recordTypeId = "0120o000001TahMAAS" // 必須項目であるレコードタイプを設定しない例
def authenticationResult = authentication.authentication()
def result = repository.register(company, authenticationResult)
then:
noExceptionThrown()
result
result.success == false // 登録失敗
result.errors.size() != 0 // エラー情報が存在
}
}
INFO 18084 --- [ Test worker] c.g.a.s.repository.CompanyRepository :
result: RegisterResult(
id=0010l00001dKTpjAAG,
success=true,
errors=[]
)
INFO 18392 --- [ Test worker] c.g.a.s.repository.CompanyRepository :
result: RegisterResult(
id=null,
success=false,
errors=[{
message=レコードタイプ ID: this ID value isn't valid for the user: ,
errorCode=INVALID_CROSS_REFERENCE_KEY,
fields=[RecordTypeId]
}]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment