Skip to content

Commit 2e266c9

Browse files
author
Antonio Contreras LEMONCODE
committed
Create project list mappers spec
1 parent 7626522 commit 2e266c9

3 files changed

Lines changed: 119 additions & 3 deletions

File tree

src/pods/project-list/project-list.container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getProjectList, deleteProject } from './api';
44
import { Project } from './project-list.vm';
55
import { useSnackbarContext } from 'common/components';
66
import { trackPromise } from 'react-promise-tracker';
7-
import { mapProjectLIstFromApiToVm } from './project-list.mappers';
7+
import { mapProjectListFromApiToVm } from './project-list.mappers';
88
import { routes } from 'core/router';
99
import { useHistory } from 'react-router-dom';
1010
const editProjectId = '0';
@@ -17,7 +17,7 @@ export const ProjectListContainer: React.FunctionComponent = () => {
1717
const onLoadProjectList = async () => {
1818
try {
1919
const apiProjectList = await trackPromise(getProjectList());
20-
const viewModelProjectList = mapProjectLIstFromApiToVm(apiProjectList);
20+
const viewModelProjectList = mapProjectListFromApiToVm(apiProjectList);
2121
setProjects(viewModelProjectList);
2222
} catch (error) {
2323
error &&
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import * as apiModel from './api/project-list.api-model';
2+
import * as viewModel from './project-list.vm';
3+
import { mapProjectListFromApiToVm } from './project-list.mappers';
4+
5+
describe('./pods/project-list', () => {
6+
it('should return empty array when feeding undefined project list', () => {
7+
// Arrange
8+
const projectList = undefined;
9+
10+
// Act
11+
const result = mapProjectListFromApiToVm(projectList);
12+
13+
// Assert
14+
expect(result).toEqual([]);
15+
});
16+
17+
it('should return empty array when feeding null project list', () => {
18+
// Arrange
19+
const projectList = null;
20+
21+
// Act
22+
const result = mapProjectListFromApiToVm(projectList);
23+
24+
// Assert
25+
expect(result).toEqual([]);
26+
});
27+
28+
it('should return empty array when feeding empty array project list', () => {
29+
// Arrange
30+
const projectList = [];
31+
32+
// Act
33+
const result = mapProjectListFromApiToVm(projectList);
34+
35+
// Assert
36+
expect(result).toEqual([]);
37+
});
38+
39+
it('should return one item with values when passing one item with values', () => {
40+
// Arrange
41+
const projectList: apiModel.Project[] = [
42+
{
43+
id: 'test id',
44+
active: true,
45+
code: 'test code',
46+
projectName: 'test project name',
47+
lastDateIncurred: '02/02/2020',
48+
creationDate: '05/11/2019',
49+
},
50+
];
51+
52+
const expectedResult: viewModel.Project[] = [
53+
{
54+
id: 'test id',
55+
active: true,
56+
code: 'test code',
57+
projectName: 'test project name',
58+
lastDateIncurred: '02/02/2020',
59+
creationDate: '05/11/2019',
60+
},
61+
];
62+
63+
// Act
64+
const result = mapProjectListFromApiToVm(projectList);
65+
66+
// Assert
67+
expect(result).toEqual(expectedResult);
68+
});
69+
70+
it('should return two item with values when passing two item with values', () => {
71+
// Arrange
72+
const projectList: apiModel.Project[] = [
73+
{
74+
id: 'test id 1',
75+
active: true,
76+
code: 'test code',
77+
projectName: 'test project name 1',
78+
lastDateIncurred: '02/02/2020',
79+
creationDate: '05/11/2019',
80+
},
81+
{
82+
id: 'test id 2',
83+
active: false,
84+
code: 'test code',
85+
projectName: 'test project name 2',
86+
lastDateIncurred: '02/11/2020',
87+
creationDate: '05/05/2019',
88+
},
89+
];
90+
91+
const expectedResult: viewModel.Project[] = [
92+
{
93+
id: 'test id 1',
94+
active: true,
95+
code: 'test code',
96+
projectName: 'test project name 1',
97+
lastDateIncurred: '02/02/2020',
98+
creationDate: '05/11/2019',
99+
},
100+
{
101+
id: 'test id 2',
102+
active: false,
103+
code: 'test code',
104+
projectName: 'test project name 2',
105+
lastDateIncurred: '02/11/2020',
106+
creationDate: '05/05/2019',
107+
},
108+
];
109+
110+
// Act
111+
const result = mapProjectListFromApiToVm(projectList);
112+
113+
// Assert
114+
expect(result).toEqual(expectedResult);
115+
});
116+
});

src/pods/project-list/project-list.mappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mapProjectFromApiToVm = (
88
...project,
99
});
1010

11-
export const mapProjectLIstFromApiToVm = (
11+
export const mapProjectListFromApiToVm = (
1212
projectList: apiModel.Project[]
1313
): viewModel.Project[] =>
1414
mapToCollection(projectList, p => mapProjectFromApiToVm(p));

0 commit comments

Comments
 (0)