|
| 1 | +// import { TestBed, inject } from '@angular/core/testing'; |
| 2 | +// import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
| 3 | + |
| 4 | +// import { ServicesManagementService } from './services-management.service'; |
| 5 | + |
| 6 | +// describe('ServicesManagementService', () => { |
| 7 | +// let service: ServicesManagementService; |
| 8 | +// let httpMock: HttpTestingController; |
| 9 | + |
| 10 | +// const projectsList: Project[] = [ |
| 11 | +// { |
| 12 | +// id: '1', |
| 13 | +// name: 'app 1', |
| 14 | +// description: 'It is a good app', |
| 15 | +// project_type_id: '123', |
| 16 | +// }, |
| 17 | +// { |
| 18 | +// id: '2', |
| 19 | +// name: 'app 2', |
| 20 | +// description: 'It is a good app', |
| 21 | +// project_type_id: '123', |
| 22 | +// }, |
| 23 | +// { |
| 24 | +// id: '3', |
| 25 | +// name: 'app 3', |
| 26 | +// description: 'It is a good app', |
| 27 | +// project_type_id: '123', |
| 28 | +// }, |
| 29 | +// ]; |
| 30 | + |
| 31 | +// beforeEach(() => { |
| 32 | +// TestBed.configureTestingModule({ |
| 33 | +// imports: [HttpClientTestingModule], |
| 34 | +// }); |
| 35 | +// service = TestBed.inject(ServicesManagementService); |
| 36 | +// httpMock = TestBed.inject(HttpTestingController); |
| 37 | +// }); |
| 38 | + |
| 39 | +// afterEach(() => { |
| 40 | +// httpMock.verify(); |
| 41 | +// }); |
| 42 | + |
| 43 | +// it('should be created', inject( |
| 44 | +// [HttpClientTestingModule, ServicesManagementService], |
| 45 | +// (httpClient: HttpClientTestingModule, apiService: ServicesManagementService) => { |
| 46 | +// expect(apiService).toBeTruthy(); |
| 47 | +// expect(httpClient).toBeTruthy(); |
| 48 | +// } |
| 49 | +// )); |
| 50 | + |
| 51 | +// it('all projects are read using GET from url', () => { |
| 52 | +// const projectsFoundSize = projectsList.length; |
| 53 | +// service.getAll().subscribe((projectsInResponse) => { |
| 54 | +// expect(projectsInResponse.length).toBe(projectsFoundSize); |
| 55 | +// }); |
| 56 | +// const getProjectsRequest = httpMock.expectOne(service.url); |
| 57 | +// expect(getProjectsRequest.request.method).toBe('GET'); |
| 58 | +// getProjectsRequest.flush(projectsList); |
| 59 | +// }); |
| 60 | + |
| 61 | +// it('projects are read using GET from url', () => { |
| 62 | +// const projectsFoundSize = projectsList.length; |
| 63 | +// service.url = '/projects'; |
| 64 | +// service.getProjects({ customerId: 'xyz' }).subscribe((projectsInResponse) => { |
| 65 | +// expect(projectsInResponse.length).toBe(projectsFoundSize); |
| 66 | +// }); |
| 67 | +// const getProjectsRequest = httpMock.expectOne(`${service.url}?customer_id=xyz`); |
| 68 | +// expect(getProjectsRequest.request.method).toBe('GET'); |
| 69 | +// getProjectsRequest.flush(projectsList); |
| 70 | +// }); |
| 71 | + |
| 72 | +// it('recent projects are read using GET from url/recent', () => { |
| 73 | +// const projectsFoundSize = projectsList.length; |
| 74 | +// service.getRecentProjects().subscribe((projectsInResponse) => { |
| 75 | +// expect(projectsInResponse.length).toBe(projectsFoundSize); |
| 76 | +// }); |
| 77 | +// const getProjectsRequest = httpMock.expectOne(`${service.url}/recent`); |
| 78 | +// expect(getProjectsRequest.request.method).toBe('GET'); |
| 79 | +// getProjectsRequest.flush(projectsList); |
| 80 | +// }); |
| 81 | + |
| 82 | +// it('create project using POST from url', () => { |
| 83 | +// const project: Project[] = [{ id: '1', name: 'ccc', description: 'xxx', project_type_id: '123' }]; |
| 84 | +// service.url = 'projects'; |
| 85 | +// service.createProject(project).subscribe((response) => { |
| 86 | +// expect(response.length).toBe(1); |
| 87 | +// }); |
| 88 | +// const createProjectsRequest = httpMock.expectOne(service.url); |
| 89 | +// expect(createProjectsRequest.request.method).toBe('POST'); |
| 90 | +// createProjectsRequest.flush(project); |
| 91 | +// }); |
| 92 | + |
| 93 | +// it('update project using PUT from url', () => { |
| 94 | +// const project: Project = { id: '1', name: 'new name', description: 'description', project_type_id: '123' }; |
| 95 | +// service.url = 'projects'; |
| 96 | +// service.updateProject(project).subscribe((response) => { |
| 97 | +// expect(response.name).toBe('new name'); |
| 98 | +// }); |
| 99 | +// const updateProjectRequest = httpMock.expectOne(`${service.url}/${project.id}`); |
| 100 | +// expect(updateProjectRequest.request.method).toBe('PUT'); |
| 101 | +// updateProjectRequest.flush(project); |
| 102 | +// }); |
| 103 | + |
| 104 | +// it('update project using PUT from url locally', () => { |
| 105 | +// const project: Project = { id: '1', name: 'new name', description: 'description', project_type_id: '123', status: 'active'}; |
| 106 | +// service.url = 'projects'; |
| 107 | +// service.isDevelopmentOrProd = true; |
| 108 | +// service.updateProject(project).subscribe((response) => { |
| 109 | +// expect(response.name).toBe('new name'); |
| 110 | +// }); |
| 111 | +// const updateProjectRequest = httpMock.expectOne(`${service.url}/${project.id}`); |
| 112 | +// expect(updateProjectRequest.request.method).toBe('PUT'); |
| 113 | +// updateProjectRequest.flush(project); |
| 114 | +// }); |
| 115 | + |
| 116 | +// it('delete project using DELETE from baseUrl', () => { |
| 117 | +// const url = `${service.url}/1`; |
| 118 | +// service.isDevelopmentOrProd = false; |
| 119 | +// service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => { |
| 120 | +// expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2); |
| 121 | +// }); |
| 122 | +// const deleteActivitiesRequest = httpMock.expectOne(url); |
| 123 | +// expect(deleteActivitiesRequest.request.method).toBe('DELETE'); |
| 124 | +// deleteActivitiesRequest.flush(projectsList); |
| 125 | +// }); |
| 126 | + |
| 127 | +// it('update status project using PUT from baseUrl locally', () => { |
| 128 | +// const url = `${service.url}/1`; |
| 129 | +// service.isDevelopmentOrProd = true; |
| 130 | +// service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => { |
| 131 | +// expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2); |
| 132 | +// }); |
| 133 | +// const deleteActivitiesRequest = httpMock.expectOne(url); |
| 134 | +// expect(deleteActivitiesRequest.request.method).toBe('PUT'); |
| 135 | +// deleteActivitiesRequest.flush(projectsList); |
| 136 | +// }); |
| 137 | + |
| 138 | +// }); |
0 commit comments