Skip to content

Commit 799b884

Browse files
authored
Add test for generating authorization URL in secured onboarding (#227)
This commit introduces a test to validate the generation of an authorization URL for the secured onboarding process using given parameters. It ensures that the URL matches the expected format and contains the necessary parts like application ID, state, and response type.
1 parent 7cb7773 commit 799b884

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.dke.data.agrirouter.documentation;
2+
3+
import com.dke.data.agrirouter.api.enums.SecuredOnboardingResponseType;
4+
import com.dke.data.agrirouter.api.service.parameters.AuthorizationRequestParameters;
5+
import com.dke.data.agrirouter.impl.onboard.secured.AuthorizationRequestServiceImpl;
6+
import com.dke.data.agrirouter.test.AbstractIntegrationTest;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.util.UUID;
11+
12+
class CreateAuthorizationUrlForSecuredOnboardingProcessTest extends AbstractIntegrationTest {
13+
14+
@Test
15+
void givenValidParametersWhenCreatingTheUrlThenTheUrlShouldBeGenerated() {
16+
var authorizationRequestService = new AuthorizationRequestServiceImpl(farmingSoftware.getEnvironment());
17+
18+
// [0] Define a custom state to identify the request, this is part of the application itself.ß
19+
var state = UUID.randomUUID().toString();
20+
21+
// [1] Define the parameters for the authorization request
22+
// ============================================================
23+
var parameters = new AuthorizationRequestParameters();
24+
parameters.setApplicationId("REPLACE_ME_WITH_ACTUAL_APPLICATION_ID");
25+
parameters.setResponseType(SecuredOnboardingResponseType.ONBOARD);
26+
parameters.setState(state);
27+
28+
// https://app.qa.agrirouter.farm/application/REPLACE_ME_WITH_ACTUAL_APPLICATION_ID/authorize?response_type=onboard&state=5dbbe1de-4e30-40fa-acd7-a17f9e3d6602&redirect_uri=
29+
var authorizationRequestURL = authorizationRequestService.getAuthorizationRequestURL(parameters);
30+
31+
// [2] Validate the generated URL
32+
// ============================================================
33+
Assertions.assertNotNull(authorizationRequestURL);
34+
Assertions.assertTrue(authorizationRequestURL.startsWith("https://app.qa.agrirouter.farm/application/"));
35+
Assertions.assertTrue(authorizationRequestURL.contains("/REPLACE_ME_WITH_ACTUAL_APPLICATION_ID/"));
36+
Assertions.assertTrue(authorizationRequestURL.contains("/authorize?response_type=onboard&state=" + state));
37+
Assertions.assertTrue(authorizationRequestURL.endsWith("&redirect_uri="));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)