Skip to content

Commit

Permalink
Merge pull request #298 from SibirBear/issue254
Browse files Browse the repository at this point in the history
[#254] Add workspace name on Integration page (with test)
  • Loading branch information
Malcom1986 authored Aug 26, 2024
2 parents 888f381 + 36300e2 commit 1381683
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ public String deleteAllowedUrl(Model model,
@GetMapping("/integration")
@PreAuthorize(IS_USER_RELATED_TO_WKS)
public String getWorkspaceIntegrationPage(Model model, @PathVariable Long wksId, HttpServletRequest req) {
if (!workspaceService.existsWorkspaceById(wksId)) {
var wksOptional = workspaceService.getWorkspaceInfoById(wksId).orElse(null);

if (wksOptional == null) {
//TODO send to error page
log.error("Workspace with id {} not found", wksId);
return "redirect:/workspaces";
}

addTokenAndUrlToModel(model, wksId, req);

model.addAttribute("wksInfo", wksOptional);
model.addAttribute("wksName", wksOptional.name());

getStatisticDataToModel(model, wksId);
getLastTypoDataToModel(model, wksId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,25 @@ static void datasourceProperties(DynamicPropertyRegistry registry) {
@ParameterizedTest
@MethodSource("io.hexlet.typoreporter.test.factory.EntitiesFactory#getWorkspacesAndUsersRelated")
void getWorkspaceIntegrationPageIsSuccessful(final Long wksId, final String email) throws Exception {
final var apiAccessToken = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId)
final var workspaces = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId);
final var apiAccessToken = workspaces
.map(s -> s.getId() + ":" + s.getApiAccessToken())
.map(String::getBytes)
.map(Base64.getEncoder()::encodeToString)
.orElse(null);

final var wksName = workspaces
.map(m -> m.getWorkspace().getName())
.orElse(null);

MockHttpServletResponse response = mockMvc.perform(get("/workspace/{wksId}/integration", wksId.toString())
.with(user(email)))
.andExpect(model().attributeExists("wksBasicToken"))
.andExpect(model().attributeExists("wksBasicToken", "wksName"))
.andReturn().getResponse();

assertThat(response.getContentAsString()).contains(apiAccessToken);
assertThat(response.getContentAsString()).contains(wksName);

}

@ParameterizedTest
Expand Down Expand Up @@ -213,4 +220,5 @@ void delAllowedUrlFromWorkspace() throws Exception {
WORKSPACE_101_ID);
assertThat(deletedAllowedUrlOptional).isEmpty();
}

}

0 comments on commit 1381683

Please sign in to comment.