Skip to content

Commit

Permalink
feat: add rest method for productName and itemId
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jul 23, 2024
1 parent 5df5243 commit ee8f291
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public Response getHelpById(String id) {
}
}

@Override
public Response getHelpByProductNameItemId(String productName, String helpItemId) {
try (Response response = client.getHelpByProductNameItemId(productName, helpItemId)) {
Help help = response.readEntity(Help.class);
HelpDTO helpDTO = helpMapper.mapHelp(help);
return Response.ok(helpDTO).build();
}
}

@Override
public Response searchHelps(HelpSearchCriteriaDTO helpSearchCriteriaDTO) {

Expand Down
32 changes: 32 additions & 0 deletions src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,38 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HelpPageResult'
/helps/{productName}/{helpItemId}:
get:
x-onecx:
permissions:
help:
- read
tags:
- helpsInternal
description: search help item by product name and item id
operationId: getHelpByProductNameItemId
parameters:
- name: productName
in: path
required: true
description: product name
schema:
type: string
- name: helpItemId
in: path
required: true
description: help item ID
schema:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Help'
404:
description: Help not found
components:
schemas:
HelpSearchCriteria:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,43 @@ void getAllProductsTest() {
mockServerClient.clear(MOCK_ID);
}

@Test
void getProductNameItemIdTest() {

var offsetDateTime = OffsetDateTime.parse("2023-11-30T13:53:03.688710200+01:00");
Help data = createHelp("p1",
"i1",
"testContext",
offsetDateTime,
"http://localhost:8080/mfe",
"testUser",
"itemId1");

mockServerClient
.when(request().withPath(HELP_SVC_INTERNAL_API_BASE_PATH + "/p1/i1")
.withMethod(HttpMethod.GET))
.withPriority(100)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));

// bff call
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
.header(APM_HEADER_PARAM, ADMIN)
.contentType(APPLICATION_JSON)
.get("/p1/i1")
.then()
.statusCode(Response.Status.OK.getStatusCode())
.extract().as(HelpDTO.class);

Assertions.assertNotNull(response);
Assertions.assertEquals(data.getItemId(), response.getItemId());
Assertions.assertEquals(data.getProductName(), response.getProductName());
}

@Test
void errorSecurityTest() {
String id = "82689h23-9624-2234-c50b-8749d073c287";
Expand Down

0 comments on commit ee8f291

Please sign in to comment.