Skip to content

Commit

Permalink
test: fixing tests - part 3 (#2941)
Browse files Browse the repository at this point in the history
* test: fixing tests - part 3

* test: fixing tests - part 4 (#2943)

* test: fixing tests - part 4

* test: fixing tests - part 5 (#2945)

* minor
  • Loading branch information
suyashpatil78 authored May 4, 2024
1 parent fdaf3b6 commit 3f70654
Show file tree
Hide file tree
Showing 29 changed files with 369 additions and 310 deletions.
194 changes: 89 additions & 105 deletions src/app/core/mock-data/split-expense-form.data.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,97 @@
import deepFreeze from 'deep-freeze-strict';

import { FormControl, FormGroup } from '@angular/forms';

export const splitExpenseFormData1 = deepFreeze(
new FormGroup({
amount: new FormControl(120),
currency: new FormControl('INR'),
percentage: new FormControl(60),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData1 = new FormGroup({
amount: new FormControl(120),
currency: new FormControl('INR'),
percentage: new FormControl(60),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData2 = deepFreeze(
new FormGroup({
amount: new FormControl(),
currency: new FormControl('INR'),
percentage: new FormControl(60),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData2 = new FormGroup({
amount: new FormControl(),
currency: new FormControl('INR'),
percentage: new FormControl(60),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData3 = deepFreeze(
new FormGroup({
amount: new FormControl(120),
currency: new FormControl('INR'),
percentage: new FormControl(),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData3 = new FormGroup({
amount: new FormControl(120),
currency: new FormControl('INR'),
percentage: new FormControl(),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData4 = deepFreeze(
new FormGroup({
amount: new FormControl(800),
currency: new FormControl('INR'),
percentage: new FormControl(40),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData4 = new FormGroup({
amount: new FormControl(800),
currency: new FormControl('INR'),
percentage: new FormControl(40),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData5 = deepFreeze(
new FormGroup({
amount: new FormControl(800),
currency: new FormControl('INR'),
percentage: new FormControl(90),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData5 = new FormGroup({
amount: new FormControl(800),
currency: new FormControl('INR'),
percentage: new FormControl(90),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData6 = deepFreeze(
new FormGroup({
amount: new FormControl(80),
currency: new FormControl('INR'),
percentage: new FormControl(96),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
})
);
export const splitExpenseFormData6 = new FormGroup({
amount: new FormControl(80),
currency: new FormControl('INR'),
percentage: new FormControl(96),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl(''),
});

export const splitExpenseFormData7 = deepFreeze(
new FormGroup({
amount: new FormControl(80),
currency: new FormControl('INR'),
percentage: new FormControl(96),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl({
code: null,
created_at: '2023-05-08T10:32:49.142566+00:00',
displayName: 'Food',
enabled: true,
fyle_category: 'Food',
id: 256621,
name: 'Food',
org_id: 'orNbIQloYtfa',
sub_category: 'Food',
updated_at: '2024-01-18T08:11:42.313617+00:00',
}),
project: new FormControl({
ap1_email: null,
ap1_full_name: null,
ap2_email: null,
ap2_full_name: null,
project_active: true,
project_approver1_id: null,
project_approver2_id: null,
project_code: null,
project_created_at: '2023-12-18T02:01:14.842Z',
project_description: null,
project_id: 325126,
project_name: 'Project 1',
project_org_category_ids: [256621, 256627, 256633],
project_org_id: 'orNbIQloYtfa',
project_updated_at: '2024-01-13T04:18:53.330Z',
projectv2_name: 'Project 1',
sub_project_name: null,
}),
cost_center: new FormControl({
active: true,
code: null,
created_at: '2023-12-13T09:20:18.568121+00:00',
description: null,
id: 20424,
name: 'Cost Center 1',
org_id: 'orNbIQloYtfa',
updated_at: '2024-01-10T16:48:41.754415+00:00',
}),
})
);
export const splitExpenseFormData7 = new FormGroup({
amount: new FormControl(80),
currency: new FormControl('INR'),
percentage: new FormControl(96),
txn_dt: new FormControl('2023-01-11'),
category: new FormControl({
code: null,
created_at: '2023-05-08T10:32:49.142566+00:00',
displayName: 'Food',
enabled: true,
fyle_category: 'Food',
id: 256621,
name: 'Food',
org_id: 'orNbIQloYtfa',
sub_category: 'Food',
updated_at: '2024-01-18T08:11:42.313617+00:00',
}),
project: new FormControl({
ap1_email: null,
ap1_full_name: null,
ap2_email: null,
ap2_full_name: null,
project_active: true,
project_approver1_id: null,
project_approver2_id: null,
project_code: null,
project_created_at: '2023-12-18T02:01:14.842Z',
project_description: null,
project_id: 325126,
project_name: 'Project 1',
project_org_category_ids: [256621, 256627, 256633],
project_org_id: 'orNbIQloYtfa',
project_updated_at: '2024-01-13T04:18:53.330Z',
projectv2_name: 'Project 1',
sub_project_name: null,
}),
cost_center: new FormControl({
active: true,
code: null,
created_at: '2023-12-13T09:20:18.568121+00:00',
description: null,
id: 20424,
name: 'Cost Center 1',
org_id: 'orNbIQloYtfa',
updated_at: '2024-01-10T16:48:41.754415+00:00',
}),
});
63 changes: 38 additions & 25 deletions src/app/core/services/advance-request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,16 @@ describe('AdvanceRequestService', () => {

describe('fixDates():', () => {
it('should convert string values to dates', () => {
const mockAdvanceReqData = cloneDeep(extendedAdvReqWithoutDates);
//@ts-ignore
expect(advanceRequestService.fixDates(extendedAdvReqWithoutDates)).toEqual(extendedAdvReqWithDates);
expect(advanceRequestService.fixDates(mockAdvanceReqData)).toEqual(extendedAdvReqWithDates);
});
});

it('fixDatesForPlatformFields(): should convert string values to dates', () => {
const mockAdvanceReqData = cloneDeep(advanceRequestPlatform.data[0]);
//@ts-ignore
expect(advanceRequestService.fixDatesForPlatformFields(advanceRequestPlatform.data[0])).toEqual(
advanceRequestPlatform.data[0]
);
expect(advanceRequestService.fixDatesForPlatformFields(mockAdvanceReqData)).toEqual(advanceRequestPlatform.data[0]);
});

it('getEReq(): should get advance request', (done) => {
Expand Down Expand Up @@ -532,10 +532,11 @@ describe('AdvanceRequestService', () => {
fileService.post.and.returnValue(of(fileObjectData3));
spyOn(advanceRequestService, 'submit').and.returnValue(of(advanceRequests));

advanceRequestService.createAdvReqWithFilesAndSubmit(advanceRequests, of(fileData1)).subscribe((res) => {
const mockFileObject = cloneDeep(fileData1);
advanceRequestService.createAdvReqWithFilesAndSubmit(advanceRequests, of(mockFileObject)).subscribe((res) => {
expect(res).toEqual(advRequestFile);
expect(advanceRequestService.submit).toHaveBeenCalledOnceWith(advanceRequests);
expect(fileService.post).toHaveBeenCalledOnceWith(fileData1[0]);
expect(fileService.post).toHaveBeenCalledOnceWith(mockFileObject[0]);
done();
});
});
Expand All @@ -556,10 +557,11 @@ describe('AdvanceRequestService', () => {
fileService.post.and.returnValue(of(fileObjectData4));
spyOn(advanceRequestService, 'saveDraft').and.returnValue(of(advancedRequests2));

advanceRequestService.saveDraftAdvReqWithFiles(advancedRequests2, of(fileData2)).subscribe((res) => {
const mockFileObject = cloneDeep(fileData2);
advanceRequestService.saveDraftAdvReqWithFiles(advancedRequests2, of(mockFileObject)).subscribe((res) => {
expect(res).toEqual(advRequestFile2);
expect(advanceRequestService.saveDraft).toHaveBeenCalledOnceWith(advancedRequests2);
expect(fileService.post).toHaveBeenCalledOnceWith(fileData2[0]);
expect(fileService.post).toHaveBeenCalledOnceWith(mockFileObject[0]);
done();
});
});
Expand Down Expand Up @@ -592,11 +594,15 @@ describe('AdvanceRequestService', () => {

describe('modifyAdvanceRequestCustomFields():', () => {
it('should modify advance request custom fields', () => {
expect(advanceRequestService.modifyAdvanceRequestCustomFields(customFields)).toEqual(expectedCustomFieldsWoDate);
const mockCustomFields = cloneDeep(customFields);
expect(advanceRequestService.modifyAdvanceRequestCustomFields(mockCustomFields)).toEqual(
expectedCustomFieldsWoDate
);
});

it('should modify custom fields with date value', () => {
expect(advanceRequestService.modifyAdvanceRequestCustomFields(customField2)).toEqual(
const mockCustomFields = cloneDeep(customField2);
expect(advanceRequestService.modifyAdvanceRequestCustomFields(mockCustomFields)).toEqual(
expectedCustomFieldsWithDate
);
});
Expand Down Expand Up @@ -728,6 +734,7 @@ describe('AdvanceRequestService', () => {
done();
});
});

it('should get all advance request with default params', (done) => {
spenderService.get.and.returnValue(of(advanceRequestPlatform));

Expand All @@ -747,8 +754,9 @@ describe('AdvanceRequestService', () => {

describe('getMyadvanceRequests():', () => {
it('should get all advance request', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes));
authService.getEou.and.resolveTo(apiEouRes);
const mockApiV2Res = cloneDeep(allAdvanceRequestsRes);
apiv2Service.get.and.returnValue(of(mockApiV2Res));

const param = {
offset: 0,
Expand All @@ -760,7 +768,7 @@ describe('AdvanceRequestService', () => {
};

advanceRequestService.getMyadvanceRequests(param).subscribe((res) => {
expect(res).toEqual(allAdvanceRequestsRes);
expect(res).toEqual(mockApiV2Res);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: param.offset,
Expand All @@ -773,12 +781,14 @@ describe('AdvanceRequestService', () => {
done();
});
});

it('should get all advance request with default params', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes));
authService.getEou.and.resolveTo(apiEouRes);
const mockApiV2Res = cloneDeep(allAdvanceRequestsRes);
apiv2Service.get.and.returnValue(of(mockApiV2Res));

advanceRequestService.getMyadvanceRequests().subscribe((res) => {
expect(res).toEqual(allAdvanceRequestsRes);
expect(res).toEqual(mockApiV2Res);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: 0,
Expand Down Expand Up @@ -827,8 +837,9 @@ describe('AdvanceRequestService', () => {

describe('getTeamAdvanceRequests():', () => {
it('should get all team advance requests | APPROVAL PENDING AND APPROVED', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allTeamAdvanceRequestsRes));
authService.getEou.and.resolveTo(apiEouRes);
const mockApiV2Res = cloneDeep(allTeamAdvanceRequestsRes);
apiv2Service.get.and.returnValue(of(mockApiV2Res));

const params = {
offset: 0,
Expand All @@ -849,7 +860,7 @@ describe('AdvanceRequestService', () => {
};

advanceRequestService.getTeamAdvanceRequests(params).subscribe((res) => {
expect(res).toEqual(allTeamAdvanceRequestsRes);
expect(res).toEqual(mockApiV2Res);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: params.offset,
Expand All @@ -866,8 +877,9 @@ describe('AdvanceRequestService', () => {
});

it('should get all team advance requests | APPROVAL PENDING', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allTeamAdvanceRequestsRes));
authService.getEou.and.resolveTo(apiEouRes);
const mockApiV2Res = cloneDeep(allTeamAdvanceRequestsRes);
apiv2Service.get.and.returnValue(of(mockApiV2Res));

const params = {
offset: 0,
Expand All @@ -888,7 +900,7 @@ describe('AdvanceRequestService', () => {
};

advanceRequestService.getTeamAdvanceRequests(params).subscribe((res) => {
expect(res).toEqual(allTeamAdvanceRequestsRes);
expect(res).toEqual(mockApiV2Res);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: params.offset,
Expand All @@ -905,8 +917,9 @@ describe('AdvanceRequestService', () => {
});

it('should get all team advance requests | APPROVED', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allTeamAdvanceRequestsRes));
authService.getEou.and.resolveTo(apiEouRes);
const mockApiV2Res = cloneDeep(allTeamAdvanceRequestsRes);
apiv2Service.get.and.returnValue(of(mockApiV2Res));

const params = {
offset: 0,
Expand All @@ -927,7 +940,7 @@ describe('AdvanceRequestService', () => {
};

advanceRequestService.getTeamAdvanceRequests(params).subscribe((res) => {
expect(res).toEqual(allTeamAdvanceRequestsRes);
expect(res).toEqual(mockApiV2Res);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: params.offset,
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/services/advance.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { apiEouRes } from '../mock-data/extended-org-user.data';
import { of } from 'rxjs';
import { SpenderService } from './platform/v1/spender/spender.service';
import { advancePlatform } from '../mock-data/advance-platform.data';
import { cloneDeep } from 'lodash';

describe('AdvanceService', () => {
let advanceService: AdvanceService;
Expand Down Expand Up @@ -59,8 +60,9 @@ describe('AdvanceService', () => {
});

it('fixDates(): should convert string values to dates', () => {
const mockExtendedAdvData = cloneDeep(extendedAdvWithoutDates);
//@ts-ignore
expect(advanceService.fixDates(extendedAdvWithoutDates)).toEqual(extendedAdvWithDates);
expect(advanceService.fixDates(mockExtendedAdvData)).toEqual(extendedAdvWithDates);
});

describe('getSpenderAdvances():', () => {
Expand Down
Loading

0 comments on commit 3f70654

Please sign in to comment.