Skip to content

Commit 8d14dad

Browse files
committed
chore: fix tests, updates dependencies, switch to async/await style handlers.
1 parent bd71c54 commit 8d14dad

25 files changed

Lines changed: 2898 additions & 1988 deletions

pnpm-lock.yaml

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

unicorn_approvals/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module.exports = {
88
testMatch: ["**/tests/unit/*.test.ts", "**/tests/integration/*.test.ts"],
99
testPathIgnorePatterns: ["/node_modules/"],
1010
testEnvironment: "node",
11+
testSequencer: "./tests/alphabetical-sequencer.js",
1112
coverageProvider: "v8",
1213
};

unicorn_approvals/package.json

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,40 @@
1010
"build": "sam build",
1111
"compile": "tsc",
1212
"deploy": "sam build && sam deploy --no-confirm-changeset",
13+
"format": "prettier --write '**/*.ts'",
1314
"lint": "eslint --ext .ts --quiet --fix",
1415
"test": "jest --runInBand",
1516
"unit": "jest --config=jest.config.test.unit.ts"
1617
},
1718
"dependencies": {
18-
"@aws-lambda-powertools/commons": "^2.20.0",
19-
"@aws-lambda-powertools/logger": "^2.20.0",
20-
"@aws-lambda-powertools/metrics": "^2.20.0",
21-
"@aws-lambda-powertools/tracer": "^2.20.0",
22-
"@aws-sdk/client-dynamodb": "^3.812.0",
23-
"@aws-sdk/client-sfn": "^3.812.0",
24-
"@aws-sdk/util-dynamodb": "^3.812.0",
19+
"@aws-lambda-powertools/commons": "^2.25.2",
20+
"@aws-lambda-powertools/logger": "^2.25.2",
21+
"@aws-lambda-powertools/metrics": "^2.25.2",
22+
"@aws-lambda-powertools/tracer": "^2.25.2",
23+
"@aws-sdk/client-dynamodb": "^3.883.0",
24+
"@aws-sdk/client-sfn": "^3.883.0",
25+
"@aws-sdk/util-dynamodb": "^3.883.0",
2526
"aws-lambda": "^1.0.7"
2627
},
2728
"devDependencies": {
28-
"@aws-sdk/client-cloudformation": "^3.812.0",
29-
"@aws-sdk/client-cloudwatch-logs": "^3.812.0",
30-
"@aws-sdk/client-eventbridge": "^3.812.0",
31-
"@aws-sdk/lib-dynamodb": "^3.814.0",
32-
"@types/aws-lambda": "^8.10.149",
33-
"@types/jest": "^29.5.14",
34-
"@types/node": "^22.15.21",
29+
"@aws-sdk/client-cloudformation": "^3.883.0",
30+
"@aws-sdk/client-cloudwatch-logs": "^3.883.0",
31+
"@aws-sdk/client-eventbridge": "^3.883.0",
32+
"@aws-sdk/lib-dynamodb": "^3.883.0",
33+
"@types/aws-lambda": "^8.10.152",
34+
"@types/jest": "^30.0.0",
35+
"@types/node": "^22.18.1",
3536
"aws-sdk-client-mock": "^4.1.0",
36-
"esbuild": "^0.25.4",
37+
"esbuild": "^0.25.9",
3738
"esbuild-jest": "^0.5.0",
38-
"eslint": "^9.27.0",
39-
"eslint-config-prettier": "^10.1.5",
40-
"globals": "^16.1.0",
41-
"jest": "^29.7.0",
42-
"prettier": "^3.5.3",
43-
"ts-jest": "^29.3.4",
39+
"eslint": "^9.35.0",
40+
"eslint-config-prettier": "^10.1.8",
41+
"globals": "^16.3.0",
42+
"jest": "^30.1.3",
43+
"prettier": "^3.6.2",
44+
"ts-jest": "^29.4.1",
4445
"ts-node": "^10.9.2",
45-
"typescript": "^5.8.3",
46-
"typescript-eslint": "^8.32.1"
46+
"typescript": "^5.9.2",
47+
"typescript-eslint": "^8.43.0"
4748
}
4849
}

unicorn_approvals/src/approvals_service/contractStatusChangedEventHandler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,10 @@ class ContractStatusChangedFunction implements LambdaInterface {
100100
}
101101
}
102102

103-
export const myFunction = new ContractStatusChangedFunction();
104-
export const lambdaHandler = myFunction.handler.bind(myFunction);
103+
const myFunction = new ContractStatusChangedFunction();
104+
export const lambdaHandler = async (
105+
event: EventBridgeEvent<string, ContractStatusChanged>,
106+
context: Context
107+
): Promise<void> => {
108+
return myFunction.handler(event, context);
109+
};

unicorn_approvals/src/approvals_service/propertiesApprovalSyncFunction.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,10 @@ class PropertiesApprovalSyncFunction implements LambdaInterface {
143143
}
144144
}
145145

146-
export const myFunction = new PropertiesApprovalSyncFunction();
147-
export const lambdaHandler = myFunction.handler.bind(myFunction);
146+
const myFunction = new PropertiesApprovalSyncFunction();
147+
export const lambdaHandler = async (
148+
event: DynamoDBStreamEvent,
149+
context: Context
150+
): Promise<DynamoDBBatchResponse> => {
151+
return myFunction.handler(event, context);
152+
};

unicorn_approvals/src/approvals_service/waitForContractApprovalFunction.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,10 @@ class ContractStatusCheckerFunction implements LambdaInterface {
153153
}
154154
}
155155

156-
export const myFunction = new ContractStatusCheckerFunction();
157-
export const lambdaHandler = myFunction.handler.bind(myFunction);
156+
const myFunction = new ContractStatusCheckerFunction();
157+
export const lambdaHandler = async (
158+
event: any,
159+
context: Context
160+
): Promise<StepFunctionsResponse> => {
161+
return myFunction.handler(event, context);
162+
};

unicorn_approvals/template.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Globals:
6262
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornApprovalsNamespace}}"
6363
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
6464
LOG_LEVEL: INFO # Log level for Logger
65+
NODE_OPTIONS: !If [IsProd, "", "--enable-source-maps"] # Disable source maps for Node.js in prod
6566
Tags:
6667
stage: !Ref Stage
6768
project: !FindInMap [Constants, ProjectName, Value]
@@ -125,9 +126,9 @@ Resources:
125126
# Manage esbuild properties
126127
BuildMethod: esbuild
127128
BuildProperties:
128-
Minify: false
129-
Target: es2020
130-
Sourcemap: true
129+
Minify: !If [IsProd, true, false] # Minify in prod
130+
Target: "es2020"
131+
Sourcemap: !If [IsProd, false, true] # Enable sourcemaps for debugging in non-prod stages
131132
EntryPoints:
132133
- contractStatusChangedEventHandler.ts
133134

@@ -181,9 +182,9 @@ Resources:
181182
# Manage esbuild properties
182183
BuildMethod: esbuild
183184
BuildProperties:
184-
Minify: false
185-
Target: es2020
186-
Sourcemap: true
185+
Minify: !If [IsProd, true, false] # Minify in prod
186+
Target: "es2020"
187+
Sourcemap: !If [IsProd, false, true] # Enable sourcemaps for debugging in non-prod stages
187188
EntryPoints:
188189
- propertiesApprovalSyncFunction.ts
189190

@@ -209,9 +210,9 @@ Resources:
209210
# Manage esbuild properties
210211
BuildMethod: esbuild
211212
BuildProperties:
212-
Minify: false
213-
Target: es2020
214-
Sourcemap: true
213+
Minify: !If [IsProd, true, false] # Minify in prod
214+
Target: "es2020"
215+
Sourcemap: !If [IsProd, false, true] # Enable sourcemaps for debugging in non-prod stages
215216
EntryPoints:
216217
- waitForContractApprovalFunction.ts
217218

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Sequencer = require('@jest/test-sequencer').default;
2+
3+
class AlphabeticalSequencer extends Sequencer {
4+
sort(tests) {
5+
return tests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
6+
}
7+
}
8+
9+
module.exports = AlphabeticalSequencer;

unicorn_approvals/tests/integration/approval_workflow.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ describe('Tests that failed workflow', () => {
169169
throw new Error('No executions found');
170170
}
171171
}, 20000);
172-
});
172+
});

unicorn_approvals/tests/integration/contract_status_changed_event.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ describe('Testing draft contract event handling', () => {
8282
if (!ddbResp.Item) throw new Error('Contract not found');
8383
expect(ddbResp.Item.contract_status?.S).toBe('APPROVED');
8484
}, 30000);
85-
});
85+
});

0 commit comments

Comments
 (0)