Skip to content

Commit

Permalink
Merge branch 'master' into form-value-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DhaaraniCIT authored Oct 10, 2024
2 parents bb9606f + be243d3 commit 66700b9
Show file tree
Hide file tree
Showing 33 changed files with 3,684 additions and 144 deletions.
8 changes: 4 additions & 4 deletions src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export class LoginComponent implements OnInit {
private userService: UserService
) { }

private redirect(redirectUri: string | undefined): void {
private redirect(redirectUri: string | undefined, code:string): void {
if (redirectUri) {
this.router.navigate([redirectUri]);
brandingConfig.brandId === 'co' ? this.router.navigate([redirectUri], { queryParams: { code: code } }) : this.router.navigate([redirectUri]);
} else {
this.router.navigate(['/integrations']);
}
Expand Down Expand Up @@ -106,9 +106,9 @@ export class LoginComponent implements OnInit {
this.helperService.setBaseApiURL(AppUrl.XERO);
this.xeroAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
}
this.redirect(redirectUri);
this.redirect(redirectUri, code);
} else {
this.redirect(redirectUri);
this.redirect(redirectUri, code);
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/common/export-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ExportLogService {
private workspaceService: WorkspaceService
) { }

getSkippedExpenses(limit: number, offset: number, selectedDateFilter: SelectedDateFilter | null, query: string | null, appName?:string): Observable<SkipExportLogResponse> {
getSkippedExpenses(limit: number, offset: number, selectedDateFilter?: SelectedDateFilter | null, query?: string | null, appName?:string): Observable<SkipExportLogResponse> {
const workspaceId = this.workspaceService.getWorkspaceId();
const params: SkipExportParam = {
limit,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class ExportLogService {

}

getExpenseGroups(state: TaskLogState, limit: number, offset: number, selectedDateFilter: SelectedDateFilter | null, exportedAt?: string | null, query?: string | null, appName?: string): Observable<ExpenseGroupResponse> {
getExpenseGroups(state: TaskLogState, limit: number, offset: number, selectedDateFilter?: SelectedDateFilter | null, exportedAt?: string | null, query?: string | null, appName?: string): Observable<ExpenseGroupResponse> {
const params: ExpenseGroupParam = {
limit,
offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export class BusinessCentralCompleteExportLogComponent implements OnInit {

pageSizeChanges(limit: number): void {
this.isLoading = true;
this.limit = limit;
this.currentPage = 1;
this.getAccountingExports(limit, this.offset);
this.limit = limit;
}

pageChanges(offset: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export class BusinessCentralSkippedExportLogComponent implements OnInit {

pageSizeChanges(limit: number): void {
this.isLoading = true;
this.limit = limit;
this.currentPage = 1;
this.getSkippedExpenses(limit, this.offset);
this.limit = limit;
}

pageChanges(offset: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SiExportSettingService } from 'src/app/core/services/si/si-configuratio
import { MinimalUser } from 'src/app/core/models/db/user.model';
import { of } from 'rxjs';
import { AccountingExportSummary, AccountingExportSummaryModel } from 'src/app/core/models/db/accounting-export-summary.model';
import { mockAccountingExportSummary, mockCompletedTasksWithFailures, mockConfiguration, mockErrors, mockExportableAccountingExportIds, mockExportSettingGet, mockExportSettings, mockTasksInProgress } from '../../intacct.fixture';
import { mockAccountingExportSummary, mockCompletedTasksWithFailures, mockConfiguration, mockErrors, mockExportableAccountingExportIds, mockExportSettingGet, mockTasksInProgress } from '../../intacct.fixture';
import { SharedModule } from 'src/app/shared/shared.module';
import { Error } from 'src/app/core/models/db/error.model';
import { AccountingErrorType, AppName, CCCImportState, IntacctCategoryDestination, ReimbursableImportState, TaskLogState } from 'src/app/core/models/enum/enum.model';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,143 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { of } from 'rxjs';
import { IntacctCompletedExportLogComponent } from './intacct-completed-export-log.component';
import { TrackingService } from 'src/app/core/services/integration/tracking.service';
import { ExportLogService } from 'src/app/core/services/common/export-log.service';
import { PaginatorService } from 'src/app/core/services/common/paginator.service';
import { UserService } from 'src/app/core/services/misc/user.service';
import { mockExpenseGroupResponse, mockPaginator } from '../../../intacct.fixture';
import { PaginatorPage, TaskLogState } from 'src/app/core/models/enum/enum.model';
import { MinimalUser } from 'src/app/core/models/db/user.model';
import { SharedModule } from 'src/app/shared/shared.module';

xdescribe('IntacctCompletedExportLogComponent', () => {
describe('IntacctCompletedExportLogComponent', () => {
let component: IntacctCompletedExportLogComponent;
let fixture: ComponentFixture<IntacctCompletedExportLogComponent>;
let exportLogService: jasmine.SpyObj<ExportLogService>;
let trackingService: jasmine.SpyObj<TrackingService>;
let paginatorService: jasmine.SpyObj<PaginatorService>;
let userService: jasmine.SpyObj<UserService>;

beforeEach(async () => {
const exportLogServiceSpy = jasmine.createSpyObj('ExportLogService', ['getExpenseGroups']);
const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['onDateFilter']);
const paginatorServiceSpy = jasmine.createSpyObj('PaginatorService', ['getPageSize', 'storePageSize']);
const userServiceSpy = jasmine.createSpyObj('UserService', ['getUserProfile']);

await TestBed.configureTestingModule({
declarations: [ IntacctCompletedExportLogComponent ]
})
.compileComponents();
declarations: [ IntacctCompletedExportLogComponent ],
imports: [ ReactiveFormsModule, SharedModule ],
providers: [
FormBuilder,
{ provide: ExportLogService, useValue: exportLogServiceSpy },
{ provide: TrackingService, useValue: trackingServiceSpy },
{ provide: PaginatorService, useValue: paginatorServiceSpy },
{ provide: UserService, useValue: userServiceSpy }
]
}).compileComponents();

exportLogService = TestBed.inject(ExportLogService) as jasmine.SpyObj<ExportLogService>;
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
paginatorService = TestBed.inject(PaginatorService) as jasmine.SpyObj<PaginatorService>;
userService = TestBed.inject(UserService) as jasmine.SpyObj<UserService>;

userService.getUserProfile.and.returnValue({ org_id: 'ORG123' } as MinimalUser);
paginatorService.getPageSize.and.returnValue(mockPaginator);
exportLogService.getExpenseGroups.and.returnValue(of(mockExpenseGroupResponse));

fixture = TestBed.createComponent(IntacctCompletedExportLogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});


it('should create', () => {
expect(component).toBeTruthy();
});
});

it('should initialize component and load data', () => {
component.ngOnInit();
expect(component.limit).toBe(mockPaginator.limit);
expect(component.offset).toBe(mockPaginator.offset);
expect(component.isLoading).toBeFalse();
expect(component.totalCount).toBe(mockExpenseGroupResponse.count);
expect(component.filteredAccountingExports.length).toBe(mockExpenseGroupResponse.results.length);
expect(component.filteredAccountingExports).toEqual(component.accountingExports);
});

it('should handle page size changes', () => {
const newLimit = 20;
component.pageSizeChanges(newLimit);
expect(component.limit).toBe(newLimit);
expect(component.currentPage).toBe(1);
expect(paginatorService.storePageSize).toHaveBeenCalledWith(PaginatorPage.EXPORT_LOG, newLimit);
expect(exportLogService.getExpenseGroups).toHaveBeenCalled();
});

it('should handle page changes', () => {
fixture.detectChanges();
component.pageChanges(10);
expect(component.offset).toBe(10);
expect(component.currentPage).toBe(2);
expect(exportLogService.getExpenseGroups).toHaveBeenCalled();
});

it('should handle simple search', fakeAsync(() => {
const searchQuery = 'test query';
fixture.detectChanges();
component.handleSimpleSearch(searchQuery);
tick(1000);
expect(component.searchQuery).toBe(searchQuery);
expect(component.offset).toBe(0);
expect(component.currentPage).toBe(1);
expect(exportLogService.getExpenseGroups).toHaveBeenCalled();
}));

it('should open expense in Fyle', () => {
const expenseId = 'exp123';
spyOn(window, 'open');
component.openExpenseinFyle(expenseId);
expect(window.open).toHaveBeenCalledWith(jasmine.stringContaining(expenseId), '_blank');
});

it('should handle date filter changes', fakeAsync(() => {
component.ngOnInit();
const dateRange = [new Date('2023-01-01'), new Date('2023-01-31')];
component.exportLogForm.controls.start.setValue(dateRange);
tick(10);
expect(component.selectedDateFilter).toEqual({
startDate: dateRange[0],
endDate: dateRange[1]
});
expect(component.isDateSelected).toBeTrue();
expect(exportLogService.getExpenseGroups).toHaveBeenCalled();
expect(component.hideCalendar).toBeFalse();
}));

it('should clear date filter when null is set', fakeAsync(() => {
fixture.detectChanges();
component.exportLogForm.controls.start.setValue(null);
tick(10);
expect(component.selectedDateFilter).toBeNull();
expect(component.isDateSelected).toBeFalse();
expect(exportLogService.getExpenseGroups).toHaveBeenCalled();
}));

it('should call getExpenseGroups with correct parameters', () => {
component.ngOnInit();
expect(exportLogService.getExpenseGroups).toHaveBeenCalledWith(
TaskLogState.COMPLETE,
mockPaginator.limit,
mockPaginator.offset,
undefined,
null,
undefined
);
});

it('should track date filter', () => {
const dateFilter = { startDate: new Date('2023-01-01'), endDate: new Date('2023-01-31') };
(component as any).trackDateFilter('custom', dateFilter);
expect(trackingService.onDateFilter).toHaveBeenCalledWith(jasmine.any(String), jasmine.objectContaining(dateFilter));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class IntacctCompletedExportLogComponent implements OnInit {

dateOptions: DateFilter[] = AccountingExportModel.getDateOptionsV2();

selectedDateFilter: SelectedDateFilter | null;
selectedDateFilter?: SelectedDateFilter | null;

exportLogForm: FormGroup;

Expand Down Expand Up @@ -96,10 +96,10 @@ export class IntacctCompletedExportLogComponent implements OnInit {

pageSizeChanges(limit: number): void {
this.isLoading = true;
this.limit = limit;
this.currentPage = 1;
this.selectedDateFilter = this.selectedDateFilter ? this.selectedDateFilter : null;
this.getAccountingExports(limit, this.offset);
this.limit = limit;
}

pageChanges(offset: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IntacctExportLogComponent } from './intacct-export-log.component';
import { FormBuilder } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideRouter, Router } from '@angular/router';

xdescribe('IntacctExportLogComponent', () => {
describe('IntacctExportLogComponent', () => {
let component: IntacctExportLogComponent;
let fixture: ComponentFixture<IntacctExportLogComponent>;
let router: Router;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [ IntacctExportLogComponent ],
providers: [ FormBuilder ]
providers: [ FormBuilder, provideRouter([]) ]
})
.compileComponents();

router = TestBed.inject(Router);
spyOn(router, 'navigateByUrl');

fixture = TestBed.createComponent(IntacctExportLogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand All @@ -24,4 +29,9 @@ xdescribe('IntacctExportLogComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should navigate to completed export log', () => {
expect(component.activeModule).toEqual(component.modules[0]);
expect(router.navigateByUrl).toHaveBeenCalledOnceWith('/integrations/intacct/main/export_log/complete');
});
});
Loading

0 comments on commit 66700b9

Please sign in to comment.