|
| 1 | +/* |
| 2 | + * Copyright 2021 Typelevel |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package feral.lambda.events |
| 18 | + |
| 19 | +import io.circe.literal._ |
| 20 | +import io.circe.syntax._ |
| 21 | +import munit.FunSuite |
| 22 | + |
| 23 | +class S3BatchEventSuite extends FunSuite { |
| 24 | + |
| 25 | + test("decoder") { |
| 26 | + event.as[S3BatchEvent].toTry.get |
| 27 | + eventNullVersionId.as[S3BatchEvent].toTry.get |
| 28 | + } |
| 29 | + |
| 30 | + test("result encoder") { |
| 31 | + assertEquals(result.asJson, resultEncoded) |
| 32 | + } |
| 33 | + |
| 34 | + def event = json""" |
| 35 | + { |
| 36 | + "invocationSchemaVersion": "1.0", |
| 37 | + "invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo", |
| 38 | + "job": { |
| 39 | + "id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce" |
| 40 | + }, |
| 41 | + "tasks": [ |
| 42 | + { |
| 43 | + "taskId": "dGFza2lkZ29lc2hlcmUK", |
| 44 | + "s3Key": "customerImage1.jpg", |
| 45 | + "s3VersionId": "1", |
| 46 | + "s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket1" |
| 47 | + } |
| 48 | + ] |
| 49 | + } |
| 50 | + """ |
| 51 | + |
| 52 | + def eventNullVersionId = json""" |
| 53 | + { |
| 54 | + "invocationSchemaVersion": "1.0", |
| 55 | + "invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo", |
| 56 | + "job": { |
| 57 | + "id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce" |
| 58 | + }, |
| 59 | + "tasks": [ |
| 60 | + { |
| 61 | + "taskId": "dGFza2lkZ29lc2hlcmUK", |
| 62 | + "s3Key": "customerImage1.jpg", |
| 63 | + "s3VersionId": null, |
| 64 | + "s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket1" |
| 65 | + } |
| 66 | + ] |
| 67 | + } |
| 68 | + """ |
| 69 | + |
| 70 | + def result = S3BatchResult( |
| 71 | + "1.0", |
| 72 | + S3BatchResultResultCode.PermanentFailure, |
| 73 | + "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo", |
| 74 | + List( |
| 75 | + S3BatchResultResult( |
| 76 | + "dGFza2lkZ29lc2hlcmUK", |
| 77 | + S3BatchResultResultCode.Succeeded, |
| 78 | + List("Mary Major", "John Stiles").asJson.noSpaces)) |
| 79 | + ) |
| 80 | + |
| 81 | + def resultEncoded = json""" |
| 82 | + { |
| 83 | + "invocationSchemaVersion": "1.0", |
| 84 | + "treatMissingKeysAs" : "PermanentFailure", |
| 85 | + "invocationId" : "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo", |
| 86 | + "results": [ |
| 87 | + { |
| 88 | + "taskId": "dGFza2lkZ29lc2hlcmUK", |
| 89 | + "resultCode": "Succeeded", |
| 90 | + "resultString": "[\"Mary Major\",\"John Stiles\"]" |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + """ |
| 95 | +} |
0 commit comments