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
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ export const advanceRequestCustomFieldValuesData: AdvanceRequestCustomFieldValue
{
name: 'Phase',
value: 'Phase 1',
type: 'SELECT',
},
{
name: 'BILLABLE',
value: true,
type: 'BOOLEAN',
},
{
name: 'Arrival Date',
value: '2023-1-2',
type: 'DATE',
},
{
name: 'Checking',
value: 'option1',
type: 'OPTION',
},
];

Expand All @@ -28,4 +36,8 @@ export const advanceRequestCustomFieldValuesData2: AdvanceRequestCustomFieldValu
name: 'Arrival Date',
value: '2023-1-2',
},
{
name: 'Checking',
value: 'option1',
},
];
42 changes: 42 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,10 +588,39 @@ export const publicAdvanceRequestRes: ApiV2Response<ExtendedAdvanceRequestPublic
offset: 0,
};

export const publicAdvanceRequestResSentBack: ApiV2Response<ExtendedAdvanceRequestPublic> = {
count: 1,
data: [
{
...cloneDeep(publicAdvanceRequestRes.data[0]),
areq_state: 'INQUIRY',
areq_is_pulled_back: false,
areq_is_sent_back: true,
areq_id: 'areqiwr3Wwirk',
},
],
offset: 0,
};

export const publicAdvanceRequestResPulledBack: ApiV2Response<ExtendedAdvanceRequestPublic> = {
count: 1,
data: [
{
...cloneDeep(publicAdvanceRequestRes.data[0]),
areq_state: 'DRAFT',
areq_is_pulled_back: true,
areq_is_sent_back: false,
areq_id: 'areqiwr3Wwirl',
},
],
offset: 0,
};

export const publicAdvanceRequestRes2: ApiV2Response<ExtendedAdvanceRequestPublic> = {
...publicAdvanceRequestRes,
count: 250,
};

export const publicAdvanceRequestRes3: ExtendedAdvanceRequestPublic = {
...publicAdvanceRequestRes.data[0],
type: 'request',
Expand Down Expand Up @@ -649,6 +679,18 @@ export const publicAdvanceRequestRes5: ApiV2Response<ExtendedAdvanceRequestPubli
offset: 0,
};

export const publicAdvanceRequestRes6: ExtendedAdvanceRequestPublic = {
...publicAdvanceRequestRes.data[0],
type: 'request',
currency: 'USD',
amount: 47.99,
created_at: new Date('2020-06-01T13:14:54.804Z'),
purpose: 'onsite client meeting',
state: 'DRAFT',
areq_is_sent_back: false,
areq_is_pulled_back: true,
};

export const allTeamAdvanceRequestsRes: ApiV2Response<ExtendedAdvanceRequest> = {
count: 43,
data: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { cloneDeep } from 'lodash';
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 +88,27 @@ export const advanceRequestPlatform: PlatformApiResponse<AdvanceRequestPlatform>
},
],
};

export const advanceRequestPlatformPulledBack: PlatformApiResponse<AdvanceRequestPlatform> = {
count: 1,
offset: 0,
data: [
{
...cloneDeep(advanceRequestPlatform.data[0]),
state: 'PULLED_BACK',
id: 'areqiwr3Wwirl',
},
],
};

export const advanceRequestPlatformSentBack: PlatformApiResponse<AdvanceRequestPlatform> = {
count: 1,
offset: 0,
data: [
{
...cloneDeep(advanceRequestPlatform.data[0]),
id: 'areqiwr3Wwirk',
state: 'SENT_BACK',
},
],
};
2 changes: 0 additions & 2 deletions src/app/core/mock-data/unflattened-advance-request.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ export const unflattenedAdvanceRequestData: UnflattenedAdvanceRequest = {
project_id: null,
custom_field_values: [
{
id: 159,
name: 'Advance Request Place',
value: 'd',
type: null,
},
{
id: 160,
name: 'Category',
value: 'Fyle is best',
type: null,
Expand Down
201 changes: 146 additions & 55 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,71 @@ 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 Expand Up @@ -630,56 +685,92 @@ describe('AdvanceRequestService', () => {
});
});

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

const param = {
offset: 0,
limit: 200,
queryParams: {
advance_id: 'eq.null',
order: 'created_at.desc,id.desc',
},
};
describe('getSpenderAdvanceRequests():', () => {
it('should get all advance request', (done) => {
spenderService.get.and.returnValue(of(advanceRequestPlatform));

advanceRequestService.getSpenderAdvanceRequests(param).subscribe((res) => {
expect(res).toEqual(publicAdvanceRequestRes);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: param.offset,
limit: param.limit,
...param.queryParams,
const param = {
offset: 0,
limit: 200,
queryParams: {
advance_id: 'eq.null',
order: 'created_at.desc,id.desc',
},
};

advanceRequestService.getSpenderAdvanceRequests(param).subscribe((res) => {
expect(res).toEqual(publicAdvanceRequestRes);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: param.offset,
limit: param.limit,
...param.queryParams,
},
});
done();
});
done();
});
});
it('should get all advance request with default params', (done) => {
spenderService.get.and.returnValue(of(advanceRequestPlatform));

it('getMyadvanceRequests(): should get all advance request', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes));
advanceRequestService.getSpenderAdvanceRequests().subscribe((res) => {
expect(res).toEqual(publicAdvanceRequestRes);
expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: 0,
limit: 200,
advance_id: 'eq.null',
},
});
done();
});
});
});

const param = {
offset: 0,
limit: 10,
queryParams: {
areq_advance_id: 'is.null',
order: 'areq_created_at.desc,areq_id.desc',
},
};
describe('getMyadvanceRequests():', () => {
it('should get all advance request', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes));

advanceRequestService.getMyadvanceRequests(param).subscribe((res) => {
expect(res).toEqual(allAdvanceRequestsRes);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: param.offset,
limit: param.limit,
areq_org_user_id: 'eq.' + apiEouRes.ou.id,
...param.queryParams,
const param = {
offset: 0,
limit: 10,
queryParams: {
areq_advance_id: 'is.null',
order: 'areq_created_at.desc,areq_id.desc',
},
};

advanceRequestService.getMyadvanceRequests(param).subscribe((res) => {
expect(res).toEqual(allAdvanceRequestsRes);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: param.offset,
limit: param.limit,
areq_org_user_id: 'eq.' + apiEouRes.ou.id,
...param.queryParams,
},
});
expect(authService.getEou).toHaveBeenCalledTimes(1);
done();
});
});
it('should get all advance request with default params', (done) => {
authService.getEou.and.returnValue(Promise.resolve(apiEouRes));
apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes));

advanceRequestService.getMyadvanceRequests().subscribe((res) => {
expect(res).toEqual(allAdvanceRequestsRes);
expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', {
params: {
offset: 0,
limit: 10,
areq_org_user_id: 'eq.' + apiEouRes.ou.id,
},
});
expect(authService.getEou).toHaveBeenCalledTimes(1);
done();
});
expect(authService.getEou).toHaveBeenCalledTimes(1);
done();
});
});

Expand Down
Loading
Loading