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: Add branching fixes and other fixes for advance request #2865

Merged
merged 15 commits into from
Apr 16, 2024
73 changes: 73 additions & 0 deletions src/app/core/mock-data/extended-advance-request.data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneDeep } from 'lodash';
import { ApiV2Response } from '../models/api-v2.model';
import { ExtendedAdvanceRequestPublic } from '../models/extended-advance-request-public.model';
import { ExtendedAdvanceRequest } from '../models/extended_advance_request.model';
Expand Down Expand Up @@ -587,6 +588,78 @@ export const publicAdvanceRequestRes: ApiV2Response<ExtendedAdvanceRequestPublic
offset: 0,
};

export const publicAdvanceRequestResSentBack: ApiV2Response<ExtendedAdvanceRequestPublic> = {
count: 1,
data: [
{
areq_state: 'INQUIRY',
areq_is_pulled_back: false,
areq_is_sent_back: true,
areq_advance_request_number: 'A/2020/10/T/95',
areq_advance_id: 'advjrgwlk2Q',
areq_amount: 47.99,
areq_approved_at: new Date('2020-06-14T13:14:55.201Z'),
areq_created_at: new Date('2020-06-01T13:14:54.804Z'),
areq_currency: 'USD',
areq_id: 'areqiwr3Wwirk',
areq_notes: 'onsite client meeting',
areq_org_user_id: 'outGt9ju6qP',
areq_project_id: '1234',
areq_purpose: 'onsite client meeting',
areq_source: 'WEBAPP',
areq_updated_at: new Date('2020-06-11T13:14:55.201Z'),
ou_department: 'Tech',
ou_department_id: 'deptCjFrZcE0rH',
ou_id: 'outGt9ju6qP',
ou_org_id: 'orwruogwnngg',
ou_sub_department: 'Tech',
us_email: '[email protected]',
us_full_name: 'John Doe',
ou_employee_id: 'outGt9ju6qP',
areq_custom_field_values: [{ name: 'checking', value: 'true', type: 'BOOLEAN' }],
project_name: 'Fast and Furious',
project_code: 'C1234',
},
],
offset: 0,
};

export const publicAdvanceRequestResPulledBack: ApiV2Response<ExtendedAdvanceRequestPublic> = {
count: 1,
data: [
{
areq_state: 'DRAFT',
areq_is_pulled_back: true,
areq_is_sent_back: false,
areq_advance_request_number: 'A/2020/10/T/95',
areq_advance_id: 'advjrgwlk2Q',
areq_amount: 47.99,
areq_approved_at: new Date('2020-06-14T13:14:55.201Z'),
areq_created_at: new Date('2020-06-01T13:14:54.804Z'),
areq_currency: 'USD',
areq_id: 'areqiwr3Wwirl',
areq_notes: 'onsite client meeting',
areq_org_user_id: 'outGt9ju6qP',
areq_project_id: '1234',
areq_purpose: 'onsite client meeting',
areq_source: 'WEBAPP',
areq_updated_at: new Date('2020-06-11T13:14:55.201Z'),
ou_department: 'Tech',
ou_department_id: 'deptCjFrZcE0rH',
ou_id: 'outGt9ju6qP',
ou_org_id: 'orwruogwnngg',
ou_sub_department: 'Tech',
us_email: '[email protected]',
us_full_name: 'John Doe',
ou_employee_id: 'outGt9ju6qP',
areq_custom_field_values: [{ name: 'checking', value: 'true', type: 'BOOLEAN' }],
project_name: 'Fast and Furious',
project_code: 'C1234',
},
],
offset: 0,
};

export const publicAdvanceRequestRes2: ApiV2Response<ExtendedAdvanceRequestPublic> = {
...publicAdvanceRequestRes,
count: 250,
Expand Down
171 changes: 171 additions & 0 deletions src/app/core/mock-data/platform/v1/advance-request-platform.data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CustomFieldTypes } from 'src/app/core/enums/platform/v1/custom-fields-type.enum';
import { AdvanceRequestState } from 'src/app/core/models/advance-request-state.model';
import { AdvanceRequestPlatform } from 'src/app/core/models/platform/advance-request-platform.model';
import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model';

Expand Down Expand Up @@ -86,3 +87,173 @@ export const advanceRequestPlatform: PlatformApiResponse<AdvanceRequestPlatform>
},
],
};

export const advanceRequestPlatformPulledBack: PlatformApiResponse<AdvanceRequestPlatform> = {
count: 1,
offset: 0,
data: [
{
advance: {
id: 'advkvnwrnpwi',
currency: 'USD',
amount: 47.99,
advance_request_id: 'advjrgwlk2Q',
seq_num: 'A/2020/10/T/95',
},
id: 'areqiwr3Wwirl',
user_id: 'uswjwgnwwgo',
user: {
id: 'uswjwgnwwgo',
email: '[email protected]',
full_name: 'John Doe',
},
approvals: [
{
approver_user_id: 'usge49ielgel',
approver_user: {
id: 'uswjwgnwwgo',
email: '[email protected]',
full_name: 'John Doe',
},
state: 'APPROVAL_PENDING',
},
],
org_id: 'orwruogwnngg',
created_at: new Date('2020-06-01T13:14:54.804+00:00'),
updated_at: new Date('2020-06-11T13:14:55.201598+00:00'),
currency: 'USD',
amount: 47.99,
policy_amount: 1500,
advance_id: 'advjrgwlk2Q',
seq_num: 'A/2020/10/T/95',
code: 'C1234',
notes: 'onsite client meeting',
purpose: 'onsite client meeting',
source: 'WEBAPP',
state: 'PULLED_BACK',
project_id: '1234',
project: {
id: 1234,
name: 'Fast and Furious',
sub_project: 'Formula One',
code: 'C1234',
display_name: 'Fast and Furious / Formula One',
},
is_policy_flagged: true,
is_exported: true,
employee_id: 'outGt9ju6qP',
employee: {
code: null,
department: {
code: null,
display_name: 'Tech',
id: 'deptCjFrZcE0rH',
name: 'Tech',
sub_department: 'Tech',
},
department_id: 'deptCjFrZcE0rH',
id: 'ouirDZ7tTLEQ',
org_id: 'orNVthTo2Zyo',
user: {
email: '[email protected]',
full_name: 'Arjun',
id: 'usJZ9bgfNB5n',
},
user_id: 'usJZ9bgfNB5n',
},
last_approved_at: new Date('2020-06-14T13:14:55.201598+00:00'),
custom_fields: [
{
name: 'checking',
value: 'true',
type: CustomFieldTypes.BOOLEAN,
},
],
},
],
};

export const advanceRequestPlatformSentBack: PlatformApiResponse<AdvanceRequestPlatform> = {
count: 1,
offset: 0,
data: [
{
advance: {
id: 'advkvnwrnpwi',
currency: 'USD',
amount: 47.99,
advance_request_id: 'advjrgwlk2Q',
seq_num: 'A/2020/10/T/95',
},
id: 'areqiwr3Wwirk',
user_id: 'uswjwgnwwgo',
user: {
id: 'uswjwgnwwgo',
email: '[email protected]',
full_name: 'John Doe',
},
approvals: [
{
approver_user_id: 'usge49ielgel',
approver_user: {
id: 'uswjwgnwwgo',
email: '[email protected]',
full_name: 'John Doe',
},
state: 'APPROVAL_PENDING',
},
],
org_id: 'orwruogwnngg',
created_at: new Date('2020-06-01T13:14:54.804+00:00'),
updated_at: new Date('2020-06-11T13:14:55.201598+00:00'),
currency: 'USD',
amount: 47.99,
policy_amount: 1500,
advance_id: 'advjrgwlk2Q',
seq_num: 'A/2020/10/T/95',
code: 'C1234',
notes: 'onsite client meeting',
purpose: 'onsite client meeting',
source: 'WEBAPP',
state: AdvanceRequestState.SENT_BACK,
project_id: '1234',
project: {
id: 1234,
name: 'Fast and Furious',
sub_project: 'Formula One',
code: 'C1234',
display_name: 'Fast and Furious / Formula One',
},
is_policy_flagged: true,
is_exported: true,
employee_id: 'outGt9ju6qP',
employee: {
code: null,
department: {
code: null,
display_name: 'Tech',
id: 'deptCjFrZcE0rH',
name: 'Tech',
sub_department: 'Tech',
},
department_id: 'deptCjFrZcE0rH',
id: 'ouirDZ7tTLEQ',
org_id: 'orNVthTo2Zyo',
user: {
email: '[email protected]',
full_name: 'Arjun',
id: 'usJZ9bgfNB5n',
},
user_id: 'usJZ9bgfNB5n',
},
last_approved_at: new Date('2020-06-14T13:14:55.201598+00:00'),
custom_fields: [
{
name: 'checking',
value: 'true',
type: CustomFieldTypes.BOOLEAN,
},
],
},
],
};
85 changes: 71 additions & 14 deletions src/app/core/services/advance-request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
extendedAdvReqWithDates,
extendedAdvReqWithoutDates,
publicAdvanceRequestRes,
publicAdvanceRequestResPulledBack,
publicAdvanceRequestResSentBack,
singleErqRes,
singleErqUnflattened,
singleExtendedAdvReqRes,
Expand All @@ -54,7 +56,11 @@ import { FileService } from './file.service';
import { OrgUserSettingsService } from './org-user-settings.service';
import { TimezoneService } from './timezone.service';
import { SpenderService } from './platform/v1/spender/spender.service';
import { advanceRequestPlatform } from '../mock-data/platform/v1/advance-request-platform.data';
import {
advanceRequestPlatform,
advanceRequestPlatformPulledBack,
advanceRequestPlatformSentBack,
} from '../mock-data/platform/v1/advance-request-platform.data';
import { cloneDeep } from 'lodash';

describe('AdvanceRequestService', () => {
Expand Down Expand Up @@ -159,22 +165,73 @@ describe('AdvanceRequestService', () => {
});
});

it('getAdvanceRequestPlatform(): should get an advance request from ID', (done) => {
const advReqID = 'areqiwr3Wwirr';
spenderService.get.and.returnValue(of(advanceRequestPlatform));
// @ts-ignore
spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatform.data[0]);
describe('getAdvanceRequestPlatform(): ', () => {
it('should get an advance request from ID', (done) => {
const advReqID = 'areqiwr3Wwiri';
const expectedData = cloneDeep(publicAdvanceRequestRes);
spenderService.get.and.returnValue(of(advanceRequestPlatform));
// @ts-ignore
spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatform.data[0]);

advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => {
expect(res).toEqual(publicAdvanceRequestRes.data[0]);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
id: `eq.${advReqID}`,
},
advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => {
expect(res).toEqual(expectedData.data[0]);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
id: `eq.${advReqID}`,
},
});
// @ts-ignore
expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith(
advanceRequestPlatform.data[0]
);
done();
});
});

it('should get a sent back advance request from ID', (done) => {
const advReqID = 'areqiwr3Wwirk';
const expectedData = cloneDeep(publicAdvanceRequestResSentBack);
spenderService.get.and.returnValue(of(advanceRequestPlatformSentBack));
// @ts-ignore
expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith(advanceRequestPlatform.data[0]);
done();
spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatformSentBack.data[0]);

advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => {
expect(res).toEqual(expectedData.data[0]);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
id: `eq.${advReqID}`,
},
});
// @ts-ignore
expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith(
advanceRequestPlatformSentBack.data[0]
);
done();
});
});

it('should get a pulled back advance request from ID', (done) => {
const advReqID = 'areqiwr3Wwirr';
const expectedData = cloneDeep(publicAdvanceRequestResPulledBack);
spenderService.get.and.returnValue(of(advanceRequestPlatformPulledBack));
// @ts-ignore
spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(
advanceRequestPlatformPulledBack.data[0]
);

advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => {
expect(res).toEqual(expectedData.data[0]);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
id: `eq.${advReqID}`,
},
});
// @ts-ignore
expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith(
advanceRequestPlatformPulledBack.data[0]
);
done();
});
});
});

Expand Down
Loading
Loading