@@ -4,9 +4,14 @@ import {
4
4
ResponseErrorInternal ,
5
5
ResponseSuccessJson
6
6
} from "italia-ts-commons/lib/responses" ;
7
+ import { FiscalCode , NonEmptyString } from "italia-ts-commons/lib/strings" ;
8
+ import { EmailAddress } from "../../../generated/backend/EmailAddress" ;
9
+ import { SpidLevelEnum } from "../../../generated/backend/SpidLevel" ;
7
10
import mockReq from "../../__mocks__/request" ;
8
11
import PagoPAClientFactory from "../../services/pagoPAClientFactory" ;
9
12
import PagoPAProxyService from "../../services/pagoPAProxyService" ;
13
+ import { SessionToken , WalletToken } from "../../types/token" ;
14
+ import { User } from "../../types/user" ;
10
15
import PagoPAProxyController from "../pagoPAProxyController" ;
11
16
12
17
const aRptId = "123456" ;
@@ -152,12 +157,35 @@ describe("PagoPAProxyController#getPaymentInfo", () => {
152
157
} ) ;
153
158
154
159
describe ( "PagoPAProxyController#activatePayment" , ( ) => {
160
+ const aTimestamp = 1518010929530 ;
161
+ const aFiscalNumber = "GRBGPP87L04L741X" as FiscalCode ;
162
+ const anEmailAddress = "garibaldi@example.com" as EmailAddress ;
163
+ const aValidSpidLevel = SpidLevelEnum [ "https://www.spid.gov.it/SpidL2" ] ;
164
+
165
+ const mockedUser : User = {
166
+ created_at : aTimestamp ,
167
+ family_name : "Garibaldi" ,
168
+ fiscal_code : aFiscalNumber ,
169
+ name : "Giuseppe Maria" ,
170
+ session_token : "123hexToken" as SessionToken ,
171
+ spid_email : anEmailAddress ,
172
+ spid_level : aValidSpidLevel ,
173
+ spid_mobile_phone : "3222222222222" as NonEmptyString ,
174
+ wallet_token : "123hexToken" as WalletToken
175
+ } ;
176
+ const expectedSoggettoPagatore = {
177
+ anagrafica : `${ mockedUser . name } ${ mockedUser . family_name } ` ,
178
+ fiscal_code : mockedUser . fiscal_code ,
179
+ tipo : "F"
180
+ } ;
181
+
155
182
beforeEach ( ( ) => {
156
183
jest . clearAllMocks ( ) ;
157
184
} ) ;
158
185
159
186
it ( "calls the activatePayment on the PagoPAProxyService with valid values" , async ( ) => {
160
187
const req = mockReq ( ) ;
188
+ req . user = mockedUser ;
161
189
162
190
mockActivatePayment . mockReturnValue (
163
191
Promise . resolve ( ResponseSuccessJson ( proxyPaymentActivationsPostResponse ) )
@@ -176,7 +204,10 @@ describe("PagoPAProxyController#activatePayment", () => {
176
204
const response = await controller . activatePayment ( req ) ;
177
205
178
206
expect ( mockActivatePayment ) . toHaveBeenCalledWith (
179
- paymentActivationsPostRequest ,
207
+ {
208
+ ...paymentActivationsPostRequest ,
209
+ soggettoPagatore : expectedSoggettoPagatore
210
+ } ,
180
211
false
181
212
) ;
182
213
@@ -189,6 +220,7 @@ describe("PagoPAProxyController#activatePayment", () => {
189
220
190
221
it ( "[TEST env] calls the activatePayment on the PagoPAProxyService with valid values" , async ( ) => {
191
222
const req = mockReq ( ) ;
223
+ req . user = mockedUser ;
192
224
193
225
mockActivatePayment . mockReturnValue (
194
226
Promise . resolve ( ResponseSuccessJson ( proxyPaymentActivationsPostResponse ) )
@@ -207,7 +239,10 @@ describe("PagoPAProxyController#activatePayment", () => {
207
239
const response = await controller . activatePayment ( req ) ;
208
240
209
241
expect ( mockActivatePayment ) . toHaveBeenCalledWith (
210
- paymentActivationsPostRequest ,
242
+ {
243
+ ...paymentActivationsPostRequest ,
244
+ soggettoPagatore : expectedSoggettoPagatore
245
+ } ,
211
246
true
212
247
) ;
213
248
expect ( response ) . toEqual ( {
@@ -219,6 +254,7 @@ describe("PagoPAProxyController#activatePayment", () => {
219
254
220
255
it ( "fails if the call to activatePayment fails" , async ( ) => {
221
256
const req = mockReq ( ) ;
257
+ req . user = mockedUser ;
222
258
223
259
mockActivatePayment . mockReturnValue (
224
260
Promise . resolve ( ResponseErrorInternal ( internalErrorMessage ) )
@@ -237,7 +273,10 @@ describe("PagoPAProxyController#activatePayment", () => {
237
273
const response = await controller . activatePayment ( req ) ;
238
274
239
275
expect ( mockActivatePayment ) . toHaveBeenCalledWith (
240
- paymentActivationsPostRequest ,
276
+ {
277
+ ...paymentActivationsPostRequest ,
278
+ soggettoPagatore : expectedSoggettoPagatore
279
+ } ,
241
280
false
242
281
) ;
243
282
expect ( response ) . toEqual ( aResponseErrorInternal ) ;
0 commit comments