Skip to content

Commit

Permalink
Angular oauth2 / clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolo89 committed May 17, 2022
1 parent ba158bb commit dae6982
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class AngularCommon {

protected static final String ANGULAR_JSON_FILE_NAME = "angular.json";

protected static final String IMPORT_REGEX = "(^import[\\s]+[^;]+;)";
protected static final String EXISTING_IMPORT_PATTERN = "^(import[\\s]+\\{[^\\}]+)\\} from '[%s]+';";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static tech.jhipster.lite.common.domain.WordUtils.indent;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.ALLOWED_COMMON_JS_DEPENDENCIES_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.ANGULAR_JSON_FILE_NAME;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.COMA;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.C_BRACKET;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.DECLARATIONS_REGEX;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void addTest(Project project, String specTsFilePath, String testToAdd, St

@Override
public void addAllowedCommonJsDependenciesAngularJson(Project project, String libToAdd) {
String fullFilePath = FileUtils.getPath(project.getFolder(), "angular.json");
String fullFilePath = FileUtils.getPath(project.getFolder(), ANGULAR_JSON_FILE_NAME);
String fileContent = getFileContent(fullFilePath);
String newFileContent = getFirstMatchInFile(ALLOWED_COMMON_JS_DEPENDENCIES_REGEX_LIST, fileContent)
.map(dependenciesPrefix -> appendValuesInList(fileContent, dependenciesPrefix, libToAdd, project.getEndOfLine()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ private void updateAppModuleTsFile(Project project) {
project,
APP_MODULE_TS_FILE_PATH,
"""
import {HTTP_INTERCEPTORS} from '@angular/common/http';
import {LoginComponent} from './login/login.component';
import {Oauth2AuthService} from './auth/oauth2-auth.service';
import {HttpAuthInterceptor} from './auth/http-auth.interceptor';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
"""
);

Expand Down Expand Up @@ -151,8 +151,8 @@ private void addTestInAppSpecTsFile(Project project) {
project,
APP_COMPONENT_SPEC_TS_FILE_PATH,
"""
import {By} from '@angular/platform-browser';
import {LoginComponent} from './login/login.component';
import { By } from '@angular/platform-browser';
import { LoginComponent } from './login/login.component';
"""
);
angularCommonService.addDeclarations(project, APP_COMPONENT_SPEC_TS_FILE_PATH, """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {RouterTestingModule} from '@angular/router/testing';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatIconModule} from '@angular/material/icon';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';

import { AppComponent } from './app.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TestBed } from '@angular/core/testing';
import { HttpHandler, HttpRequest } from '@angular/common/http';
import { lastValueFrom, of } from 'rxjs';

import { HttpAuthInterceptor } from './http-auth.interceptor';
import { Oauth2AuthService } from './oauth2-auth.service';
import { HttpHandler, HttpRequest } from '@angular/common/http';
import { lastValueFrom, of } from 'rxjs';

import Mock = jest.Mock;

const URL = 'http://localhost:8080/api/dummy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public static void assertUpdatedFiles(Project project) throws IOException {
"""
import { NgModule, APP_INITIALIZER} from '@angular/core';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import {HTTP_INTERCEPTORS} from '@angular/common/http';
import {LoginComponent} from './login/login.component';
import {Oauth2AuthService} from './auth/oauth2-auth.service';
import {HttpAuthInterceptor} from './auth/http-auth.interceptor';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
const initializeApp = (oauth2AuthService: Oauth2AuthService) => {
return () => {
Expand Down Expand Up @@ -127,8 +127,8 @@ public static void assertUpdatedFiles(Project project) throws IOException {
expectedContentLines =
"""
import { AppComponent } from './app.component';
import {By} from '@angular/platform-browser';
import {LoginComponent} from './login/login.component';
import { By } from '@angular/platform-browser';
import { LoginComponent } from './login/login.component';
beforeEach(
waitForAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ private void verifyUpdatedFiles(Project project) {
project,
APP_MODULE_TS_FILE_PATH,
"""
import {HTTP_INTERCEPTORS} from '@angular/common/http';
import {LoginComponent} from './login/login.component';
import {Oauth2AuthService} from './auth/oauth2-auth.service';
import {HttpAuthInterceptor} from './auth/http-auth.interceptor';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
"""
);

Expand Down Expand Up @@ -177,8 +177,8 @@ private void verifyUpdatedFiles(Project project) {
project,
APP_COMPONENT_SPEC_TS_FILE_PATH,
"""
import {By} from '@angular/platform-browser';
import {LoginComponent} from './login/login.component';
import { By } from '@angular/platform-browser';
import { LoginComponent } from './login/login.component';
"""
);

Expand Down

0 comments on commit dae6982

Please sign in to comment.