Skip to content

Commit 7d1415e

Browse files
authored
fix canary tests (#2530)
* fix canary tests * fix that * fix that * try this * try this * try this
1 parent 7348f29 commit 7d1415e

File tree

4 files changed

+82
-34
lines changed

4 files changed

+82
-34
lines changed

.changeset/orange-steaks-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/ai-constructs': patch
3+
---
4+
5+
Adapt unit test to handle new cdk release

package-lock.json

Lines changed: 26 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ai-constructs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
},
3636
"devDependencies": {
3737
"@aws-amplify/backend-output-storage": "^1.1.4",
38+
"@types/lodash.transform": "^4.6.9",
39+
"lodash.transform": "^4.6.0",
3840
"typescript": "^5.0.0"
3941
},
4042
"peerDependencies": {

packages/ai-constructs/src/conversation/conversation_handler_construct.test.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path';
77
import { StackMetadataBackendOutputStorageStrategy } from '@aws-amplify/backend-output-storage';
88
import { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
99
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
10+
import transform from 'lodash.transform';
1011

1112
void describe('Conversation Handler Function construct', () => {
1213
void it('creates handler with log group with JWT token redacting policy', () => {
@@ -20,40 +21,68 @@ void describe('Conversation Handler Function construct', () => {
2021
assert.strictEqual(Object.values(logGroups).length, 1);
2122
const logGroupLogicalId = Object.keys(logGroups)[0];
2223
const logGroup = Object.values(logGroups)[0];
23-
assert.deepStrictEqual(logGroup.Properties.DataProtectionPolicy, {
24-
name: 'data-protection-policy-cdk',
25-
description: 'cdk generated data protection policy',
26-
version: '2021-06-01',
27-
configuration: {
28-
customDataIdentifier: [
24+
let expectedDataProtectionPolicy: Record<string, unknown> = {
25+
Name: 'data-protection-policy-cdk',
26+
Description: 'cdk generated data protection policy',
27+
Version: '2021-06-01',
28+
Configuration: {
29+
CustomDataIdentifier: [
2930
{
30-
name: 'JWTToken',
31-
regex: 'ey[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*',
31+
Name: 'JWTToken',
32+
Regex: 'ey[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*',
3233
},
3334
],
3435
},
35-
statement: [
36+
Statement: [
3637
{
37-
sid: 'audit-statement-cdk',
38-
dataIdentifier: ['JWTToken'],
39-
operation: {
40-
audit: {
41-
findingsDestination: {},
38+
Sid: 'audit-statement-cdk',
39+
DataIdentifier: ['JWTToken'],
40+
Operation: {
41+
Audit: {
42+
FindingsDestination: {},
4243
},
4344
},
4445
},
4546
{
46-
sid: 'redact-statement-cdk',
47-
dataIdentifier: ['JWTToken'],
48-
operation: {
47+
Sid: 'redact-statement-cdk',
48+
DataIdentifier: ['JWTToken'],
49+
Operation: {
4950
// eslint-disable-next-line spellcheck/spell-checker
50-
deidentify: {
51-
maskConfig: {},
51+
Deidentify: {
52+
MaskConfig: {},
5253
},
5354
},
5455
},
5556
],
56-
});
57+
};
58+
if ('name' in logGroup.Properties.DataProtectionPolicy) {
59+
// we may run some tests with older CDK version.
60+
// in that case the expected keys are all lower case, see https://github.com/aws/aws-cdk/pull/33462
61+
const keysToCamelCase = (target: Record<string, unknown>) =>
62+
transform(
63+
target,
64+
(
65+
result: { [x: string | number]: unknown },
66+
val: unknown,
67+
key: string | number
68+
) => {
69+
if (typeof val === 'object') {
70+
val = keysToCamelCase(val as Record<string, unknown>);
71+
}
72+
if (typeof key === 'string') {
73+
key = `${key.slice(0, 1).toLowerCase()}${key.slice(1)}`;
74+
}
75+
result[key] = val;
76+
}
77+
);
78+
expectedDataProtectionPolicy = keysToCamelCase(
79+
expectedDataProtectionPolicy
80+
);
81+
}
82+
assert.deepStrictEqual(
83+
logGroup.Properties.DataProtectionPolicy,
84+
expectedDataProtectionPolicy
85+
);
5786
template.hasResourceProperties('AWS::Lambda::Function', {
5887
Handler: 'index.handler',
5988
LoggingConfig: {

0 commit comments

Comments
 (0)