Skip to content

Commit db02f40

Browse files
CCM-10442: Email test fixes (#567)
1 parent f0c99fe commit db02f40

File tree

12 files changed

+34
-100
lines changed

12 files changed

+34
-100
lines changed

infrastructure/terraform/components/sandbox/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
1919
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonymous with account short-name) | `string` | n/a | yes |
2020
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
21-
| <a name="input_letter_suppliers"></a> [letter\_suppliers](#input\_letter\_suppliers) | Letter suppliers enabled in the environment | <pre>map(object({<br/> email_addresses = list(string)<br/> enable_polling = bool<br/> default_supplier = optional(bool)<br/> }))</pre> | <pre>{<br/> "WTMMOCK": {<br/> "default_supplier": true,<br/> "email_addresses": [],<br/> "enable_polling": true<br/> }<br/>}</pre> | no |
2221
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
2322
| <a name="input_parent_acct_environment"></a> [parent\_acct\_environment](#input\_parent\_acct\_environment) | Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments | `string` | `"main"` | no |
2423
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
@@ -47,8 +46,7 @@
4746
| <a name="output_sftp_poll_lambda_name"></a> [sftp\_poll\_lambda\_name](#output\_sftp\_poll\_lambda\_name) | n/a |
4847
| <a name="output_templates_table_name"></a> [templates\_table\_name](#output\_templates\_table\_name) | n/a |
4948
| <a name="output_test_email_bucket_name"></a> [test\_email\_bucket\_name](#output\_test\_email\_bucket\_name) | n/a |
50-
| <a name="output_test_proof_requested_email_prefix"></a> [test\_proof\_requested\_email\_prefix](#output\_test\_proof\_requested\_email\_prefix) | n/a |
51-
| <a name="output_test_template_submitted_email_prefix"></a> [test\_template\_submitted\_email\_prefix](#output\_test\_template\_submitted\_email\_prefix) | n/a |
49+
| <a name="output_test_email_bucket_prefix"></a> [test\_email\_bucket\_prefix](#output\_test\_email\_bucket\_prefix) | n/a |
5250
<!-- vale on -->
5351
<!-- markdownlint-enable -->
5452
<!-- END_TF_DOCS -->
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
locals {
2-
mock_letter_supplier_name = "WTMMOCK"
3-
4-
use_sftp_letter_supplier_mock = lookup(var.letter_suppliers, local.mock_letter_supplier_name, null) != null
5-
62
email_domain = "sandbox.${local.acct.dns_zone["name"]}"
73
sandbox_letter_supplier_mock_proof_requested_sender = "proof-requested-sender-${var.environment}@${local.email_domain}"
84
sandbox_letter_supplier_mock_template_submitted_sender = "template-submitted-sender-${var.environment}@${local.email_domain}"
95
sandbox_letter_supplier_mock_recipient = "supplier-recipient-${var.environment}@${local.email_domain}"
10-
11-
# var.letter_suppliers is defined at a point where we don't know what the environment is, so
12-
# we need to add the environment-dependent test recipient separately here
13-
letter_suppliers = local.use_sftp_letter_supplier_mock ? merge(
14-
var.letter_suppliers,
15-
{ WTMMOCK = {
16-
email_addresses = concat(var.letter_suppliers.WTMMOCK.email_addresses, [local.sandbox_letter_supplier_mock_recipient])
17-
enable_polling = true
18-
default_supplier = true
19-
} }
20-
) : var.letter_suppliers
216
}

infrastructure/terraform/components/sandbox/module_backend_api.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ module "backend_api" {
1818
}
1919

2020
enable_proofing = true
21-
letter_suppliers = local.letter_suppliers
21+
letter_suppliers = {
22+
WTMMOCK = {
23+
email_addresses = [local.sandbox_letter_supplier_mock_recipient]
24+
enable_polling = true
25+
default_supplier = true
26+
}
27+
}
2228

2329
kms_key_arn = data.aws_kms_key.sandbox.arn
2430

infrastructure/terraform/components/sandbox/outputs.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ output "test_email_bucket_name" {
6262
value = local.acct["ses_testing_config"].bucket_name
6363
}
6464

65-
output "test_proof_requested_email_prefix" {
66-
value = "proof-requested-emails-${var.environment}"
67-
}
68-
69-
70-
output "test_template_submitted_email_prefix" {
71-
value = "template-submitted-emails-${var.environment}"
65+
output "test_email_bucket_prefix" {
66+
value = "emails-${var.environment}"
7267
}

infrastructure/terraform/components/sandbox/ses_receipt_rule_proof_requested.tf renamed to infrastructure/terraform/components/sandbox/ses_receipt_rule.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ resource "aws_ses_receipt_rule" "proof_requested" {
22
name = "${local.csi}-store-email-proof-requested"
33
rule_set_name = local.acct["ses_testing_config"].rule_set_name
44

5-
# Despite being called "recipients", AWS appears to apply this check to the sender email
6-
recipients = [local.sandbox_letter_supplier_mock_proof_requested_sender]
5+
recipients = [local.sandbox_letter_supplier_mock_recipient]
76
enabled = true
87
scan_enabled = true
98
tls_policy = "Optional"
109

1110
s3_action {
1211
position = 1
1312
bucket_name = local.acct["ses_testing_config"].bucket_name
14-
object_key_prefix = "proof-requested-emails-${var.environment}/"
13+
object_key_prefix = "emails-${var.environment}/"
1514
iam_role_arn = local.acct["ses_testing_config"].iam_role_arn
1615
}
1716
}

infrastructure/terraform/components/sandbox/ses_receipt_rule_template_submitted.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

infrastructure/terraform/components/sandbox/variables.tf

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,6 @@ variable "kms_deletion_window" {
6363
default = "30"
6464
}
6565

66-
variable "letter_suppliers" {
67-
type = map(object({
68-
email_addresses = list(string)
69-
enable_polling = bool
70-
default_supplier = optional(bool)
71-
}))
72-
73-
default = {
74-
"WTMMOCK" = {
75-
email_addresses = []
76-
enable_polling = true
77-
default_supplier = true
78-
}
79-
}
80-
81-
validation {
82-
condition = (
83-
length(var.letter_suppliers) == 0 ||
84-
length([for s in values(var.letter_suppliers) : s if s.default_supplier]) == 1
85-
)
86-
error_message = "If letter suppliers are configured, exactly one must be default_supplier"
87-
}
88-
89-
description = "Letter suppliers enabled in the environment"
90-
}
91-
9266
variable "parent_acct_environment" {
9367
type = string
9468
description = "Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments"

tests/test-team/global.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ declare global {
1414
TEMPLATES_INTERNAL_BUCKET_NAME: string;
1515
TEMPLATES_QUARANTINE_BUCKET_NAME: string;
1616
TEMPLATES_DOWNLOAD_BUCKET_NAME: string;
17-
TEST_TEMPLATE_SUBMITTED_EMAIL_PREFIX: string;
18-
TEST_PROOF_REQUESTED_EMAIL_PREFIX: string;
17+
TEST_EMAIL_BUCKET_PREFIX: string;
1918
}
2019
}
2120

tests/test-team/helpers/email-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export class EmailHelper {
5454
async getEmailForTemplateId(
5555
prefix: string,
5656
templateId: string,
57-
dateCutoff: Date
57+
dateCutoff: Date,
58+
extraTextToSearch: string
5859
) {
5960
const s3Items = await this.getAllS3Items(prefix);
6061

@@ -82,7 +83,7 @@ export class EmailHelper {
8283

8384
const content = await streamToString(Body);
8485

85-
if (content.includes(templateId)) {
86+
if (content.includes(templateId) && content.includes(extraTextToSearch)) {
8687
return content;
8788
}
8889
}

tests/test-team/template-mgmt-api-tests/submit-template.api.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ test.describe('POST /v1/template/:templateId/submit', () => {
200200

201201
await expect(async () => {
202202
const emailContents = await emailHelper.getEmailForTemplateId(
203-
process.env.TEST_TEMPLATE_SUBMITTED_EMAIL_PREFIX,
203+
process.env.TEST_EMAIL_BUCKET_PREFIX,
204204
templateId,
205-
start
205+
start,
206+
'template-submitted-sender'
206207
);
207208

208209
expect(emailContents).toContain(templateId);

0 commit comments

Comments
 (0)