Skip to content

Commit

Permalink
Merge pull request #1 from jdwillmsen/develop
Browse files Browse the repository at this point in the history
CI workflow adjustments
  • Loading branch information
jdwillmsen authored Nov 18, 2023
2 parents ed9b56d + eddc4de commit e8489d4
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 22 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ on:
- main
pull_request:

permissions:
actions: read
contents: read

env:
NX_CLOUD_DISTRIBUTED_EXECUTION: true # this enables DTE
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 3 # expected number of agents
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 4 # expected number of agents
NX_BRANCH: ${{ github.event.number || github.ref_name }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # this is needed if our pipeline publishes to npm
Expand Down Expand Up @@ -60,7 +64,9 @@ jobs:
NX_CLOUD_DISTRIBUTED_EXECUTION=false npx nx-cloud record -- npx nx format:check & pids+=($!)
# list of commands to be run on agents
npx nx affected -t lint,test,component-test,build --parallel=3 &
npx nx affected -t lint,test --parallel=4 &
npx nx affected -t component-test --parallel=1 &
npx nx affected -t build --parallel=4 &
pids+=($!)
# run all commands in parallel and bail if one of them fails
Expand All @@ -78,7 +84,7 @@ jobs:
strategy:
matrix:
# Add more agents here as your repository expands
agent: [1, 2, 3]
agent: [1, 2, 3, 4]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { Environment } from '@usersrole-nx/core';

describe('RolesService', () => {
let rolesService: RolesService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const httpClientMock: jest.Mocked<any> = {
patch: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarServiceMock: jest.Mocked<any> = {
error: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class SignInComponent {
.subscribe((response) => response);
}

private handleError(error: any) {
private handleError(error: { message: string }) {
this.snackbarService.error(error.message, { variant: 'filled' }, true);
return EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ describe('roleGuard', () => {
component: TestSignInComponent,
},
];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const angularFireAuthMock: jest.Mocked<any> = {
user: of(null),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const usersServiceMock: jest.Mocked<any> = {
users$: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackBarServiceMock: jest.Mocked<any> = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const permissionServiceMock: jest.Mocked<any> = {
canActivateRole: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HttpRequest } from '@angular/common/http';

describe('AuthTokenInterceptor', () => {
let interceptor: AuthTokenInterceptor;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let angularFireAuthMock: jest.Mocked<any> = {
idToken: new BehaviorSubject<string | null>('mocked-id-token'),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('GlobalHttpErrorHandlerInterceptor', () => {

it('should still send failure after retries', (done) => {
const request = new HttpRequest('GET', 'http://mock');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const httpHandlerMock: jest.Mocked<any> = {
handle: () => throwError(() => new HttpErrorResponse({ status: 500 })),
};
Expand All @@ -49,6 +50,7 @@ describe('GlobalHttpErrorHandlerInterceptor', () => {

it('should catch the error if 403 and handle', (done) => {
const request = new HttpRequest('GET', 'http://mock');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const httpHandlerMock: jest.Mocked<any> = {
handle: () => throwError(() => new HttpErrorResponse({ status: 403 })),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ import { AuthenticationService } from './authentication.service';
import { of } from 'rxjs';
import { GithubAuthProvider, GoogleAuthProvider } from 'firebase/auth';
import * as errorHandlerModule from '../error-handler/error-handler.service';
import firebase from 'firebase/compat';
import AuthCredential = firebase.auth.AuthCredential;

describe('AuthenticationService', () => {
let authService: AuthenticationService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const angularFireAuthMock: jest.Mocked<any> = {
authState: of(null),
signInWithEmailAndPassword: jest.fn(),
signInWithPopup: jest.fn(),
signOut: jest.fn(),
fetchSignInMethodsForEmail: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const routerMock: jest.Mocked<any> = {
navigate: jest.fn(() => Promise.resolve(true)),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarServiceMock: jest.Mocked<any> = {
success: jest.fn(),
error: jest.fn(),
Expand Down Expand Up @@ -280,7 +285,7 @@ describe('AuthenticationService', () => {
it('should handle login failure when error code account exists with different credentials', () => {
const error = {
email: '[email protected]',
credential: true,
credential: {} as AuthCredential,
code: 'auth/account-exists-with-different-credential',
};
const handleErrorSpy = jest.spyOn(errorHandlerModule, 'handleError');
Expand All @@ -300,7 +305,8 @@ describe('AuthenticationService', () => {
});

it('should handle error when unknown conditions', () => {
const error = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const error = {} as any;
const handleErrorSpy = jest.spyOn(errorHandlerModule, 'handleError');

authService.handleAuthLoginFailure(error);
Expand All @@ -314,7 +320,7 @@ describe('AuthenticationService', () => {
it('should handle error when linking credentials fails', () => {
const error = {
email: '[email protected]',
credential: true,
credential: {} as AuthCredential,
code: 'auth/account-exists-with-different-credential',
};
jest.spyOn(errorHandlerModule, 'handleError');
Expand All @@ -340,7 +346,7 @@ describe('AuthenticationService', () => {
it('should handle error when sign in with popup fails', () => {
const error = {
email: '[email protected]',
credential: true,
credential: {} as AuthCredential,
code: 'auth/account-exists-with-different-credential',
};
jest.spyOn(errorHandlerModule, 'handleError');
Expand All @@ -362,7 +368,7 @@ describe('AuthenticationService', () => {
it('should handle error when fetch sign in methods for email fails', () => {
const error = {
email: '[email protected]',
credential: true,
credential: {} as AuthCredential,
code: 'auth/account-exists-with-different-credential',
};
jest.spyOn(errorHandlerModule, 'handleError');
Expand All @@ -380,7 +386,7 @@ describe('AuthenticationService', () => {
it('should handle error when first popup provider method is not supported', () => {
const error = {
email: '[email protected]',
credential: true,
credential: {} as AuthCredential,
code: 'auth/account-exists-with-different-credential',
};
jest.spyOn(errorHandlerModule, 'handleError');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ export class AuthenticationService {
.signInWithEmailAndPassword(email, password)
.then(() => {
this.router.navigate(['home']).then(() => {
this.snackbarService.success(SUCCESS_SIGN_IN_MESSAGE, {
variant: 'filled',
autoClose: true,
});
this.snackbarService.success(
SUCCESS_SIGN_IN_MESSAGE,
{
variant: 'filled',
autoClose: true,
},
true,
);
});
})
.catch((error) => {
Expand Down Expand Up @@ -120,7 +124,11 @@ export class AuthenticationService {
}
}

handleAuthLoginFailure(error: any): void {
handleAuthLoginFailure(error: {
email: string;
credential: firebase.auth.AuthCredential;
code: string;
}): void {
if (
error.email &&
error.credential &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('ErrorHandlerService', () => {
let service: ErrorHandlerService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarServiceMock: jest.Mocked<any> = {
error: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ngZoneMock: jest.Mocked<any> = {
run: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ interface AngularFireError extends Error {
rejection: FirebaseError;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function errorIsAngularFireError(err: any): err is AngularFireError {
return err.rejection && err.rejection.name === 'FirebaseError';
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const handleError = (error: any, snackbarService: SnackbarService) => {
let errorMessage = DEFAULT_ERROR_MESSAGE;
if (typeof error.error === 'object' && error.error.message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FirestoreService } from './firestore.service';

describe('FirestoreService', () => {
let firestoreService: FirestoreService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const firestoreMock: jest.Mocked<any> = {};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { PermissionService } from './permission.service';

describe('PermissionService', () => {
let permissionsService: PermissionService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let angularFireAuthMock: jest.Mocked<any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const routerMock: jest.Mocked<any> = {
navigate: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const usersServiceMock: jest.Mocked<any> = {
user$: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarServiceMock: jest.Mocked<any> = {
error: jest.fn(),
};
Expand All @@ -36,11 +40,10 @@ describe('PermissionService', () => {
const roles: Role[] = ['read', 'user'];
const next: ActivatedRouteSnapshot = {
data: { roles },
} as any;
} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
const userDetails = { roles };
usersServiceMock.user$.mockReturnValue(of(userDetails));

permissionsService.canActivateRole(next).subscribe((result: any) => {
permissionsService.canActivateRole(next).subscribe((result) => {
expect(result).toBeFalsy();
expect(routerMock.navigate).not.toHaveBeenCalled();
done();
Expand All @@ -51,11 +54,12 @@ describe('PermissionService', () => {
const roles: Role[] = ['admin', 'user'];
const next: ActivatedRouteSnapshot = {
data: { roles },
} as any;
} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
const userDetails = { roles: ['admin', 'user'] };
angularFireAuthMock.user = of({ uid: 'testUser' });
usersServiceMock.user$.mockReturnValue(of(userDetails));

// eslint-disable-next-line @typescript-eslint/no-explicit-any
permissionsService.canActivateRole(next).subscribe((result: any) => {
expect(result).toBeTruthy();
expect(routerMock.navigate).not.toHaveBeenCalled();
Expand All @@ -67,11 +71,12 @@ describe('PermissionService', () => {
const roles: Role[] = ['admin', 'manager'];
const next: ActivatedRouteSnapshot = {
data: { roles },
} as any;
} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
const userDetails = { roles: ['users'] };
angularFireAuthMock.user = of({ uid: 'testUser' });
usersServiceMock.user$.mockReturnValue(of(userDetails));

// eslint-disable-next-line @typescript-eslint/no-explicit-any
permissionsService.canActivateRole(next).subscribe((result: any) => {
expect(result).toBeFalsy();
expect(routerMock.navigate).toHaveBeenCalledWith(['/forbidden']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

describe('SnackbarService', () => {
let service: SnackbarService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarMock: jest.Mocked<any> = {
openFromComponent: jest.fn(),
dismiss: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { Environment } from '../../environment.token';

describe('UsersService', () => {
let usersService: UsersService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const httpClientMock: jest.Mocked<any> = {
get: jest.fn(),
post: jest.fn(),
patch: jest.fn(),
delete: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snackbarServiceMock: jest.Mocked<any> = {
error: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class UsersService {
.pipe(catchError((error) => this.handleError(error)));
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleError(error: any) {
return handleError(error, this.snackbarService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ThemeSelectorComponent {
});
}
},
error: (error: { error: any }) =>
error: (error) =>
this.snackbarService.error(error.error, { variant: 'filled' }, true),
});
this.styleManagerService.currentThemeName.subscribe((themeName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Role } from '@usersrole-nx/shared';

describe('NavigationService', () => {
let navigationService: NavigationService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const permissionServiceMock: jest.Mocked<any> = {
hasRole: jest.fn(),
};
Expand Down
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"affected": {
"defaultBase": "master"
"defaultBase": "main"
},
"targetDefaults": {
"build": {
Expand Down Expand Up @@ -66,5 +66,6 @@
"style": "scss"
}
},
"parallel": 6,
"nxCloudAccessToken": "MTUxMDVjNWQtNDFhYy00NzNhLTk3MWEtNWU2NWQ4MDM4NWE4fHJlYWQtd3JpdGU="
}

0 comments on commit e8489d4

Please sign in to comment.