BillingApiHandler extends LoggingRequestHandler { private HttpResponse createInvoice(HttpRequest request, String userId) { Inspector inspector = inspectorOrThrow(request); TenantName tenantName = TenantName.from(getInspectorFieldOrThrow(inspector, "tenant")); LocalDate startDate = LocalDate.parse(getInspectorFieldOrThrow(inspector, "startTime")); LocalDate endDate = LocalDate.parse(getInspectorFieldOrThrow(inspector, "endTime")); ZonedDateTime startTime = startDate.atStartOfDay(ZoneId.of("UTC")); ZonedDateTime endTime = endDate.atStartOfDay(ZoneId.of("UTC")); var invoiceId = billingController.createInvoiceForPeriod(tenantName, startTime, endTime, userId); return new MessageResponse("Created invoice with ID " + invoiceId.value()); } BillingApiHandler(Executor executor,
                             AccessLog accessLog,
                             Controller controller); @Override HttpResponse handle(HttpRequest request);  }
@Test public void response_list_bills() { var invoice = createInvoice(); billingController.addInvoice(tenant, invoice, true); billingController.addInvoice(tenant, invoice, false); billingController.setPlan(tenant, PlanId.from("some-plan"), true); var request = request("/billing/v1/tenant/tenant1/billing?until=2020-05-28").roles(tenantRole); tester.assertResponse(request, new File("tenant-billing-view")); }
@Test public void adding_new_status() { billingController.addInvoice(tenant, createInvoice(), true); var requestBody = "{\"status\":\"DONE\"}"; var request = request("/billing/v1/invoice/id-1/status", POST) .data(requestBody) .roles(financeAdmin); tester.assertResponse(request, "{\"message\":\"Updated status of invoice id-1\"}"); var invoice = billingController.getInvoices(tenant).get(0); assertEquals("DONE", invoice.status()); }