11import request from "supertest" ;
22import app from "@src/app" ;
33import { tryber } from "@src/features/database" ;
4+ import { getPresignedUrl } from "@src/features/s3/presignUrl" ;
5+
6+ jest . mock ( "@src/features/s3/presignUrl" ) ;
7+
8+ const mockedGetPresignedUrl = getPresignedUrl as jest . MockedFunction <
9+ typeof getPresignedUrl
10+ > ;
411
512describe ( "GET /campaigns/campaignId/finance/otherCosts" , ( ) => {
13+ beforeEach ( ( ) => {
14+ mockedGetPresignedUrl . mockImplementation ( async ( url : string ) => url ) ;
15+ } ) ;
16+
17+ afterEach ( ( ) => {
18+ jest . clearAllMocks ( ) ;
19+ } ) ;
620 beforeAll ( async ( ) => {
721 await tryber . tables . WpAppqEvdProfile . do ( ) . insert ( [
822 {
@@ -176,11 +190,13 @@ describe("GET /campaigns/campaignId/finance/otherCosts", () => {
176190 id : 1 ,
177191 url : "https://example.com/attachment1.pdf" ,
178192 mimetype : "application/pdf" ,
193+ presigned_url : expect . any ( String ) ,
179194 } ) ,
180195 expect . objectContaining ( {
181196 id : 2 ,
182197 url : "https://example.com/attachment2.jpg" ,
183198 mimetype : "image/jpeg" ,
199+ presigned_url : expect . any ( String ) ,
184200 } ) ,
185201 ] ) ,
186202 } ) ,
@@ -201,6 +217,7 @@ describe("GET /campaigns/campaignId/finance/otherCosts", () => {
201217 id : 3 ,
202218 url : "https://example.com/attachment3.png" ,
203219 mimetype : "image/png" ,
220+ presigned_url : expect . any ( String ) ,
204221 } ) ,
205222 ] ) ,
206223 } ) ,
@@ -230,6 +247,20 @@ describe("GET /campaigns/campaignId/finance/otherCosts", () => {
230247 id : 1 ,
231248 } ,
232249 description : "Cost 1 description" ,
250+ attachments : expect . arrayContaining ( [
251+ expect . objectContaining ( {
252+ id : 1 ,
253+ url : "https://example.com/attachment1.pdf" ,
254+ mimetype : "application/pdf" ,
255+ presigned_url : expect . any ( String ) ,
256+ } ) ,
257+ expect . objectContaining ( {
258+ id : 2 ,
259+ url : "https://example.com/attachment2.jpg" ,
260+ mimetype : "image/jpeg" ,
261+ presigned_url : expect . any ( String ) ,
262+ } ) ,
263+ ] ) ,
233264 } ) ,
234265 expect . objectContaining ( {
235266 cost_id : 2 ,
@@ -243,6 +274,14 @@ describe("GET /campaigns/campaignId/finance/otherCosts", () => {
243274 id : 2 ,
244275 } ,
245276 description : "Cost 2 description" ,
277+ attachments : expect . arrayContaining ( [
278+ expect . objectContaining ( {
279+ id : 3 ,
280+ url : "https://example.com/attachment3.png" ,
281+ mimetype : "image/png" ,
282+ presigned_url : expect . any ( String ) ,
283+ } ) ,
284+ ] ) ,
246285 } ) ,
247286 ] ) ,
248287 } )
@@ -307,4 +346,24 @@ describe("GET /campaigns/campaignId/finance/otherCosts", () => {
307346 expect ( costWithoutAttachments . cost ) . toBe ( 50 ) ;
308347 expect ( costWithoutAttachments . attachments ) . toEqual ( [ ] ) ;
309348 } ) ;
349+
350+ it ( "Should call getPresignedUrl for each attachment with 3 hours expiration" , async ( ) => {
351+ await request ( app )
352+ . get ( "/campaigns/1/finance/otherCosts" )
353+ . set ( "Authorization" , "Bearer admin" ) ;
354+
355+ expect ( mockedGetPresignedUrl ) . toHaveBeenCalledTimes ( 3 ) ;
356+ expect ( mockedGetPresignedUrl ) . toHaveBeenCalledWith (
357+ "https://example.com/attachment1.pdf" ,
358+ 10800
359+ ) ;
360+ expect ( mockedGetPresignedUrl ) . toHaveBeenCalledWith (
361+ "https://example.com/attachment2.jpg" ,
362+ 10800
363+ ) ;
364+ expect ( mockedGetPresignedUrl ) . toHaveBeenCalledWith (
365+ "https://example.com/attachment3.png" ,
366+ 10800
367+ ) ;
368+ } ) ;
310369} ) ;
0 commit comments