@@ -112,6 +112,98 @@ void invoicePdfCanBeStreamed() throws Exception {
112112 assertEquals ("/v2/invoices/inv_1/pdf" , request .uri ().getPath ());
113113 }
114114
115+ @ Test
116+ void invoiceZipRequestCanBeCreated () {
117+ StubHttpClient httpClient = new StubHttpClient ();
118+ httpClient .enqueueJson (200 , "{\" id\" :\" zip_1\" ,\" status\" :\" pending\" }" );
119+
120+ Facturapi sdk = new Facturapi (
121+ FacturapiConfig .builder ("sk_test" )
122+ .httpClient (httpClient .client ())
123+ .build ()
124+ );
125+
126+ var response = sdk .invoices ().createZipRequest (
127+ Map .of (
128+ "year" , 2025 ,
129+ "month" , 3 ,
130+ "issuer_type" , "issuing" ,
131+ "invoice_types" , java .util .List .of ("I" , "E" )
132+ )
133+ );
134+
135+ assertEquals ("zip_1" , response .get ("id" ));
136+ var request = httpClient .requests ().get (0 );
137+ assertEquals ("POST" , request .method ());
138+ assertEquals ("/v2/invoices/zip-requests" , request .uri ().getPath ());
139+ assertTrue (request .bodyUtf8 ().contains ("\" issuer_type\" :\" issuing\" " ));
140+ }
141+
142+ @ Test
143+ void invoiceZipRequestsCanBeListed () {
144+ StubHttpClient httpClient = new StubHttpClient ();
145+ httpClient .enqueueJson (
146+ 200 ,
147+ "{\" page\" :1,\" total_pages\" :1,\" total_results\" :1,\" data\" :[{\" id\" :\" zip_1\" }]}"
148+ );
149+
150+ Facturapi sdk = new Facturapi (
151+ FacturapiConfig .builder ("sk_test" )
152+ .httpClient (httpClient .client ())
153+ .build ()
154+ );
155+
156+ var response = sdk .invoices ().listZipRequests (
157+ Map .of ("year" , 2025 , "month" , 3 , "status" , "finished" , "limit" , 20 , "page" , 1 )
158+ );
159+
160+ assertEquals ("zip_1" , response .getData ().get (0 ).get ("id" ));
161+ var request = httpClient .requests ().get (0 );
162+ assertEquals ("GET" , request .method ());
163+ assertEquals ("/v2/invoices/zip-requests" , request .uri ().getPath ());
164+ assertTrue (request .uri ().getQuery ().contains ("year=2025" ));
165+ assertTrue (request .uri ().getQuery ().contains ("status=finished" ));
166+ }
167+
168+ @ Test
169+ void invoiceZipRequestCanBeRetrieved () {
170+ StubHttpClient httpClient = new StubHttpClient ();
171+ httpClient .enqueueJson (200 , "{\" id\" :\" zip_1\" ,\" status\" :\" finished\" }" );
172+
173+ Facturapi sdk = new Facturapi (
174+ FacturapiConfig .builder ("sk_test" )
175+ .httpClient (httpClient .client ())
176+ .build ()
177+ );
178+
179+ var response = sdk .invoices ().retrieveZipRequest ("zip_1" );
180+
181+ assertEquals ("finished" , response .get ("status" ));
182+ var request = httpClient .requests ().get (0 );
183+ assertEquals ("GET" , request .method ());
184+ assertEquals ("/v2/invoices/zip-requests/zip_1" , request .uri ().getPath ());
185+ }
186+
187+ @ Test
188+ void invoiceZipRequestCanBeDownloaded () throws Exception {
189+ StubHttpClient httpClient = new StubHttpClient ();
190+ httpClient .enqueueBinary (200 , "ZIP-CONTENT" .getBytes (StandardCharsets .UTF_8 ), "application/zip" );
191+
192+ Facturapi sdk = new Facturapi (
193+ FacturapiConfig .builder ("sk_test" )
194+ .httpClient (httpClient .client ())
195+ .build ()
196+ );
197+
198+ try (InputStream stream = sdk .invoices ().downloadZipRequest ("zip_1" )) {
199+ assertEquals ("ZIP-CONTENT" , new String (stream .readAllBytes (), StandardCharsets .UTF_8 ));
200+ }
201+
202+ var request = httpClient .requests ().get (0 );
203+ assertEquals ("GET" , request .method ());
204+ assertEquals ("/v2/invoices/zip-requests/zip_1/zip" , request .uri ().getPath ());
205+ }
206+
115207 @ Test
116208 void organizationUploadsAcceptBytes () {
117209 StubHttpClient httpClient = new StubHttpClient ();
0 commit comments