Skip to content

Commit

Permalink
NXP-32714: add signout butn & update utest
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshkumar1019 committed Jul 4, 2024
1 parent 3b5577a commit 0263180
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 118 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build

on:
pull_request:
branches:
- dev
workflow_call:
inputs:
branch:
description: 'The current branch'
default: dev
type: string
required: false
secrets:
NPM_PACKAGES_TOKEN:
description: 'NPM_PACKAGES_TOKEN'
required: true
GIT_TOKEN:
description: 'GIT_TOKEN'
required: true
env:
BRANCH_NAME: ${{ github.head_ref || inputs.branch || 'dev' }}
enabledebug: ${{ inputs.debug == true && '-vvv' || ''}}
NEXUS_URL: https://packages.nuxeo.com/repository/npm-public/
NEXUS_REPOSITORY: npm-public
NODE_AUTH_TOKEN: ${{ secrets.NPM_ADMIN_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN}}
NEW_VERSION: 2.0.0

jobs:
utest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: ${{ env.NEXUS_URL }}
scope: '@nuxeo'

- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '17'

- name: 'Update settings.xml with server configuration'
run: |
echo '<settings>
<servers>
<server>
<id>maven-internal</id>
<username>${{ secrets.PACKAGES_AUTH_USER }}</username>
<password>${{ secrets.PACKAGES_AUTH_TOKEN }}</password>
</server>
</servers>
</settings>' > ~/.m2/settings.xml
- name: Configure Additional Registries
working-directory: nuxeo-admin-console-web/angular-app
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GIT_TOKEN }}" >> .npmrc
- name: Install @angular/cli
run: npm install -g @angular/cli

- name: Install Dependencies
working-directory: nuxeo-admin-console-web/angular-app
run: npm install

- name: Build Angular Project
run: mvn package

- name: Publish to package.nuxeo.com
working-directory: nuxeo-admin-console-package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm publish --registry=https://packages.nuxeo.com/repository/npm-public/
63 changes: 25 additions & 38 deletions .github/workflows/utest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ on:
required: true
env:
BRANCH_NAME: ${{ github.head_ref || inputs.branch || 'dev' }}
enabledebug: ${{ inputs.debug == true && '-vvv' || ''}}
NEXUS_URL: https://packages.nuxeo.com/repository/npm-public/
NEXUS_REPOSITORY: npm-public
NODE_AUTH_TOKEN: ${{ secrets.NPM_ADMIN_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN}}
NEW_VERSION: 2.0.0

jobs:
utest:
Expand All @@ -35,48 +29,41 @@ jobs:
with:
ref: ${{ env.BRANCH_NAME }}

- name: Setup Node.js
uses: actions/setup-node@v4
- name: Remove .npmrc file if exists
run: |
if [ -f .npmrc ]; then
rm .npmrc
fi
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: ${{ env.NEXUS_URL }}
registry-url: 'https://packages.nuxeo.com/repository/npm-public/'
node-version: 20
scope: '@nuxeo'

- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '17'

- name: 'Update settings.xml with server configuration'
run: |
echo '<settings>
<servers>
<server>
<id>maven-internal</id>
<username>${{ secrets.PACKAGES_AUTH_USER }}</username>
<password>${{ secrets.PACKAGES_AUTH_TOKEN }}</password>
</server>
</servers>
</settings>' > ~/.m2/settings.xml

- name: Configure Additional Registries
working-directory: nuxeo-admin-console-web/angular-app
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GIT_TOKEN }}" >> .npmrc
npm config set @hylandsoftware:registry https://npm.pkg.github.com --global
npm config set //npm.pkg.github.com/:_authToken=${{ secrets.GIT_TOKEN }} --global
npm config set registry https://registry.npmjs.org/ --global
- name: Install @angular/cli
run: npm install -g @angular/cli


- name: Install Dependencies
working-directory: nuxeo-admin-console-web/angular-app
run: npm install

- name: Build Angular Project
run: mvn package

- name: Publish to package.nuxeo.com
working-directory: nuxeo-admin-console-package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install Chrome and Chromedriver
uses: browser-actions/setup-chrome@v1
with:
chrome-version: 120
install-chromedriver: true

- name: Verify Chrome installation
run: google-chrome --version

- name: Unit tests
working-directory: nuxeo-admin-console-web/angular-app
run: |
npm publish --registry=https://packages.nuxeo.com/repository/npm-public/
xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" npm test
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@ import { environment } from "../../../environments/environment";
import { UserInterface } from "../../shared/types/user.interface";
import { AuthUserResponseInterface } from "../types/authResponse.interface";
import { HylandSSORequestInterface } from "../types/hylandSSORequest.interface";
import {NuxeoJSClientService} from "../../shared/services/nuxeo-js-client.service";
import { NuxeoJSClientService } from "../../shared/services/nuxeo-js-client.service";

@Injectable({
providedIn: "root",
})
export class AuthService {
constructor(private http: HttpClient,private nuxeoJsClientService: NuxeoJSClientService) {}
constructor(private http: HttpClient, private nuxeoJsClientService: NuxeoJSClientService) { }


getCurrentUser(): Observable<UserInterface> {
const url = `${this.nuxeoJsClientService.getApiUrl()}` + "me";
const url = `${this.nuxeoJsClientService.getApiUrl()}me`;
return this.http.get<AuthUserResponseInterface>(url).pipe(
map(response => this.getUser(response))
);
}

getUser(response: AuthUserResponseInterface): UserInterface {
return {
id: response.id,
properties:{
properties: {
firstName: response.properties.firstName,
lastName: response.properties.lastName,
email: response.properties.email,
username: response.properties.username
}

};
}

Expand All @@ -41,7 +40,7 @@ export class AuthService {
.pipe(map(this.getUser));
}
signOut(): Observable<void> {
const url = `${this.nuxeoJsClientService.getBaseUrl()}`+ "logout";
const url = `${this.nuxeoJsClientService.getBaseUrl()}logout`;
return this.http.get<void>(url, {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,6 @@ export const getCurrentUserEffect = createEffect(
{ functional: true }
);

export const ssoEffect = createEffect(
(
actions$ = inject(Actions),
authService = inject(AuthService),
persistenceService = inject(PersistenceService)
) => {

return actions$.pipe(
ofType(authActions.sso),
switchMap(({ request }) => {
return authService.sso(request).pipe(
map((currentUser: UserInterface) => {
// persistenceService.set("accessToken", currentUser.token);
return authActions.ssoSuccess({ currentUser });
}),
catchError((errorResponse: HttpErrorResponse) => {
return of(
authActions.ssoFailure({
errors: errorResponse.error.errors,
})
);
})
);
})
);
},
{ functional: true }
);

export const redirectAfterSSOEffect = createEffect(
(actions$ = inject(Actions), router = inject(Router)) => {
return actions$.pipe(
ofType(authActions.ssoSuccess),
tap(() => {
router.navigateByUrl("/");
})
);
},
{ functional: true, dispatch: false }
);

export const signOutEffect = createEffect(
(
actions$ = inject(Actions),
Expand All @@ -96,5 +55,5 @@ export const signOutEffect = createEffect(
})
);
},
{ functional: true ,dispatch: false}
{ functional: true, dispatch: false }
);
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("WarningComponent", () => {
spyOn(component.dialogService, "closeAll");
component.onConfirm();
expect(persistenceServiceSetSpy).toHaveBeenCalledWith(
"doNotWarn",
"doNotWarn-Administrator",
"true"
);
expect(commonServiceLoadAppEmitSpy).toHaveBeenCalledWith(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- eslint-disable @angular-eslint/template/no-negated-async -->
<mat-toolbar class="header-bar">
<div class="header-bar__branding">
<button mat-icon-button aria-label="branding icon">
Expand All @@ -7,14 +6,12 @@
<span class="header-bar__branding__title">Admin Console</span>
</div>



<span class="header-bar__spacer"></span>
<span *ngIf="displayName" class="header-bar__branding__username">
{{ displayName}}
</span>
<button mat-stroked-button (click)="onSignOut()" aria-label="Logout">
<mat-icon>power_settings_new</mat-icon> Logout
<button mat-stroked-button (click)="onSignOut()" aria-label="Logout">
<mat-icon>power_settings_new</mat-icon> Logout
</button>

</mat-toolbar>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { authActions } from '../../auth/store/actions';
import { Observable, Subscription } from 'rxjs';
import { AuthStateInterface } from '../../auth/types/authState.interface';
import { UserInterface } from '../../shared/types/user.interface';
import {NuxeoJSClientService} from "../../shared/services/nuxeo-js-client.service";
import { NuxeoJSClientService } from "../../shared/services/nuxeo-js-client.service";
@Component({
selector: 'header-bar',
templateUrl: './header-bar.component.html',
styleUrls: ['./header-bar.component.scss'],
selector: "header-bar",
templateUrl: "./header-bar.component.html",
styleUrls: ["./header-bar.component.scss"],
})
export class HeaderBarComponent implements OnInit, OnDestroy {
currentUser$: Observable<UserInterface | null | undefined>;
Expand Down Expand Up @@ -38,7 +38,7 @@ export class HeaderBarComponent implements OnInit, OnDestroy {

private redirectToHome(): void {
const _baseURL = this.nuxeoJsClientService.getBaseUrl();
window.location.href = _baseURL + 'login.jsp';
window.location.href = `${_baseURL}login.jsp?requestedUrl=nuxeoadmin`;
}

private setDisplayName(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ describe("PersistenceService", () => {
);
});
it("should set key-value pair in localstorage successfully, if there is no error", () => {
service.set("doNotWarn", "true");
expect(localStorage.getItem("doNotWarn")).toBe('"true"');
service.set("doNotWarn-Administrator", "true");
expect(localStorage.getItem("doNotWarn-Administrator")).toBe('"true"');
});

it("should not set key-value pair in localstorage, if there is error", () => {
spyOn(service, "set").and.callFake(() => {
throw new Error("");
});
expect(localStorage.getItem("doNotWarn")).toBe(null);
expect(localStorage.getItem("doNotWarn-Administrator")).toBe(null);
});

it("should not return value if getting key-value pair from localstorage thorws an error", () => {
localStorage.removeItem("doNotWarn");
expect(service.get("doNotWarn")).toBe(null);
localStorage.removeItem("doNotWarn-Administrator");
expect(service.get("doNotWarn-Administrator")).toBe(null);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// export interface UserInterface {
// // demo model need to be replaced
// email: string;
// token: string;
// username: string;
// usertype: string;
// bio: string | null;
// image: string | null;
// }
export interface UserInterface {
id:string,
properties:{
firstName:string,
lastName:string,
id: string,
properties: {
firstName: string,
lastName: string,
email: string;
username: string;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const environment = {
// todo: This is the only difference between the development and production environments
// demo url: https://api.realworld.io/api
apiUrl: "/nuxeo",
apiUrl: "assets",
production: true,
};

0 comments on commit 0263180

Please sign in to comment.