This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AcmeCompanyApi implements CompanyApi { | |
| private readonly acmeCausesEndpoint: AcmeCausesEndpoint; | |
| private readonly claimOpeningEndpoint: AcmeClaimOpeningEndpoint; | |
| private readonly authTokenRetriever: AcmeAuthTokenRetriever; | |
| constructor(config: AcmeApiConfig = new AcmeApiConfig()) { | |
| this.acmeCausesEndpoint = new AcmeCausesEndpoint(config); | |
| this.claimOpeningEndpoint = new AcmeClaimOpeningEndpoint(config); | |
| this.authTokenRetriever = new AcmeAuthTokenRetriever(config); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AcmeCompanyApi implements CompanyApi { | |
| private readonly forGettingCauses: ForGettingCauses; | |
| private readonly forOpeningClaim: ForOpeningClaim; | |
| private readonly authTokenRetriever: AuthTokenRetriever; | |
| constructor(config: AcmeApiConfig = new AcmeApiConfig()) { | |
| this.forGettingCauses = new AcmeCausesEndpoint(config); | |
| this.forOpeningClaim = new AcmeClaimOpeningEndpoint(config); | |
| this.authTokenRetriever = new AcmeAuthTokenRetriever(config); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('AcmeCompanyApi', () => { | |
| // some declarations | |
| beforeEach(() => { | |
| decoratedApi = { | |
| open: jest.fn<Promise<OpeningResult>, [Claim]>() | |
| }; | |
| api = new WithErrorHandlingCompanyApi(decoratedApi); | |
| claim = aClaim(causeCodeInClaim); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WithErrorHandlingCompanyApi implements CompanyApi { | |
| constructor(private readonly decoratedApi: CompanyApi) { | |
| } | |
| async open(claim: Claim): Promise<OpeningResult> { | |
| try { | |
| return await this.decoratedApi.open(claim); | |
| } catch (e) { | |
| if (e instanceof CannotRetrieveTokenError) { | |
| return OpeningResult.failed(claim, 'Acme API: failure retrieving token'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AcmeCompanyApi implements CompanyApi { | |
| constructor( | |
| private readonly forGettingCauses: ForGettingCauses, | |
| private readonly forOpeningClaim: ForOpeningClaim, | |
| private readonly authTokenRetriever: AuthTokenRetriever) { | |
| } | |
| async open(claim: Claim): Promise<OpeningResult> { | |
| const token = await this.authTokenRetriever.retrieveToken(); | |
| const causes = await this.forGettingCauses.getAllFor(claim, token); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AcmeCompanyApi implements CompanyApi { | |
| constructor( | |
| private readonly forGettingCauses: ForGettingCauses, | |
| private readonly forOpeningClaim: ForOpeningClaim, | |
| private readonly authTokenRetriever: AuthTokenRetriever) { | |
| } | |
| async open(claim: Claim): Promise<OpeningResult> { | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // some imports | |
| describe('AcmeCompanyApi', () => { | |
| // some declarations | |
| beforeEach(() => { | |
| forGettingCauses = { | |
| getAllFor: jest.fn<Promise<Cause[]>, [Claim, AuthToken]>() | |
| }; | |
| forOpeningClaim = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class OpeningResult | |
| { | |
| public static OpeningResult Success(ClaimId claimId, ReferenceInCompany referenceInCompany) | |
| { | |
| return new SuccessfulOpeningResult(claimId, referenceInCompany); | |
| } | |
| public static OpeningResult Failure(ClaimId claimId, string description) | |
| { | |
| return new FailingOpeningResult(claimId, description); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OpeningResult | |
| { | |
| private readonly string? _failureDescription; | |
| private readonly ReferenceInCompany? _referenceInCompany; | |
| private readonly ClaimId _claimId; | |
| private OpeningResult(ReferenceInCompany? referenceInCompany, ClaimId claimId, string? failureDescription) | |
| { | |
| _failureDescription = failureDescription; | |
| _claimId = claimId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // some imports | |
| public class NotifyOpenedClaimCommandBuilder { | |
| // some fields | |
| public static NotifyOpenedClaimCommandBuilder aNotifyOpenedCommand() { | |
| return new NotifyOpenedClaimCommandBuilder(); | |
| } | |
| public NotifyOpenedClaimCommandBuilder of(ClaimDataBuilder claimBuilder) { |
NewerOlder