@@ -4,9 +4,14 @@ import {
44 ResponseErrorInternal ,
55 ResponseSuccessJson
66} 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" ;
710import mockReq from "../../__mocks__/request" ;
811import PagoPAClientFactory from "../../services/pagoPAClientFactory" ;
912import PagoPAProxyService from "../../services/pagoPAProxyService" ;
13+ import { SessionToken , WalletToken } from "../../types/token" ;
14+ import { User } from "../../types/user" ;
1015import PagoPAProxyController from "../pagoPAProxyController" ;
1116
1217const aRptId = "123456" ;
@@ -152,12 +157,35 @@ describe("PagoPAProxyController#getPaymentInfo", () => {
152157} ) ;
153158
154159describe ( "PagoPAProxyController#activatePayment" , ( ) => {
160+ const aTimestamp = 1518010929530 ;
161+ const aFiscalNumber = "GRBGPP87L04L741X" as FiscalCode ;
162+ const anEmailAddress = "[email protected] " 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+
155182 beforeEach ( ( ) => {
156183 jest . clearAllMocks ( ) ;
157184 } ) ;
158185
159186 it ( "calls the activatePayment on the PagoPAProxyService with valid values" , async ( ) => {
160187 const req = mockReq ( ) ;
188+ req . user = mockedUser ;
161189
162190 mockActivatePayment . mockReturnValue (
163191 Promise . resolve ( ResponseSuccessJson ( proxyPaymentActivationsPostResponse ) )
@@ -176,7 +204,10 @@ describe("PagoPAProxyController#activatePayment", () => {
176204 const response = await controller . activatePayment ( req ) ;
177205
178206 expect ( mockActivatePayment ) . toHaveBeenCalledWith (
179- paymentActivationsPostRequest ,
207+ {
208+ ...paymentActivationsPostRequest ,
209+ soggettoPagatore : expectedSoggettoPagatore
210+ } ,
180211 false
181212 ) ;
182213
@@ -189,6 +220,7 @@ describe("PagoPAProxyController#activatePayment", () => {
189220
190221 it ( "[TEST env] calls the activatePayment on the PagoPAProxyService with valid values" , async ( ) => {
191222 const req = mockReq ( ) ;
223+ req . user = mockedUser ;
192224
193225 mockActivatePayment . mockReturnValue (
194226 Promise . resolve ( ResponseSuccessJson ( proxyPaymentActivationsPostResponse ) )
@@ -207,7 +239,10 @@ describe("PagoPAProxyController#activatePayment", () => {
207239 const response = await controller . activatePayment ( req ) ;
208240
209241 expect ( mockActivatePayment ) . toHaveBeenCalledWith (
210- paymentActivationsPostRequest ,
242+ {
243+ ...paymentActivationsPostRequest ,
244+ soggettoPagatore : expectedSoggettoPagatore
245+ } ,
211246 true
212247 ) ;
213248 expect ( response ) . toEqual ( {
@@ -219,6 +254,7 @@ describe("PagoPAProxyController#activatePayment", () => {
219254
220255 it ( "fails if the call to activatePayment fails" , async ( ) => {
221256 const req = mockReq ( ) ;
257+ req . user = mockedUser ;
222258
223259 mockActivatePayment . mockReturnValue (
224260 Promise . resolve ( ResponseErrorInternal ( internalErrorMessage ) )
@@ -237,7 +273,10 @@ describe("PagoPAProxyController#activatePayment", () => {
237273 const response = await controller . activatePayment ( req ) ;
238274
239275 expect ( mockActivatePayment ) . toHaveBeenCalledWith (
240- paymentActivationsPostRequest ,
276+ {
277+ ...paymentActivationsPostRequest ,
278+ soggettoPagatore : expectedSoggettoPagatore
279+ } ,
241280 false
242281 ) ;
243282 expect ( response ) . toEqual ( aResponseErrorInternal ) ;
0 commit comments