@@ -3,14 +3,16 @@ import { describe, expect, it, vi } from "vitest";
33const mockFetchSubmitted = vi . fn ( ) . mockResolvedValue ( [ ] ) ;
44const mockFetchIndicatorG = vi . fn ( ) . mockResolvedValue ( new Map ( ) ) ;
55const mockFetchCse = vi . fn ( ) . mockResolvedValue ( new Map ( ) ) ;
6+ const mockFetchCseFiles = vi . fn ( ) . mockResolvedValue ( new Map ( ) ) ;
67
78vi . mock ( "~/modules/export/queries" , ( ) => ( {
89 fetchSubmittedDeclarations : ( ...args : unknown [ ] ) =>
910 mockFetchSubmitted ( ...args ) ,
1011 fetchIndicatorGByDeclaration : ( ...args : unknown [ ] ) =>
1112 mockFetchIndicatorG ( ...args ) ,
1213 fetchCseOpinionsByDeclaration : ( ...args : unknown [ ] ) => mockFetchCse ( ...args ) ,
13- fetchCseFilesByDeclaration : vi . fn ( ) . mockResolvedValue ( new Map ( ) ) ,
14+ fetchCseFilesByDeclaration : ( ...args : unknown [ ] ) =>
15+ mockFetchCseFiles ( ...args ) ,
1416 fetchJointEvaluationFilesByDeclaration : vi . fn ( ) . mockResolvedValue ( new Map ( ) ) ,
1517} ) ) ;
1618
@@ -74,6 +76,7 @@ describe("GET /api/v1/export/declarations", () => {
7476 mockFetchSubmitted . mockResolvedValue ( [ ] ) ;
7577 mockFetchIndicatorG . mockResolvedValue ( new Map ( ) ) ;
7678 mockFetchCse . mockResolvedValue ( new Map ( ) ) ;
79+ mockFetchCseFiles . mockResolvedValue ( new Map ( ) ) ;
7780 } ) ;
7881
7982 it ( "should return 401 when Authorization header is missing" , async ( ) => {
@@ -294,5 +297,145 @@ describe("GET /api/v1/export/declarations", () => {
294297 expect ( decl . indicators . F . annual ) . toHaveLength ( 4 ) ;
295298 expect ( decl . secondDeclaration . correction ) . toBeNull ( ) ;
296299 expect ( decl . cseOpinions ) . toEqual ( [ ] ) ;
300+ expect ( decl . cseFiles ) . toEqual ( [ ] ) ;
301+ } ) ;
302+
303+ it ( "should expose CSE opinion declarationNumber alongside type" , async ( ) => {
304+ mockFetchSubmitted . mockResolvedValue ( [
305+ {
306+ declarationId : "decl-1" ,
307+ siren : "123456789" ,
308+ year : 2027 ,
309+ status : "submitted" ,
310+ compliancePath : null ,
311+ totalWomen : 100 ,
312+ totalMen : 150 ,
313+ secondDeclarationStatus : null ,
314+ secondDeclReferencePeriodStart : null ,
315+ secondDeclReferencePeriodEnd : null ,
316+ createdAt : new Date ( "2027-03-15T10:00:00Z" ) ,
317+ updatedAt : new Date ( "2027-03-15T12:00:00Z" ) ,
318+ companyName : "ACME Corp" ,
319+ workforce : 250 ,
320+ nafCode : "62.02" ,
321+ address : "1 rue test" ,
322+ hasCse : true ,
323+ declarantFirstName : "Jean" ,
324+ declarantLastName : "Dupont" ,
325+ declarantEmail : "jean@acme.fr" ,
326+ declarantPhone : "0612345678" ,
327+ ...nullIndicators ,
328+ } ,
329+ ] ) ;
330+ mockFetchCse . mockResolvedValue (
331+ new Map ( [
332+ [
333+ "decl-1" ,
334+ [
335+ {
336+ declarationNumber : 1 ,
337+ type : "accuracy" ,
338+ opinion : "favorable" ,
339+ opinionDate : "2027-03-01" ,
340+ } ,
341+ {
342+ declarationNumber : 2 ,
343+ type : "gap" ,
344+ opinion : "unfavorable" ,
345+ opinionDate : "2027-06-01" ,
346+ } ,
347+ ] ,
348+ ] ,
349+ ] ) ,
350+ ) ;
351+
352+ const { GET } = await import ( "~/app/api/v1/export/declarations/route" ) ;
353+ const request = authedRequest (
354+ "http://localhost/api/v1/export/declarations?date_begin=2027-03-15" ,
355+ ) ;
356+ const response = await GET ( request ) ;
357+
358+ expect ( response . status ) . toBe ( 200 ) ;
359+ const body = await response . json ( ) ;
360+ expect ( body . declarations [ 0 ] . cseOpinions ) . toEqual ( [
361+ {
362+ declarationNumber : 1 ,
363+ type : "accuracy" ,
364+ opinion : "favorable" ,
365+ date : "2027-03-01" ,
366+ } ,
367+ {
368+ declarationNumber : 2 ,
369+ type : "gap" ,
370+ opinion : "unfavorable" ,
371+ date : "2027-06-01" ,
372+ } ,
373+ ] ) ;
374+ } ) ;
375+
376+ it ( "should include CSE file URLs in the declaration response" , async ( ) => {
377+ mockFetchSubmitted . mockResolvedValue ( [
378+ {
379+ declarationId : "decl-1" ,
380+ siren : "123456789" ,
381+ year : 2027 ,
382+ status : "submitted" ,
383+ compliancePath : null ,
384+ totalWomen : 100 ,
385+ totalMen : 150 ,
386+ secondDeclarationStatus : null ,
387+ secondDeclReferencePeriodStart : null ,
388+ secondDeclReferencePeriodEnd : null ,
389+ createdAt : new Date ( "2027-03-15T10:00:00Z" ) ,
390+ updatedAt : new Date ( "2027-03-15T12:00:00Z" ) ,
391+ companyName : "ACME Corp" ,
392+ workforce : 250 ,
393+ nafCode : "62.02" ,
394+ address : "1 rue test" ,
395+ hasCse : true ,
396+ declarantFirstName : "Jean" ,
397+ declarantLastName : "Dupont" ,
398+ declarantEmail : "jean@acme.fr" ,
399+ declarantPhone : "0612345678" ,
400+ ...nullIndicators ,
401+ } ,
402+ ] ) ;
403+ mockFetchCseFiles . mockResolvedValue (
404+ new Map ( [
405+ [
406+ "123456789-2027" ,
407+ [
408+ {
409+ id : "file-abc" ,
410+ siren : "123456789" ,
411+ year : 2027 ,
412+ fileName : "avis-cse-2027.pdf" ,
413+ filePath : "/s3/path" ,
414+ uploadedAt : new Date ( "2027-03-10T08:30:00Z" ) ,
415+ } ,
416+ ] ,
417+ ] ,
418+ ] ) ,
419+ ) ;
420+
421+ const { GET } = await import ( "~/app/api/v1/export/declarations/route" ) ;
422+ const request = authedRequest (
423+ "http://localhost/api/v1/export/declarations?date_begin=2027-03-15" ,
424+ ) ;
425+ const response = await GET ( request ) ;
426+
427+ expect ( response . status ) . toBe ( 200 ) ;
428+ expect ( mockFetchCseFiles ) . toHaveBeenCalledWith ( [
429+ { siren : "123456789" , year : 2027 } ,
430+ ] ) ;
431+ const body = await response . json ( ) ;
432+ expect ( body . declarations [ 0 ] . cseFiles ) . toEqual ( [
433+ {
434+ id : "file-abc" ,
435+ fileName : "avis-cse-2027.pdf" ,
436+ uploadedAt : "2027-03-10T08:30:00.000Z" ,
437+ downloadUrl : "/api/v1/files/file-abc" ,
438+ } ,
439+ ] ) ;
297440 } ) ;
298441} ) ;
0 commit comments