Skip to content

Commit 610cfdd

Browse files
committed
chore: clean up eslint configs, data load and package.json repo link
1 parent c5197b3 commit 610cfdd

File tree

9 files changed

+175
-25
lines changed

9 files changed

+175
-25
lines changed

unicorn_contracts/eslint.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import eslint from "@eslint/js";
22
import tseslint from "typescript-eslint";
33
import prettierConfig from 'eslint-config-prettier'
4-
// import prettierPlugin from 'eslint-plugin-prettier'
5-
64

75
export default tseslint.config(
86
{

unicorn_properties/eslint.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import eslint from "@eslint/js";
22
import tseslint from "typescript-eslint";
33
import prettierConfig from 'eslint-config-prettier'
4-
// import prettierPlugin from 'eslint-plugin-prettier'
5-
64

75
export default tseslint.config(
86
{

unicorn_properties/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "properties",
33
"version": "1.0.0",
44
"description": "Properties Module for Serverless Developer Experience Reference Architecture - Node",
5-
"repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs",
5+
"repository": "https://github.com/aws-samples/aws-serverless-developer-experience-workshop-typescript/tree/develop",
66
"license": "MIT",
77
"author": "Amazon.com, Inc.",
88
"main": "app.js",

unicorn_properties/tests/integration/_events_/put_event_contract_status_changed.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

unicorn_properties/tests/integration/_events_/put_event_publication_approval_requested.json

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT-0
3+
import {
4+
sleep,
5+
findOutputValue,
6+
clearDatabase,
7+
initializeDatabase,
8+
} from './helper';
9+
import {
10+
EventBridgeClient,
11+
PutEventsCommand,
12+
} from '@aws-sdk/client-eventbridge';
13+
import {
14+
SFNClient,
15+
ListExecutionsCommand,
16+
GetExecutionHistoryCommand,
17+
} from '@aws-sdk/client-sfn';
18+
19+
import ContractStatusChangedDraftEvent from '../events/eventbridge/contract_status_changed_event_contract_1_draft.json';
20+
import PublicationApprovalNonExistingContractEvent from '../events/eventbridge/publication_approval_requested_event_non_existing_contract.json';
21+
import PublicationApprovalInappropriateDescriptionEvent from '../events/eventbridge/publication_approval_requested_event_inappropriate_description.json';
22+
import PublicationApprovalInappropriateImagesEvent from '../events/eventbridge/publication_approval_requested_event_inappropriate_images.json';
23+
24+
describe('Tests that failed workflow', () => {
25+
beforeAll(async () => {
26+
await clearDatabase();
27+
await initializeDatabase();
28+
29+
// Create a draft contract
30+
const evb = new EventBridgeClient({
31+
region: process.env.AWS_DEFAULT_REGION,
32+
});
33+
await evb.send(
34+
new PutEventsCommand({ Entries: ContractStatusChangedDraftEvent })
35+
);
36+
await sleep(5000);
37+
}, 30000);
38+
39+
afterAll(async () => {
40+
await clearDatabase();
41+
}, 30000);
42+
43+
it('Fails if the contract does not exist', async () => {
44+
// Arrange
45+
const evb = new EventBridgeClient({
46+
region: process.env.AWS_DEFAULT_REGION,
47+
});
48+
const sfn = new SFNClient({ region: process.env.AWS_DEFAULT_REGION });
49+
50+
// Act
51+
await evb.send(
52+
new PutEventsCommand({
53+
Entries: PublicationApprovalNonExistingContractEvent,
54+
})
55+
);
56+
await sleep(5000);
57+
// Assert
58+
const listExecutionsCommand = new ListExecutionsCommand({
59+
stateMachineArn: await findOutputValue(
60+
'uni-prop-local-properties-approval',
61+
'ApprovalStateMachineArn'
62+
),
63+
statusFilter: 'FAILED',
64+
});
65+
const sfnResp = await sfn.send(listExecutionsCommand);
66+
67+
if (sfnResp.executions) {
68+
const getExecutionHistory = new GetExecutionHistoryCommand({
69+
executionArn: sfnResp.executions[0].executionArn,
70+
});
71+
const sfnHistory = await sfn.send(getExecutionHistory);
72+
// filter through sfnHistory looking for an event with "type": "FailStateEntered" and stateEnteredEventDetails.name set to "NotFound"
73+
const failStateEvent = sfnHistory.events?.find(
74+
(event: any) =>
75+
event.type === 'FailStateEntered' &&
76+
event.stateEnteredEventDetails?.name === 'NotFound'
77+
);
78+
79+
expect(failStateEvent).toBeTruthy();
80+
expect(failStateEvent?.type).toBe('FailStateEntered');
81+
expect(failStateEvent?.stateEnteredEventDetails?.name).toBe('NotFound');
82+
} else {
83+
throw new Error('No executions found');
84+
}
85+
}, 20000);
86+
87+
it('Flags content moderation for inappropriate description', async () => {
88+
// Arrange
89+
const evb = new EventBridgeClient({
90+
region: process.env.AWS_DEFAULT_REGION,
91+
});
92+
const sfn = new SFNClient({ region: process.env.AWS_DEFAULT_REGION });
93+
94+
// Act
95+
await evb.send(
96+
new PutEventsCommand({
97+
Entries: PublicationApprovalInappropriateDescriptionEvent,
98+
})
99+
);
100+
await sleep(5000);
101+
// Assert
102+
const listExecutionsCommand = new ListExecutionsCommand({
103+
stateMachineArn: await findOutputValue(
104+
'uni-prop-local-properties-approval',
105+
'ApprovalStateMachineArn'
106+
),
107+
statusFilter: 'SUCCEEDED',
108+
});
109+
const sfnResp = await sfn.send(listExecutionsCommand);
110+
111+
if (sfnResp.executions) {
112+
const getExecutionHistory = new GetExecutionHistoryCommand({
113+
executionArn: sfnResp.executions[0].executionArn,
114+
});
115+
const sfnHistory = await sfn.send(getExecutionHistory);
116+
const failStateEvent = sfnHistory.events?.find(
117+
(event: any) =>
118+
event.type === 'SucceedStateEntered' &&
119+
event.stateEnteredEventDetails?.name === 'Declined'
120+
);
121+
122+
expect(failStateEvent).toBeTruthy();
123+
expect(failStateEvent?.type).toBe('SucceedStateEntered');
124+
expect(failStateEvent?.stateEnteredEventDetails?.name).toBe('Declined');
125+
} else {
126+
throw new Error('No executions found');
127+
}
128+
}, 20000);
129+
130+
it('Flags content moderation for inappropriate images', async () => {
131+
// Arrange
132+
const evb = new EventBridgeClient({
133+
region: process.env.AWS_DEFAULT_REGION,
134+
});
135+
const sfn = new SFNClient({ region: process.env.AWS_DEFAULT_REGION });
136+
137+
// Act
138+
await evb.send(
139+
new PutEventsCommand({
140+
Entries: PublicationApprovalInappropriateImagesEvent,
141+
})
142+
);
143+
await sleep(5000);
144+
// Assert
145+
const listExecutionsCommand = new ListExecutionsCommand({
146+
stateMachineArn: await findOutputValue(
147+
'uni-prop-local-properties-approval',
148+
'ApprovalStateMachineArn'
149+
),
150+
statusFilter: 'SUCCEEDED',
151+
});
152+
const sfnResp = await sfn.send(listExecutionsCommand);
153+
154+
if (sfnResp.executions) {
155+
const getExecutionHistory = new GetExecutionHistoryCommand({
156+
executionArn: sfnResp.executions[0].executionArn,
157+
});
158+
const sfnHistory = await sfn.send(getExecutionHistory);
159+
const failStateEvent = sfnHistory.events?.find(
160+
(event: any) =>
161+
event.type === 'SucceedStateEntered' &&
162+
event.stateEnteredEventDetails?.name === 'Declined'
163+
);
164+
165+
expect(failStateEvent).toBeTruthy();
166+
expect(failStateEvent?.type).toBe('SucceedStateEntered');
167+
expect(failStateEvent?.stateEnteredEventDetails?.name).toBe('Declined');
168+
} else {
169+
throw new Error('No executions found');
170+
}
171+
}, 20000);
172+
});

unicorn_web/data/load_data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ STACK_NAME="uni-prop-local-web"
66
JSON_FILE="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/property_data.json"
77
echo "JSON_FILE: '${JSON_FILE}'"
88

9-
DDB_TBL_NAME="$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].Outputs[?starts_with(OutputKey, `WebTableName`)].OutputValue' --output text)"
9+
DDB_TBL_NAME="$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].Outputs[?ends_with(OutputKey, `WebTableName`)].OutputValue' --output text)"
1010
echo "DDB_TABLE_NAME: '${DDB_TBL_NAME}'"
1111

1212
echo "LOADING ITEMS TO DYNAMODB:"

unicorn_web/eslint.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import eslint from "@eslint/js";
22
import tseslint from "typescript-eslint";
33
import prettierConfig from 'eslint-config-prettier'
4-
// import prettierPlugin from 'eslint-plugin-prettier'
5-
64

75
export default tseslint.config(
86
{

unicorn_web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "contracts",
33
"version": "1.0.0",
44
"description": "Contracts Module for Serverless Developer Experience Reference Architecture - Node",
5-
"repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs",
5+
"repository": "https://github.com/aws-samples/aws-serverless-developer-experience-workshop-typescript/tree/develop",
66
"license": "MIT",
77
"author": "Amazon.com, Inc.",
88
"main": "app.js",

0 commit comments

Comments
 (0)