-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgetCounselorFromGroupAuxiliary.test.js
More file actions
174 lines (160 loc) · 5.15 KB
/
Copy pathgetCounselorFromGroupAuxiliary.test.js
File metadata and controls
174 lines (160 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import {
DEFAULT_GROUP_LINK_NUVEM_CIVICA,
DEFAULT_USER_LINK_NUVEM_CIVICA,
} from '../../../src/constants/linkConstants';
import {
getCounselorFromGroup,
getCounselor,
getCounselorProfile,
getGroup,
} from '../../../src/actions/auxiliary/getCounselorFromGroupAuxiliary';
import {
GET_COUNSELORS_GROUP_LINKS_ERROR,
GET_COUNSELORS_FROM_CAE_ACCOUNT_ERROR,
GET_COUNSELORS_FROM_CAE_PROFILE_ERROR,
GET_GROUP_ERROR,
} from '../../../src/constants/errorConstants';
import { APP_IDENTIFIER } from '../../../src/constants/codeNumbers';
import { convertingContentStringToJSON } from '../../../src/actions/applicationActions';
describe('Testing getCounselorFromGroupAuxiliary functions', () => {
let mock = null;
let codGroup = null;
let counselorLink = null;
let linkWithCodMembro = null;
let counselorInformations = null;
let getProfileHeader = null;
let paramsToNuvem = null;
beforeAll(() => {
mock = new MockAdapter(axios);
codGroup = 1;
counselorLink = 'http://mobile-aceite.tcu.gov.br/appCivicoRS/rest/pessoas/6832';
linkWithCodMembro = 'http://mobile-aceite.tcu.gov.br/appCivicoRS/rest/grupos/1118/membros/1068';
counselorInformations = {
nuvemCode: 6832,
email: 'testecae@hotmail.com',
name: 'Teste',
codMembro: '1068',
profile: {},
};
getProfileHeader = {
headers: {
appIdentifier: APP_IDENTIFIER,
},
};
paramsToNuvem = {
params: {
codAplicativo: APP_IDENTIFIER,
descricao: 'CAE',
},
};
});
afterEach(() => {
mock.reset();
});
it('Testing getCounselorFromGroup', async () => {
mock.onGet(`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros`)
.reply(200, [
{
links: [
{
href: 'http://testlink.com',
},
{
href: 'http://testlink2.com',
},
],
},
],
);
const actionReturn = await getCounselorFromGroup(codGroup);
expect(actionReturn[1]).toEqual(['http://testlink.com']);
expect(actionReturn[0]).toEqual(['http://testlink2.com']);
});
it('Testing getCounselorFromGroup on failure', async () => {
mock.onGet(`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros`)
.reply(400);
try {
await await getCounselorFromGroup(codGroup);
} catch (error) {
console.log(error.stack);
const errorJson = JSON.parse(error.message);
expect(errorJson.name).toBe(GET_COUNSELORS_GROUP_LINKS_ERROR);
}
});
it('Testing getCounselor', async () => {
mock.onGet(counselorLink)
.reply(200, {
nomeUsuario: 'testecae@hotmail.com',
nomeCompleto: 'Teste',
cod: 6832,
email: 'testecae@hotmail.com',
emailVerificado: false,
});
const actionReturn = await getCounselor(counselorLink, linkWithCodMembro);
expect(actionReturn).toEqual([counselorInformations, 6832]);
});
it('Testing editCounselorProfile failure', async () => {
mock.onGet(counselorLink)
.reply(400);
try {
await getCounselor(counselorLink, linkWithCodMembro);
} catch (error) {
const errorJson = JSON.parse(error.message);
expect(errorJson.name).toBe(GET_COUNSELORS_FROM_CAE_ACCOUNT_ERROR);
}
});
it('Testing getCounselorProfile', async () => {
const campos = `
{'cpf':'54545184848',
'phone':'64575481884',
'isPresident':false,
'presidentChecked':false,
'counselorType':'Suplente',
'segment':'Trabalhadores da educação',
'CAE_Type':'Municipal',
'CAE_UF':'GO - Goiás',
'CAE_municipalDistrict':'Aloândia -',
'CAE':'Aloândia - GO'}`;
mock.onGet(`${DEFAULT_USER_LINK_NUVEM_CIVICA}${counselorInformations.nuvemCode}/perfil`, getProfileHeader)
.reply(200, {
camposAdicionais: campos,
});
const actionReturn = await getCounselorProfile(
counselorInformations, counselorInformations.nuvemCode);
const profile = convertingContentStringToJSON(campos);
const finalCounselor = counselorInformations;
finalCounselor.profile = profile;
expect(actionReturn).toEqual(finalCounselor);
});
it('Testing getCounselorProfile failure', async () => {
mock.onGet(`${DEFAULT_USER_LINK_NUVEM_CIVICA}${counselorInformations.nuvemCode}/perfil`, getProfileHeader)
.reply(400);
try {
await getCounselorProfile(
counselorInformations, counselorInformations.nuvemCode);
} catch (error) {
const errorJson = JSON.parse(error.message);
expect(errorJson.name).toBe(GET_COUNSELORS_FROM_CAE_PROFILE_ERROR);
}
});
it('Testing getGroup', async () => {
mock.onGet(DEFAULT_GROUP_LINK_NUVEM_CIVICA, paramsToNuvem)
.reply(200, [{
codGrupo: 1,
}]);
const actionReturn = await getGroup('CAE');
expect(actionReturn).toEqual(1);
});
it('Testing getGroup failure', async () => {
mock.onGet(DEFAULT_GROUP_LINK_NUVEM_CIVICA, paramsToNuvem)
.reply(400);
try {
await getGroup('CAE');
} catch (error) {
const errorJson = JSON.parse(error.message);
expect(errorJson.name).toBe(GET_GROUP_ERROR);
}
});
});