Skip to content

Commit

Permalink
fix: Revert platform projects (#3000)
Browse files Browse the repository at this point in the history
* Revert "fix: Improved test cases ProjectsService (#2980)"

This reverts commit 77e6f4c.

* Revert "feat: Migrate getByParamsUnformatted -> spenderPlatformV1ApiService (#2954)"

This reverts commit 53f20fb.

* Revert "feat: Migrate getAllActive -> spenderPlatformV1ApiService (#2967)"

This reverts commit b5c9e2e.

* Revert "feat: Migrate getbyId -> spenderPlatformV1ApiService (#2946)"

This reverts commit e110648.

* Revert "feat: Add transformToV1Response & transformToV2Response for PlatformProject (#2942)"

This reverts commit 5ca606e.

---------

Co-authored-by: Dimple <[email protected]>
  • Loading branch information
Dimple16 and Dimple committed May 16, 2024
1 parent 4c679ff commit 20e62d5
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 286 deletions.
102 changes: 0 additions & 102 deletions src/app/core/mock-data/platform/v1/platform-project.data.ts

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/core/models/platform/platform-project.model.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/core/models/platform/v1/platform-project-params.model.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/app/core/models/v2/project-v2.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export interface ProjectV2 {
ap1_email?: string;
ap1_full_name?: string;
ap2_email?: string;
ap2_full_name?: string;
ap1_email: string;
ap1_full_name: string;
ap2_email: string;
ap2_full_name: string;
project_active: boolean;
project_approver1_id?: string;
project_approver2_id?: string;
project_approver1_id: string;
project_approver2_id: string;
project_code: string;
project_created_at: Date;
project_description: string;
Expand Down
62 changes: 21 additions & 41 deletions src/app/core/services/projects.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import {
params,
} from '../test-data/projects.spec.data';
import { ProjectsService } from './projects.service';
import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service';
import {
platformAPIResponseMultiple,
platformProjectSingleRes,
platformAPIResponseActiveOnly,
} from '../mock-data/platform/v1/platform-project.data';
import { ProjectPlatformParams } from '../mock-data/platform/v1/platform-projects-params.data';

const fixDate = (data) =>
data.map((datum) => ({
Expand All @@ -35,12 +28,10 @@ describe('ProjectsService', () => {
let projectsService: ProjectsService;
let apiService: jasmine.SpyObj<ApiService>;
let apiV2Service: jasmine.SpyObj<ApiV2Service>;
let spenderPlatformV1ApiService: jasmine.SpyObj<SpenderPlatformV1ApiService>;

beforeEach(() => {
const apiServiceSpy = jasmine.createSpyObj('ApiService', ['get']);
const apiv2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get']);
const spenderPlatformApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get']);

TestBed.configureTestingModule({
providers: [
Expand All @@ -53,56 +44,47 @@ describe('ProjectsService', () => {
provide: ApiV2Service,
useValue: apiv2ServiceSpy,
},
{
provide: SpenderPlatformV1ApiService,
useValue: spenderPlatformApiServiceSpy,
},
],
});
projectsService = TestBed.inject(ProjectsService);
apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
spenderPlatformV1ApiService = TestBed.inject(
SpenderPlatformV1ApiService
) as jasmine.SpyObj<SpenderPlatformV1ApiService>;
});

it('should be created', () => {
expect(projectsService).toBeTruthy();
});

it('should be able to fetch project by id', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformProjectSingleRes));
spyOn(projectsService, 'transformToV2Response').and.returnValue([apiV2ResponseSingle.data[0]]);
apiV2Service.get.and.returnValue(of(apiV2ResponseSingle));
projectsService.getbyId(257528).subscribe((res) => {
expect(res).toEqual(apiV2ResponseSingle.data[0]);
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledOnceWith('/projects', {
params: {
id: 'eq.257528',
},
});
expect(projectsService.transformToV2Response).toHaveBeenCalled();
expect(res).toEqual(fixDate(apiV2ResponseSingle.data)[0]);
done();
});

expect(apiV2Service.get).toHaveBeenCalledWith('/projects', {
params: {
project_id: 'eq.257528',
},
});
});

it('should be able to fetch all active projects', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformAPIResponseActiveOnly));
spyOn(projectsService, 'transformToV1Response').and.returnValue(expectedReponseActiveOnly);
apiService.get.and.returnValue(of(apiResponseActiveOnly));
projectsService.getAllActive().subscribe((res) => {
expect(res).toEqual(expectedReponseActiveOnly);
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledOnceWith('/projects', {
params: {
is_enabled: `eq.true`,
},
});
expect(projectsService.transformToV1Response).toHaveBeenCalled();
done();
});

expect(apiService.get).toHaveBeenCalledWith('/projects', {
params: {
active_only: true,
},
});
});

it('should be able to fetch data when no params provided', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformAPIResponseMultiple));
apiV2Service.get.and.returnValue(of(apiV2ResponseMultiple));

projectsService.getByParamsUnformatted({}).subscribe((res) => {
expect(res).toEqual(fixDate(apiV2ResponseMultiple.data));
Expand All @@ -111,17 +93,15 @@ describe('ProjectsService', () => {
});

it('should be able to fetch data when params are provided', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformAPIResponseMultiple));
const params = ProjectPlatformParams;
apiV2Service.get.and.returnValue(of(apiV2ResponseMultiple));

const result = projectsService.getByParamsUnformatted(testProjectParams);
spyOn(projectsService, 'transformToV2Response').and.returnValue(expectedProjectsResponse);

result.subscribe((res) => {
expect(res).toEqual(expectedProjectsResponse);
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledWith('/projects', {
expect(apiV2Service.get).toHaveBeenCalledWith('/projects', {
params,
});
expect(projectsService.transformToV2Response).toHaveBeenCalled();
done();
});
});
Expand All @@ -137,7 +117,7 @@ describe('ProjectsService', () => {
});

it('should get project count restricted by a set of category IDs', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformAPIResponseActiveOnly));
apiService.get.and.returnValue(of(apiResponseActiveOnly));

const result = projectsService.getProjectCount({ categoryIds: testCategoryIds });
result.subscribe((res) => {
Expand All @@ -147,7 +127,7 @@ describe('ProjectsService', () => {
});

it('should get project count not restricted by a set of category IDs', (done) => {
spenderPlatformV1ApiService.get.and.returnValue(of(platformAPIResponseActiveOnly));
apiService.get.and.returnValue(of(apiResponseActiveOnly));

const resultWithOutParam = projectsService.getProjectCount();
const resultWithParam = projectsService.getProjectCount({ categoryIds: null });
Expand Down
Loading

0 comments on commit 20e62d5

Please sign in to comment.