Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix failing tests across the app #3417

Open
wants to merge 33 commits into
base: FYLE-86cx2t82k-base-feature-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { BackButtonActionPriority } from './core/models/back-button-action-prior
import { BackButtonService } from './core/services/back-button.service';
import { TextZoom } from '@capacitor/text-zoom';
import { GmapsService } from './core/services/gmaps.service';
import { SpenderOnboardingService } from './core/services/spender-onboarding.service';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -68,7 +69,8 @@ export class AppComponent implements OnInit {
private loginInfoService: LoginInfoService,
private navController: NavController,
private backButtonService: BackButtonService,
private gmapsService: GmapsService
private gmapsService: GmapsService,
private spenderOnboardingService: SpenderOnboardingService
) {
this.initializeApp();
this.registerBackButtonAction();
Expand Down Expand Up @@ -192,6 +194,14 @@ export class AppComponent implements OnInit {
}, 500);
});

this.spenderOnboardingService.setOnboardingStatusAsComplete().subscribe(() => {
if (this.isOnline) {
this.sidemenuRef.showSideMenuOnline();
} else {
this.sidemenuRef.showSideMenuOffline();
}
});

Comment on lines +197 to +204
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Watch out! Memory leak alert!

The subscription to onboarding status needs cleanup. Implement OnDestroy and unsubscribe to prevent memory leaks.

+  private onboardingStatusSubscription: Subscription;

   ngOnInit(): void {
-    this.spenderOnboardingService.setOnboardingStatusAsComplete().subscribe(() => {
+    this.onboardingStatusSubscription = this.spenderOnboardingService.setOnboardingStatusAsComplete().subscribe(() => {
       if (this.isOnline) {
         this.sidemenuRef.showSideMenuOnline();
       } else {
         this.sidemenuRef.showSideMenuOffline();
       }
     });
   }

+  ngOnDestroy(): void {
+    if (this.onboardingStatusSubscription) {
+      this.onboardingStatusSubscription.unsubscribe();
+    }
+  }

Committable suggestion skipped: line range outside the PR's diff.

this.userEventService.onLogout(() => {
this.trackingService.onSignOut();
this.freshChatService.destroy();
Expand Down
31 changes: 27 additions & 4 deletions src/app/auth/switch-org/switch-org.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('SwitchOrgPage', () => {
const deepLinkServiceSpy = jasmine.createSpyObj('DeepLinkService', ['getExpenseRoute']);
const ldSpy = jasmine.createSpyObj('LaunchDarklyService', ['initializeUser']);
const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']);
const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingSettings', ['getOnboardingSettings']);
const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingService', ['getOnboardingStatus']);

TestBed.configureTestingModule({
declarations: [SwitchOrgPage, ActiveOrgCardComponent, OrgCardComponent, FyZeroStateComponent],
Expand Down Expand Up @@ -280,7 +280,10 @@ describe('SwitchOrgPage', () => {
component.searchOrgsInput = fixture.debugElement.query(By.css('.smartlook-show'));
component.contentRef = fixture.debugElement.query(By.css('.switch-org__content-container__content-block'));
fixture.detectChanges();
spyOn(component, 'navigateToDashboard').and.callThrough();
spenderOnboardingService.getOnboardingStatus.and.returnValue(
of({ ...onboardingStatusData, state: OnboardingState.COMPLETED })
);
orgSettingsService.get.and.returnValue(of(orgSettingsData));
}));

it('should create', () => {
Expand Down Expand Up @@ -568,6 +571,16 @@ describe('SwitchOrgPage', () => {
}));
});

it('navigateToDashboard(): should navigate to spender onboarding when onboarding status is not complete', fakeAsync(() => {
spenderOnboardingService.getOnboardingStatus.and.returnValue(
of({ ...onboardingStatusData, state: OnboardingState.YET_TO_START })
);
orgSettingsService.get.and.returnValue(of(orgSettingsData));
component.navigateToDashboard();
tick();
expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'spender_onboarding']);
}));
Comment on lines +574 to +582
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Your test case is like a perfect entry scene, but we need more action!

Consider adding test cases for:

  • Navigation when different card settings are enabled/disabled
  • Navigation with different combinations of onboarding states
  • Error handling during navigation


describe('navigateToSetupPage():', () => {
it('should navigate to setup page if org the roles has OWNER', () => {
component.navigateToSetupPage(['OWNER']);
Expand All @@ -592,7 +605,12 @@ describe('SwitchOrgPage', () => {
.pipe(
finalize(() => {
expect(loaderService.hideLoader).toHaveBeenCalledTimes(1);
expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_dashboard']);
expect(router.navigate).toHaveBeenCalledOnceWith([
'/',
'enterprise',
'my_dashboard',
{ openSMSOptInDialog: undefined },
]);
})
)
.subscribe((res) => {
Expand Down Expand Up @@ -675,7 +693,12 @@ describe('SwitchOrgPage', () => {
tick();
component.navigateBasedOnUserStatus(config).subscribe((res) => {
expect(res).toBeNull();
expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_dashboard']);
expect(router.navigate).toHaveBeenCalledOnceWith([
'/',
'enterprise',
'my_dashboard',
{ openSMSOptInDialog: undefined },
]);
});
}));

Expand Down
3 changes: 2 additions & 1 deletion src/app/auth/switch-org/switch-org.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ export class SwitchOrgPage implements OnInit, AfterViewChecked {
forkJoin([this.orgSettingsService.get(), this.spenderOnboardingService.getOnboardingStatus()]).subscribe(
([orgSettings, onboardingStatus]) => {
if (
(orgSettings.visa_enrollment_settings.enabled ||
(orgSettings.corporate_credit_card_settings.enabled ||
orgSettings.visa_enrollment_settings.enabled ||
orgSettings.mastercard_enrollment_settings.enabled ||
orgSettings.amex_feed_enrollment_settings.enabled) &&
onboardingStatus.state !== OnboardingState.COMPLETED
Comment on lines +324 to 328
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Your navigation logic is like a perfectly choreographed fight scene!

The conditions for card settings are well-structured:

(orgSettings.corporate_credit_card_settings.enabled ||
  orgSettings.visa_enrollment_settings.enabled ||
  orgSettings.mastercard_enrollment_settings.enabled ||
  orgSettings.amex_feed_enrollment_settings.enabled)

However, consider extracting this into a helper method for better readability:

private isCardEnrollmentEnabled(orgSettings: OrgSettings): boolean {
  return (
    orgSettings.corporate_credit_card_settings.enabled ||
    orgSettings.visa_enrollment_settings.enabled ||
    orgSettings.mastercard_enrollment_settings.enabled ||
    orgSettings.amex_feed_enrollment_settings.enabled
  );
}

Expand Down
14 changes: 13 additions & 1 deletion src/app/core/services/spender-onboarding.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { BehaviorSubject, map, Observable } from 'rxjs';
import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service';
import { PlatformApiResponse } from '../models/platform/platform-api-response.model';
import { OnboardingWelcomeStepStatus } from '../models/onboarding-welcome-step-status.model';
Expand All @@ -10,6 +10,8 @@
providedIn: 'root',
})
export class SpenderOnboardingService {
onboardingComplete$: BehaviorSubject<boolean> = new BehaviorSubject(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Mind it! Initialize onboardingComplete$ to false by default!

Starting with true state could mislead subscribers about completion status. Let the actual completion event drive the state to true.

-  onboardingComplete$: BehaviorSubject<boolean> = new BehaviorSubject(true);
+  onboardingComplete$: BehaviorSubject<boolean> = new BehaviorSubject(false);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onboardingComplete$: BehaviorSubject<boolean> = new BehaviorSubject(true);
onboardingComplete$: BehaviorSubject<boolean> = new BehaviorSubject(false);


constructor(private spenderPlatformV1ApiService: SpenderPlatformV1ApiService) {}

getOnboardingStatus(): Observable<OnboardingStatus> {
Expand Down Expand Up @@ -78,4 +80,14 @@
};
return this.processSmsOptInStep(data);
}

setOnboardingStatusAsComplete(): Observable<boolean> {
return this.onboardingComplete$.asObservable();
}
Comment on lines +84 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Macha, rename method to reflect its true purpose!

The method name suggests it sets the status but it only returns an observable. Let's make it crystal clear!

-  setOnboardingStatusAsComplete(): Observable<boolean> {
+  getOnboardingStatusComplete$(): Observable<boolean> {
     return this.onboardingComplete$.asObservable();
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setOnboardingStatusAsComplete(): Observable<boolean> {
return this.onboardingComplete$.asObservable();
}
getOnboardingStatusComplete$(): Observable<boolean> {
return this.onboardingComplete$.asObservable();
}


// Emit a new event
setOnboardingStatusEvent(): void {
this.onboardingComplete$.next(true);
console.log('event set');

Check failure on line 91 in src/app/core/services/spender-onboarding.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement

Check failure on line 91 in src/app/core/services/spender-onboarding.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement

Check failure on line 91 in src/app/core/services/spender-onboarding.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement
}
Comment on lines +88 to +92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Style-ah! Remove that console.log statement!

Production code should use proper logging service, not console.log statements.

   setOnboardingStatusEvent(): void {
     this.onboardingComplete$.next(true);
-    console.log('event set');
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Emit a new event
setOnboardingStatusEvent(): void {
this.onboardingComplete$.next(true);
console.log('event set');
}
// Emit a new event
setOnboardingStatusEvent(): void {
this.onboardingComplete$.next(true);
}
🧰 Tools
🪛 eslint

[error] 91-91: Unexpected console statement.

(no-console)

🪛 GitHub Check: Run linters

[failure] 91-91:
Unexpected console statement

🪛 GitHub Actions: Lint

[error] 91-91: Unexpected console statement - ESLint rule 'no-console' violation

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
<input
class="smartlook-show connect-card__card-number-input pl-0"
inputmode="numeric"
mask="0000 0000 0000 0000"
mask="0000 0000 0000"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Listen here, partner! This mask situation is no small matter!

The mask 0000 0000 0000 (12 digits) won't cut it for our card numbers! Both Visa and Mastercard need 16 digits to work their magic, as shown in the test case using '4111111111111111'. This mask change would leave users hanging with 4 digits short!

• Change the mask back to 0000 0000 0000 0000 to handle 16-digit card numbers properly

🔗 Analysis chain

Hold on! This card mask needs a double take!

The mask has been reduced from 16 to 12 digits, which might not accommodate all valid card numbers.

Please verify if all supported card types (Visa, Mastercard) can be properly entered with the 12-digit mask.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for card number validation logic
rg -A 5 "card.*number.*valid" src/

Length of output: 18158

placeholder="xxxx xxxx xxxx"
data-testid="card-number-input"
formControlName="card_number_{{ card.id }}"
required
(input)="onCardNumberUpdate(card)"
[readonly]="cardValuesMap[card.id].enrollment_success"
/>

<div class="connect-card__card-last-four">
Expand Down
Loading
Loading