Skip to content

Commit

Permalink
Merge pull request #1290 from qmonmert/fix/angular-jwt
Browse files Browse the repository at this point in the history
[Angular] JWT (clean code)
  • Loading branch information
pascalgrimaud authored Apr 8, 2022
2 parents 9941ee5 + 268385c commit 3d4a952
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

public class Angular {

public static final String APP_MODULE = "app.module.ts";
public static final String APP_COMPONENT = "app.component.ts";
public static final String APP_COMPONENT_SPEC = "app.component.spec.ts";
public static final String APP_COMPONENT_HTML = "app.component.html";

private Angular() {}

public static List<String> devDependencies() {
Expand Down Expand Up @@ -59,8 +64,8 @@ public static List<String> files() {
return List.of("angular.json", "jest.conf.js", "tsconfig.app.json", "tsconfig.json", "tsconfig.spec.json");
}

public static List<String> jwtFiles() {
return List.of("proxy.conf.json");
public static Map<String, String> jwtFiles() {
return Map.ofEntries(Map.entry("proxy.conf.json", ""));
}

public static Map<String, String> angularFiles() {
Expand All @@ -71,12 +76,12 @@ public static Map<String, String> angularFiles() {
Map.entry("main.ts", ""),
Map.entry("polyfills.ts", ""),
Map.entry("styles.css", ""),
Map.entry("app.module.ts", primaryApp),
Map.entry("app.component.ts", primaryApp),
Map.entry("app.component.html", primaryApp),
Map.entry(APP_MODULE, primaryApp),
Map.entry(APP_COMPONENT, primaryApp),
Map.entry(APP_COMPONENT_HTML, primaryApp),
Map.entry("app-routing.module.ts", primaryApp),
Map.entry("app-routing.module.spec.ts", primaryApp),
Map.entry("app.component.spec.ts", primaryApp),
Map.entry(APP_COMPONENT_SPEC, primaryApp),
Map.entry("environment.prod.ts", environments),
Map.entry("environment.prod.spec.ts", environments),
Map.entry("environment.ts", environments),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package tech.jhipster.lite.generator.client.angular.core.domain;

import static tech.jhipster.lite.common.domain.FileUtils.getPath;
import static tech.jhipster.lite.generator.client.angular.core.domain.Angular.APP_COMPONENT;
import static tech.jhipster.lite.generator.client.angular.core.domain.Angular.APP_COMPONENT_HTML;
import static tech.jhipster.lite.generator.client.angular.core.domain.Angular.APP_COMPONENT_SPEC;
import static tech.jhipster.lite.generator.client.angular.core.domain.Angular.APP_MODULE;
import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP;
import static tech.jhipster.lite.generator.project.domain.Constants.PACKAGE_JSON;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME;
Expand All @@ -18,11 +22,6 @@ public class AngularDomainService implements AngularService {
public static final String SOURCE_PRIMARY = getPath(SOURCE, APP);
public static final String DESTINATION_PRIMARY = APP;

private static final String APP_MODULE = "app.module.ts";
private static final String APP_COMPONENT = "app.component.ts";
private static final String APP_COMPONENT_SPEC = "app.component.spec.ts";
private static final String APP_COMPONENT_HTML = "app.component.html";

private final ProjectRepository projectRepository;
private final NpmService npmService;

Expand Down Expand Up @@ -432,7 +431,8 @@ public void addFiles(Project project) {
}

public void addJwtFiles(Project project) {
Angular.jwtFiles().forEach(file -> projectRepository.add(project, SOURCE, file));
project.addConfig("serverPort", 8080);
Angular.jwtFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, getPath("", path)));
}

public void addAngularFiles(Project project) {
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/generator/client/angular/proxy.conf.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"/api": {
"target": "http://localhost:{{serverPort}}",
"secure": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,8 @@ public static void assertAppWithCss(Project project) {
}

public static void assertAppJwt(Project project) {
String pathAuth = "src/main/webapp/app/auth";
String pathLogin = "src/main/webapp/app/login";

assertFileExist(project, getPath(pathAuth, "account.model.ts"));
assertFileExist(project, getPath(pathAuth, "account.service.ts"));
assertFileExist(project, getPath(pathAuth, "account.service.spec.ts"));
assertFileExist(project, getPath(pathAuth, "auth-jwt.service.ts"));
assertFileExist(project, getPath(pathAuth, "auth-jwt.service.spec.ts"));
assertFileExist(project, getPath(pathAuth, "auth.interceptor.ts"));
assertFileExist(project, getPath(pathLogin, "login.service.ts"));
assertFileExist(project, getPath(pathLogin, "login.service.spec.ts"));
assertFileExist(project, getPath(pathLogin, "login.model.ts"));
String rootPath = "src/main/webapp/";
Angular.angularJwtFiles().forEach((file, path) -> assertFileExist(project, getPath(rootPath + path, file)));
}

public static void assertLogos(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void shouldAddJwtFiles() {

angularDomainService.addJwtFiles(project);

verify(projectRepository, times(1)).add(any(Project.class), anyString(), anyString());
verify(projectRepository, times(1)).template(any(Project.class), anyString(), anyString(), anyString());
}

@Test
Expand Down

0 comments on commit 3d4a952

Please sign in to comment.