Skip to content

Commit

Permalink
Angular: apply prettier on angularoauth2app
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Sep 28, 2024
1 parent 6f26ec6 commit 53a30f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ public class AngularOauth2ModuleFactory {
private static final String TEST_IMPORTS =
"""
import { By } from '@angular/platform-browser';
import LoginComponent from './login/login.component';
""";
import LoginComponent from './login/login.component';""";

private static final ElementReplacer TEST_NEEDLE = lineAfterRegex("^\\s+it\\('should have appName',[^}]+\\}\\);");

private static final String LOGIN_IMPORT =
"""
import LoginComponent from './login/login.component';
""";
private static final String LOGIN_IMPORT = "import LoginComponent from './login/login.component';";

private static final String OAUTH2_AUTH_SERVICE_IMPORT =
"""
Expand Down Expand Up @@ -94,13 +91,9 @@ public class AngularOauth2ModuleFactory {
it('should display login component', () => {
expect(fixture.debugElement.query(By.directive(LoginComponent))).toBeTruthy();
});
""";
});""";

private static final String HTTP_AUTH_INTERCEPTOR_IMPORT =
"""
import { httpAuthInterceptor } from './app/auth/http-auth.interceptor';
""";
private static final String HTTP_AUTH_INTERCEPTOR_IMPORT = "import { httpAuthInterceptor } from './app/auth/http-auth.interceptor';";

private static final JHipsterSource SOURCE = from("client/angular/security/oauth2/src/main/webapp/app");

Expand Down Expand Up @@ -146,18 +139,18 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.and()
.in(path("src/main/webapp/main.ts"))
.add(EXISTING_PROVIDE_HTTP_CLIENT_NEEDLE, "provideHttpClient(withInterceptors([httpAuthInterceptor])),")
.add(fileStart(), HTTP_AUTH_INTERCEPTOR_IMPORT)
.add(lineAfterRegex("from '@angular/router';"), HTTP_AUTH_INTERCEPTOR_IMPORT)
.and()
.in(path("src/main/webapp/app/app.component.ts"))
.add(FILLED_STANDALONE_NEEDLE, "$1, LoginComponent]")
.add(fileStart(), OAUTH2_AUTH_SERVICE_IMPORT)
.add(fileStart(), LOGIN_IMPORT)
.add(lineAfterRegex("from '@angular/core';"), OAUTH2_AUTH_SERVICE_IMPORT)
.add(lineAfterRegex("from './auth/oauth2-auth.service';"), LOGIN_IMPORT)
.add(INJECT_NEEDLE, INJECT_IMPORT)
.add(APPNAME_NEEDLE, INJECT_OAUTH2_AUTH_SERVICE)
.add(lineAfterRegex("this.appName.set\\('" + properties.projectBaseName().name() + "'\\);"), INIT_AUTHENTICATION)
.and()
.in(path("src/main/webapp/app/app.component.spec.ts"))
.add(fileStart(), TEST_IMPORTS)
.add(lineAfterRegex("from '@angular/router';"), TEST_IMPORTS)
.add(TEST_NEEDLE, LOGIN_COMPONENT_TEST.indent(indentation.spacesCount() * 2))
.and()
.in(path("src/main/webapp/app/app.component.html"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { HttpClient, HttpRequest, provideHttpClient, withInterceptors } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';

import { httpAuthInterceptor } from './http-auth.interceptor';
import { Oauth2AuthService } from './oauth2-auth.service';
Expand Down Expand Up @@ -31,7 +31,6 @@ describe('httpAuthInterceptor', () => {
});

describe('Bearer Token', () => {
it('should add authorization bearer token in request when defined', () => {
jest.spyOn(oauth2AuthService, 'token', 'get').mockReturnValue(TOKEN);
const originalRequest = buildHttpRequest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
import { inject } from '@angular/core';
import { HttpRequest, HttpEvent, HttpHandlerFn } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Oauth2AuthService } from './oauth2-auth.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Oauth2AuthService } from './oauth2-auth.service';
import { TestBed } from '@angular/core/testing';
import Keycloak, { KeycloakInitOptions } from 'keycloak-js';
import { lastValueFrom } from 'rxjs';
import { Oauth2AuthService } from './oauth2-auth.service';
import SpyInstance = jest.SpyInstance;

jest.mock('keycloak-js', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentFixture, ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';

import { By } from '@angular/platform-browser';
import LoginComponent from './login.component';
import { Oauth2AuthService } from '../auth/oauth2-auth.service';
import LoginComponent from './login.component';

describe('LoginComponent', () => {
let fixture: ComponentFixture<LoginComponent>;
Expand All @@ -11,7 +11,7 @@ describe('LoginComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }]
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }],
}).compileComponents();
});

Expand Down

0 comments on commit 53a30f0

Please sign in to comment.