"use strict";
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */
Object.defineProperty(exports, "__esModule", { value: true });
const aws_cdk_lib_1 = require("aws-cdk-lib");
const assertions_1 = require("aws-cdk-lib/assertions");
const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
const aws_elasticloadbalancingv2_1 = require("aws-cdk-lib/aws-elasticloadbalancingv2");
const aws_s3_1 = require("aws-cdk-lib/aws-s3");
const RSWApplicationLoadBalancer_1 = require("./RSWApplicationLoadBalancer");
describe('RSWApplicationLoadBalancer tests', () => {
    beforeAll(() => {
        jest.spyOn(aws_elasticloadbalancingv2_1.ApplicationLoadBalancer.prototype, 'logAccessLogs').mockImplementation();
    });
    it('has the correct alb properties when given no subnets', () => {
        const stack = new aws_cdk_lib_1.Stack();
        const rswApplicationLoadBalancerProps = {
            vpc: new aws_ec2_1.Vpc(stack, 'testVPC'),
            subnets: {},
            internetFacing: true,
            accessLogsBucket: new aws_s3_1.Bucket(stack, 'testS3AccessLogsBucket', {
                objectOwnership: aws_s3_1.ObjectOwnership.OBJECT_WRITER
            })
        };
        new RSWApplicationLoadBalancer_1.RSWApplicationLoadBalancer(stack, 'TestRSWApplicationLoadBalancer', rswApplicationLoadBalancerProps);
        const template = assertions_1.Template.fromStack(stack);
        template.resourceCountIs('AWS::ElasticLoadBalancingV2::LoadBalancer', 1);
        template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
            LoadBalancerAttributes: [
                {
                    Key: 'deletion_protection.enabled',
                    Value: 'false'
                }
            ],
            Scheme: 'internet-facing',
            Type: 'application'
        });
        template.resourceCountIs('AWS::EC2::SecurityGroup', 1);
        template.hasResourceProperties('AWS::EC2::SecurityGroup', {
            SecurityGroupEgress: [
                {
                    CidrIp: '255.255.255.255/32',
                    Description: 'Disallow all traffic',
                    FromPort: 252,
                    IpProtocol: 'icmp',
                    ToPort: 86
                }
            ]
        });
    });
    it('has the correct alb properties when given public subnets', () => {
        const stack = new aws_cdk_lib_1.Stack();
        const vpc = new aws_ec2_1.Vpc(stack, 'testVPC');
        const rswApplicationLoadBalancerProps = {
            vpc: vpc,
            subnets: vpc.selectSubnets({ subnetType: aws_ec2_1.SubnetType.PUBLIC }),
            internetFacing: true,
            accessLogsBucket: new aws_s3_1.Bucket(stack, 'testS3AccessLogsBucket', {
                objectOwnership: aws_s3_1.ObjectOwnership.OBJECT_WRITER
            })
        };
        new RSWApplicationLoadBalancer_1.RSWApplicationLoadBalancer(stack, 'TestRSWApplicationLoadBalancer', rswApplicationLoadBalancerProps);
        const template = assertions_1.Template.fromStack(stack);
        template.resourceCountIs('AWS::ElasticLoadBalancingV2::LoadBalancer', 1);
        template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
            LoadBalancerAttributes: [
                {
                    Key: 'deletion_protection.enabled',
                    Value: 'false'
                }
            ],
            Scheme: 'internet-facing',
            Type: 'application'
        });
        template.resourceCountIs('AWS::EC2::SecurityGroup', 1);
        template.hasResourceProperties('AWS::EC2::SecurityGroup', {
            SecurityGroupEgress: [
                {
                    CidrIp: '255.255.255.255/32',
                    Description: 'Disallow all traffic',
                    FromPort: 252,
                    IpProtocol: 'icmp',
                    ToPort: 86
                }
            ]
        });
    });
    it('has the correct alb properties when given private subnets and internetFacing as false', () => {
        const stack = new aws_cdk_lib_1.Stack();
        const vpc = new aws_ec2_1.Vpc(stack, 'testVPC');
        const rswApplicationLoadBalancerProps = {
            vpc: vpc,
            subnets: vpc.selectSubnets({ subnetType: aws_ec2_1.SubnetType.PRIVATE_WITH_NAT }),
            internetFacing: false,
            accessLogsBucket: new aws_s3_1.Bucket(stack, 'testS3AccessLogsBucket', {
                objectOwnership: aws_s3_1.ObjectOwnership.OBJECT_WRITER
            })
        };
        new RSWApplicationLoadBalancer_1.RSWApplicationLoadBalancer(stack, 'TestRSWApplicationLoadBalancer', rswApplicationLoadBalancerProps);
        const template = assertions_1.Template.fromStack(stack);
        template.resourceCountIs('AWS::ElasticLoadBalancingV2::LoadBalancer', 1);
        template.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
            LoadBalancerAttributes: [
                {
                    Key: 'deletion_protection.enabled',
                    Value: 'false'
                }
            ],
            Scheme: 'internal',
            Type: 'application'
        });
        template.resourceCountIs('AWS::EC2::SecurityGroup', 1);
        template.hasResourceProperties('AWS::EC2::SecurityGroup', {
            SecurityGroupEgress: [
                {
                    CidrIp: '255.255.255.255/32',
                    Description: 'Disallow all traffic',
                    FromPort: 252,
                    IpProtocol: 'icmp',
                    ToPort: 86
                }
            ]
        });
    });
});
//# sourceMappingURL=RSWApplicationLoadBalancer.test.js.map