Move invoice generation to billing bucket and improve emailing

This moves the new pipeline's invoice generation to the billing bucket, under the 'invoices/yyyy-MM' subdirectory.

This also changes the invoice e-mail to use a multipart message that attaches the invoice to the e-mail, to guarantee the correct MIME type and download.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181746191
This commit is contained in:
larryruili 2018-01-12 08:18:49 -08:00 committed by Ben McIlwain
parent 5726f1dc4e
commit a42f18798e
16 changed files with 477 additions and 133 deletions

View file

@ -53,6 +53,7 @@ public class GenerateInvoicesActionTest {
private Templates templates;
private Launch launch;
private FakeResponse response;
private BillingEmailUtils emailUtils;
private GenerateInvoicesAction action;
@Before
@ -61,6 +62,7 @@ public class GenerateInvoicesActionTest {
projects = mock(Projects.class);
templates = mock(Templates.class);
launch = mock(Launch.class);
emailUtils = mock(BillingEmailUtils.class);
when(dataflow.projects()).thenReturn(projects);
when(projects.templates()).thenReturn(templates);
when(templates.launch(any(String.class), any(LaunchTemplateParameters.class)))
@ -72,8 +74,15 @@ public class GenerateInvoicesActionTest {
job.setId("12345");
when(launch.execute()).thenReturn(new LaunchTemplateResponse().setJob(job));
action = new GenerateInvoicesAction(
"test-project", "gs://test-project-beam", new YearMonth(2017, 10), dataflow, response);
action =
new GenerateInvoicesAction(
"test-project",
"gs://test-project-beam",
"gs://test-project-beam/templates/invoicing",
new YearMonth(2017, 10),
dataflow,
response,
emailUtils);
}
@Test
@ -96,7 +105,8 @@ public class GenerateInvoicesActionTest {
new TaskMatcher()
.url("/_dr/task/publishInvoices")
.method("POST")
.param("jobId", "12345");
.param("jobId", "12345")
.param("yearMonth", "2017-10");
assertTasksEnqueued("billing", matcher);
}
@ -106,5 +116,6 @@ public class GenerateInvoicesActionTest {
action.run();
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getPayload()).isEqualTo("Template launch failed: expected");
verify(emailUtils).sendAlertEmail("Template Launch failed due to expected");
}
}