Skip to content

Commit

Permalink
Merge pull request #41 from alma-cdk/beta-improve-tests-20241121
Browse files Browse the repository at this point in the history
fix: bug in getFeatureInfo & improve all the tests
  • Loading branch information
aripalo authored Nov 22, 2024
2 parents 6143af6 + 262d3f5 commit 4f80847
Show file tree
Hide file tree
Showing 17 changed files with 2,022 additions and 7 deletions.
68 changes: 68 additions & 0 deletions src/__test__/TestableProjectStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as cdk from "aws-cdk-lib";
import {
Project,
SmartStack,
AccountWrapper,
EnvironmentWrapper,
Account,
AccountType,
} from "..";

interface TestStackInSharedAccountProps {
defaultRegion?: string;
accounts: Record<string, Account>;
accountType: AccountType;
environmentType?: string;
stackProps?: cdk.StackProps;
}

export class TestableProjectStack extends SmartStack {
public readonly projectName: string;
public readonly stackConstructId: string;

constructor(props: TestStackInSharedAccountProps) {
const {
accounts,
accountType,
environmentType,
defaultRegion,
stackProps,
} = props;

const projectName = "test-project";

const project = new Project({
name: projectName,
author: {
name: "test",
email: "[email protected]",
},
defaultRegion,
accounts,
});

project.node.setContext("account-type", accountType);
project.node.setContext("account", accountType);

let wrapper: AccountWrapper | EnvironmentWrapper;

if (environmentType) {
project.node.setContext("environment-type", environmentType);
project.node.setContext("environment", environmentType);
project.node.setContext("env", environmentType);
wrapper = new EnvironmentWrapper(project);
} else {
wrapper = new AccountWrapper(project);
}

const stackConstructId = "TestStack";

super(wrapper, stackConstructId, {
description: "This stack is for testing purposes only",
...stackProps,
});

this.projectName = projectName;
this.stackConstructId = stackConstructId;
}
}
File renamed without changes.
15 changes: 15 additions & 0 deletions src/__test__/expectErrorMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Construct } from "constructs";

export function expectErrorMetadata(scope: Construct, matcher?: jest.Expect) {
if (matcher === undefined) {
expect(scope.node.metadata).toEqual([]);
} else {
expect(scope.node.metadata).toEqual(
expect.arrayContaining([
expect.objectContaining({
data: matcher,
}),
]),
);
}
}
120 changes: 120 additions & 0 deletions src/configurations/__snapshots__/accounts.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/configurations/__snapshots__/environments.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions src/configurations/accounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
AccountType,
emptyMockAccountProps,
AccountStrategy,
} from "./accounts";

test("AccountType", () => {
expect(AccountType).toMatchSnapshot();
});

test("emptyMockAccountProps", () => {
expect(emptyMockAccountProps).toMatchSnapshot();
});

describe("AccountStrategy", () => {
test("one", () => {
expect(
AccountStrategy.one({
shared: {
id: "123456789012",
config: {
key: "value",
},
},
}),
).toMatchSnapshot();
});

test("two", () => {
expect(
AccountStrategy.two({
dev: {
id: "123456789012",
config: {
foo: "bar",
},
},
prod: {
id: "213456789012",
config: {
baz: "quux",
},
},
}),
).toMatchSnapshot();
});

test("three", () => {
expect(
AccountStrategy.three({
dev: {
id: "111111111111",
config: {
cidr: "172.16.0.0/22",
},
},
preprod: {
id: "222222222222",
config: {
cidr: "172.16.4.0/22",
},
},
prod: {
id: "333333333333",
config: {
cidr: "172.16.8.0/22",
},
},
}),
).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/configurations/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface AccountStrategyThreeProps {
readonly [AccountType.PROD]: AccountConfiguration;
}

const emptyMockAccountProps: AccountConfiguration = {
export const emptyMockAccountProps: AccountConfiguration = {
id: "123456789012",
};

Expand Down
Loading

0 comments on commit 4f80847

Please sign in to comment.