diff --git a/Sources/AWSLambdaEvents/SES.swift b/Sources/AWSLambdaEvents/SES.swift index 789e30b..f402883 100644 --- a/Sources/AWSLambdaEvents/SES.swift +++ b/Sources/AWSLambdaEvents/SES.swift @@ -98,6 +98,7 @@ public struct SESEvent: Decodable, Sendable { case pass = "PASS" case fail = "FAIL" case gray = "GRAY" + case disabled = "DISABLED" case processingFailed = "PROCESSING_FAILED" } } diff --git a/Tests/AWSLambdaEventsTests/SESTests.swift b/Tests/AWSLambdaEventsTests/SESTests.swift index 5d2c935..50c105f 100644 --- a/Tests/AWSLambdaEventsTests/SESTests.swift +++ b/Tests/AWSLambdaEventsTests/SESTests.swift @@ -89,8 +89,80 @@ struct SESTests { } """ - @Test func simpleEventFromJSON() throws { - let data = Data(SESTests.eventBody.utf8) + static let eventBodyDisabled = """ + { + "Records": [ + { + "eventSource": "aws:ses", + "eventVersion": "1.0", + "ses": { + "mail": { + "commonHeaders": { + "date": "Wed, 7 Oct 2015 12:34:56 -0700", + "from": [ + "Jane Doe " + ], + "messageId": "<0123456789example.com>", + "returnPath": "janedoe@example.com", + "subject": "Test Subject", + "to": [ + "johndoe@example.com" + ] + }, + "destination": [ + "johndoe@example.com" + ], + "headers": [ + { + "name": "Return-Path", + "value": "" + }, + { + "name": "Received", + "value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.eu-west-1.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for johndoe@example.com; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)" + } + ], + "headersTruncated": true, + "messageId": "5h5auqp1oa1bg49b2q8f8tmli1oju8pcma2haao1", + "source": "janedoe@example.com", + "timestamp": "1970-01-01T00:00:00.000Z" + }, + "receipt": { + "action": { + "functionArn": "arn:aws:lambda:eu-west-1:123456789012:function:Example", + "invocationType": "Event", + "type": "Lambda" + }, + "dkimVerdict": { + "status": "PASS" + }, + "processingTimeMillis": 574, + "recipients": [ + "test@swift-server.com", + "test2@swift-server.com" + ], + "spamVerdict": { + "status": "DISABLED" + }, + "spfVerdict": { + "status": "PROCESSING_FAILED" + }, + "timestamp": "1970-01-01T00:00:00.000Z", + "virusVerdict": { + "status": "FAIL" + } + } + } + } + ] + } + """ + + @Test(arguments: [ + (SESTests.eventBody, SESEvent.Status.pass), (SESTests.eventBodyDisabled, SESEvent.Status.disabled), + ]) + func simpleEventFromJSON(input: (String, SESEvent.Status)) throws { + let data = Data(input.0.utf8) let event = try JSONDecoder().decode(SESEvent.self, from: data) let record = try #require(event.records.first) @@ -122,7 +194,7 @@ struct SESTests { #expect(record.ses.receipt.processingTimeMillis == 574) #expect(record.ses.receipt.recipients[0] == "test@swift-server.com") #expect(record.ses.receipt.recipients[1] == "test2@swift-server.com") - #expect(record.ses.receipt.spamVerdict.status == .pass) + #expect(record.ses.receipt.spamVerdict.status == input.1) #expect(record.ses.receipt.spfVerdict.status == .processingFailed) #expect(record.ses.receipt.timestamp.description == "1970-01-01 00:00:00 +0000") #expect(record.ses.receipt.virusVerdict.status == .fail)