-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from alma-cdk/beta-improve-tests-20241121
fix: bug in getFeatureInfo & improve all the tests
- Loading branch information
Showing
17 changed files
with
2,022 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
]), | ||
); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/configurations/__snapshots__/environments.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.