Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
Write an unhappy path unit test for the consolidated endpoint handler
Browse files Browse the repository at this point in the history
  • Loading branch information
halprin committed Jan 25, 2024
1 parent 358cc3e commit 3aad541
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ DomainResponse handleConsolidatedSummary(DomainRequest request) {

} catch (Exception e) {
var errorString = "Unable to retrieve consolidated orders";
logger.logFatal(errorString, e);
logger.logError(errorString, e);
return domainResponseHelper.constructErrorResponse(500, errorString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,33 @@ class EtorDomainRegistrationTest extends Specification {
1 * mockResponseHelper.constructOkResponse(expectedResultMap) >> new DomainResponse(expectedStatusCode)
}

def "Consolidated metadata endpoint fails with a 500"() {
given:
def expectedStatusCode = 500

def request = new DomainRequest()
request.setPathParams(["sender": "testSender"])

def connector = new EtorDomainRegistration()
TestApplicationContext.register(EtorDomainRegistration, connector)

def mockResponseHelper = Mock(DomainResponseHelper)
TestApplicationContext.register(DomainResponseHelper, mockResponseHelper)

def mockOrchestrator = Mock(PartnerMetadataOrchestrator)
mockOrchestrator.getConsolidatedMetadata(_ as String) >> { throw new PartnerMetadataException("woops") }
TestApplicationContext.register(PartnerMetadataOrchestrator, mockOrchestrator)

TestApplicationContext.injectRegisteredImplementations()

when:
def response = connector.handleConsolidatedSummary(request)

then:
response.statusCode == 500
1 * mockResponseHelper.constructErrorResponse(expectedStatusCode, _ as String) >> new DomainResponse(expectedStatusCode)
}

def "results endpoint happy path"() {
given:
def expectedStatusCode = 200
Expand Down

0 comments on commit 3aad541

Please sign in to comment.