Skip to content

Commit

Permalink
AT-10890: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rddimon committed Nov 23, 2023
1 parent aa374d0 commit fa4cbbd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/aws/route53-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Route53Wrapper {
*/
public async changeResourceRecordSet(action: ChangeAction, domain: DomainConfig): Promise<void> {
if (domain.createRoute53Record === false) {
Logging.logInfo(`Skipping ${action === "DELETE" ? "removal" : "creation"} of Route53 record.`);
Logging.logInfo(`Skipping ${action === ChangeAction.DELETE ? "removal" : "creation"} of Route53 record.`);
return;
}
// Set up parameters
Expand Down Expand Up @@ -124,7 +124,7 @@ class Route53Wrapper {
hostedZoneIds = [route53HostedZoneId];
}

const recordsToCreate = domain.createRoute53IPv6Record ? [RRType.AAAA] : [RRType.A];
const recordsToCreate = domain.createRoute53IPv6Record ? [RRType.A, RRType.AAAA] : [RRType.A];
for (const hostedZoneId of hostedZoneIds) {
const changes = recordsToCreate.map((Type) => ({
Action: action,
Expand Down
20 changes: 11 additions & 9 deletions test/unit-tests/aws/api-gateway-v1-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import {
APIGatewayClient, CreateBasePathMappingCommand,
CreateDomainNameCommand, DeleteBasePathMappingCommand,
DeleteDomainNameCommand, GetBasePathMappingsCommand,
GetDomainNameCommand, UpdateBasePathMappingCommand
GetDomainNameCommand, PatchOperation, UpdateBasePathMappingCommand,
Op, EndpointType, SecurityPolicy
} from "@aws-sdk/client-api-gateway";
import {consoleOutput, expect, getDomainConfig} from "../base";
import Globals from "../../../src/globals";
import DomainConfig = require("../../../src/models/domain-config");
import APIGatewayV1Wrapper = require("../../../src/aws/api-gateway-v1-wrapper");
import DomainInfo = require("../../../src/models/domain-info");
import ApiGatewayMap = require("../../../src/models/api-gateway-map");
import {Type} from "@aws-sdk/client-s3";


describe("API Gateway V1 wrapper checks", () => {
Expand Down Expand Up @@ -52,9 +54,9 @@ describe("API Gateway V1 wrapper checks", () => {
const expectedParams = {
domainName: dc.givenDomainName,
endpointConfiguration: {
types: [dc.endpointType],
types: [EndpointType.EDGE],
},
securityPolicy: dc.securityPolicy,
securityPolicy: SecurityPolicy.TLS_1_0,
tags: {
...Globals.serverless.service.provider.stackTags,
...Globals.serverless.service.provider.tags,
Expand Down Expand Up @@ -93,9 +95,9 @@ describe("API Gateway V1 wrapper checks", () => {
const expectedParams = {
domainName: dc.givenDomainName,
endpointConfiguration: {
types: [dc.endpointType],
types: [EndpointType.REGIONAL],
},
securityPolicy: dc.securityPolicy,
securityPolicy: SecurityPolicy.TLS_1_0,
tags: {
...Globals.serverless.service.provider.stackTags,
...Globals.serverless.service.provider.tags,
Expand Down Expand Up @@ -135,9 +137,9 @@ describe("API Gateway V1 wrapper checks", () => {
const expectedParams = {
domainName: dc.givenDomainName,
endpointConfiguration: {
types: [dc.endpointType],
types: [EndpointType.REGIONAL],
},
securityPolicy: dc.securityPolicy,
securityPolicy: SecurityPolicy.TLS_1_0,
tags: {
...Globals.serverless.service.provider.stackTags,
...Globals.serverless.service.provider.tags,
Expand Down Expand Up @@ -437,12 +439,12 @@ describe("API Gateway V1 wrapper checks", () => {
};

await apiGatewayV1Wrapper.updateBasePathMapping(dc);

const a: PatchOperation = null;
const expectedParams = {
basePath: dc.apiMapping.basePath,
domainName: dc.givenDomainName,
patchOperations: [{
op: "replace",
op: Op.replace,
path: "/basePath",
value: dc.basePath,
}]
Expand Down
16 changes: 8 additions & 8 deletions test/unit-tests/aws/api-gateway-v2-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {mockClient} from "aws-sdk-client-mock";
import {
ApiGatewayV2Client, CreateApiMappingCommand,
CreateDomainNameCommand, DeleteApiMappingCommand,
DeleteDomainNameCommand, GetApiMappingsCommand,
GetDomainNameCommand, UpdateApiMappingCommand
DeleteDomainNameCommand, EndpointType, GetApiMappingsCommand,
GetDomainNameCommand, SecurityPolicy, UpdateApiMappingCommand
} from "@aws-sdk/client-apigatewayv2";
import {consoleOutput, expect, getDomainConfig} from "../base";
import Globals from "../../../src/globals";
Expand Down Expand Up @@ -54,8 +54,8 @@ describe("API Gateway V2 wrapper checks", () => {
DomainNameConfigurations: [
{
CertificateArn: dc.certificateArn,
EndpointType: dc.endpointType,
SecurityPolicy: dc.securityPolicy
EndpointType: EndpointType.EDGE,
SecurityPolicy: SecurityPolicy.TLS_1_0
}
],
Tags: {
Expand Down Expand Up @@ -97,8 +97,8 @@ describe("API Gateway V2 wrapper checks", () => {
DomainNameConfigurations: [
{
CertificateArn: dc.certificateArn,
EndpointType: dc.endpointType,
SecurityPolicy: dc.securityPolicy
EndpointType: EndpointType.REGIONAL,
SecurityPolicy: SecurityPolicy.TLS_1_0
}
],
Tags: {
Expand Down Expand Up @@ -141,8 +141,8 @@ describe("API Gateway V2 wrapper checks", () => {
DomainNameConfigurations: [
{
CertificateArn: dc.certificateArn,
EndpointType: dc.endpointType,
SecurityPolicy: dc.securityPolicy
EndpointType: EndpointType.REGIONAL,
SecurityPolicy: SecurityPolicy.TLS_1_0
}
],
Tags: {
Expand Down
61 changes: 33 additions & 28 deletions test/unit-tests/aws/route53-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import {consoleOutput, expect, getDomainConfig} from "../base";
import Globals from "../../../src/globals";
import Route53Wrapper = require("../../../src/aws/route53-wrapper");
import {mockClient} from "aws-sdk-client-mock";
import {ChangeResourceRecordSetsCommand, ListHostedZonesCommand, Route53Client} from "@aws-sdk/client-route-53";
import {
ChangeAction,
ChangeResourceRecordSetsCommand,
ListHostedZonesCommand, ResourceRecordSetRegion,
Route53Client, RRType
} from "@aws-sdk/client-route-53";
import DomainConfig = require("../../../src/models/domain-config");

describe("Route53 wrapper checks", () => {
Expand Down Expand Up @@ -263,7 +268,7 @@ describe("Route53 wrapper checks", () => {
createRoute53Record: false
}));

const actualResult = await new Route53Wrapper().changeResourceRecordSet("UPSERT", dc);
const actualResult = await new Route53Wrapper().changeResourceRecordSet(ChangeAction.UPSERT, dc);
expect(actualResult).to.equal(undefined);
});

Expand All @@ -283,33 +288,33 @@ describe("Route53 wrapper checks", () => {
domainName: "test_domain"
}));

await new Route53Wrapper().changeResourceRecordSet("UPSERT", dc);
await new Route53Wrapper().changeResourceRecordSet(ChangeAction.UPSERT, dc);

const expectedParams = {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "A",
Type: RRType.A,
},
},
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "AAAA",
Type: RRType.AAAA,
},
},
],
Expand Down Expand Up @@ -341,36 +346,36 @@ describe("Route53 wrapper checks", () => {
}
}));

await new Route53Wrapper().changeResourceRecordSet("UPSERT", dc);
await new Route53Wrapper().changeResourceRecordSet(ChangeAction.UPSERT, dc);

const expectedParams = {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "A",
Region: 'test_region',
Type: RRType.A,
Region: ResourceRecordSetRegion.us_east_1,
SetIdentifier: 'test_domain'
},
},
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "AAAA",
Region: 'test_region',
Type: RRType.AAAA,
Region: ResourceRecordSetRegion.us_east_1,
SetIdentifier: 'test_domain'
},
},
Expand Down Expand Up @@ -404,35 +409,35 @@ describe("Route53 wrapper checks", () => {
}
}));

await new Route53Wrapper().changeResourceRecordSet("UPSERT", dc);
await new Route53Wrapper().changeResourceRecordSet(ChangeAction.UPSERT, dc);

const expectedParams = {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "A",
Type: RRType.A,
Weight: 1,
SetIdentifier: 'test_domain'
},
},
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: "test_host_id",
},
Name: "test_domain",
Type: "AAAA",
Type: RRType.AAAA,
Weight: 1,
SetIdentifier: 'test_domain'
},
Expand Down Expand Up @@ -472,33 +477,33 @@ describe("Route53 wrapper checks", () => {
splitHorizonDns: true
}));

await new Route53Wrapper().changeResourceRecordSet("UPSERT", dc);
await new Route53Wrapper().changeResourceRecordSet(ChangeAction.UPSERT, dc);

const expectedParams1 = {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: publicZone,
},
Name: "test_domain",
Type: "A",
Type: RRType.A,
},
},
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: publicZone,
},
Name: "test_domain",
Type: "AAAA",
Type: RRType.AAAA,
},
},
],
Expand All @@ -513,27 +518,27 @@ describe("Route53 wrapper checks", () => {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: publicZone,
},
Name: "test_domain",
Type: "A",
Type: RRType.A
},
},
{
Action: "UPSERT",
Action: ChangeAction.UPSERT,
ResourceRecordSet: {
AliasTarget: {
DNSName: "test_domain",
EvaluateTargetHealth: false,
HostedZoneId: publicZone,
},
Name: "test_domain",
Type: "AAAA",
Type: RRType.AAAA,
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion test/unit-tests/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import spies = require("chai-spies");
import Globals from "../../src/globals";
import {ServerlessOptions, ServerlessUtils} from "../../src/types";
import ServerlessCustomDomain = require("../../src");
import {ResourceRecordSetRegion} from "@aws-sdk/client-route-53";

chai.use(spies);

Expand Down Expand Up @@ -100,7 +101,7 @@ const getV3Utils = () => {
}
}

Globals.currentRegion = "test_region";
Globals.currentRegion = ResourceRecordSetRegion.us_east_1;
Globals.options = {
stage: "test"
};
Expand Down

0 comments on commit fa4cbbd

Please sign in to comment.