Skip to content

Commit d519a25

Browse files
feat(gen2-migration): add gen1 and gen2 test scripts for mood-board app (#14729)
test: add gen1 and gen2 test scripts for mood-board app Add e2e test scripts for the mood-board migration app, following the same pattern as the other test apps (project-boards, discussions, etc.). New files: - test-utils.ts: shared test functions and orchestrator covering Board/MoodItem CRUD, moodItemsByBoardID index, getRandomEmoji and getKinesisEvents Lambda resolvers, and S3 storage operations. - gen1-test-script.ts: validates Gen1 deployment - gen2-test-script.ts: validates Gen2 deployment Bug fixes found during testing: - schema.graphql: fixed function name case mismatch (moodboardKinesisreader -> moodboardKinesisReader) that caused a Lambda 404 at runtime. - configure.sh: removed configure-schema.sh call that hardcoded the API directory name as "moodboard", which doesn't match the deployment-name-based directory created by amplify add api. The category initializer already handles schema updates dynamically. Validated by running the full migration CLI pipeline: gen1 post-push, gen2 post-generate, and gen1 post-refactor all passed with zero failures. --- Prompt: create a gen1 test script and gen2 test script for mood-board app
1 parent 954c1db commit d519a25

File tree

5 files changed

+619
-2
lines changed

5 files changed

+619
-2
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/bash
22
set -euxo pipefail
3-
./configure-schema.sh
43
./configure-functions.sh
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Gen1 Test Script for Mood Board App
3+
*
4+
* This script tests all functionality for Amplify Gen1:
5+
* 1. GraphQL Queries (Boards, MoodItems)
6+
* 2. Board CRUD Operations
7+
* 3. MoodItem CRUD Operations
8+
* 4. Lambda Function Operations (getRandomEmoji, getKinesisEvents)
9+
* 5. S3 Storage Operations
10+
* 6. Cleanup (Delete Test Data)
11+
*
12+
* Credentials are provisioned automatically via Cognito AdminCreateUser + AdminSetUserPassword.
13+
*/
14+
15+
// Polyfill crypto for Node.js environment (required for Amplify Auth)
16+
import { webcrypto } from 'crypto';
17+
if (typeof globalThis.crypto === 'undefined') {
18+
(globalThis as any).crypto = webcrypto;
19+
}
20+
21+
import { Amplify } from 'aws-amplify';
22+
import { signIn, signOut, getCurrentUser } from 'aws-amplify/auth';
23+
import amplifyconfig from './src/amplifyconfiguration.json';
24+
import { TestRunner } from '../_test-common/test-apps-test-utils';
25+
import { provisionTestUser } from '../_test-common/signup';
26+
import { createTestFunctions, createTestOrchestrator } from './test-utils';
27+
28+
// Configure Amplify
29+
Amplify.configure(amplifyconfig);
30+
31+
// ============================================================
32+
// Main Test Execution
33+
// ============================================================
34+
35+
async function runAllTests(): Promise<void> {
36+
console.log('🚀 Starting Mood Board Gen1 Test Script\n');
37+
console.log('This script tests:');
38+
console.log(' 1. GraphQL Queries (Boards, MoodItems)');
39+
console.log(' 2. Board CRUD Operations');
40+
console.log(' 3. MoodItem CRUD Operations');
41+
console.log(' 4. Lambda Function Operations (Emoji, Kinesis)');
42+
console.log(' 5. S3 Storage Operations');
43+
console.log(' 6. Cleanup (Delete Test Data)');
44+
45+
// Provision user via admin APIs, then sign in here so tokens stay in this module's Amplify scope
46+
const { signinValue, testUser } = await provisionTestUser(amplifyconfig);
47+
48+
// Sign in from this module so the auth tokens are available to api/storage
49+
try {
50+
await signIn({ username: signinValue, password: testUser.password });
51+
const currentUser = await getCurrentUser();
52+
console.log(`✅ Signed in as: ${currentUser.username}`);
53+
} catch (error: any) {
54+
console.error('❌ SignIn failed:', error.message || error);
55+
process.exit(1);
56+
}
57+
58+
const runner = new TestRunner();
59+
const testFunctions = createTestFunctions();
60+
const {
61+
runQueryTests,
62+
runBoardMutationTests,
63+
runMoodItemMutationTests,
64+
runLambdaTests,
65+
runStorageTests,
66+
runCleanupTests,
67+
} = createTestOrchestrator(testFunctions, runner);
68+
69+
// Part 1: Query tests
70+
await runQueryTests();
71+
72+
// Part 2: Board mutations
73+
const boardId = await runBoardMutationTests();
74+
75+
// Part 3: MoodItem mutations (requires board)
76+
let moodItemId: string | null = null;
77+
if (boardId) {
78+
moodItemId = await runMoodItemMutationTests(boardId);
79+
}
80+
81+
// Part 4: Lambda functions (requires auth)
82+
await runLambdaTests();
83+
84+
// Part 5: S3 Storage
85+
await runStorageTests();
86+
87+
// Part 6: Cleanup
88+
await runCleanupTests(boardId, moodItemId);
89+
90+
// Sign out
91+
try {
92+
await signOut();
93+
console.log('✅ Signed out successfully');
94+
} catch (error: any) {
95+
console.error('❌ Sign out error:', error.message || error);
96+
}
97+
98+
// Print summary and exit with appropriate code
99+
runner.printSummary();
100+
}
101+
102+
// Run all tests
103+
void runAllTests();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Gen2 Test Script for Mood Board App
3+
*
4+
* This script tests all functionality for Amplify Gen2:
5+
* 1. GraphQL Queries (Boards, MoodItems)
6+
* 2. Board CRUD Operations
7+
* 3. MoodItem CRUD Operations
8+
* 4. Lambda Function Operations (getRandomEmoji, getKinesisEvents)
9+
* 5. S3 Storage Operations
10+
* 6. Cleanup (Delete Test Data)
11+
*
12+
* Credentials are provisioned automatically via Cognito AdminCreateUser.
13+
*/
14+
15+
// Polyfill crypto for Node.js environment (required for Amplify Auth)
16+
import { webcrypto } from 'crypto';
17+
if (typeof globalThis.crypto === 'undefined') {
18+
(globalThis as any).crypto = webcrypto;
19+
}
20+
21+
import { Amplify } from 'aws-amplify';
22+
import { signIn, signOut, getCurrentUser } from 'aws-amplify/auth';
23+
import amplifyconfig from './amplify_outputs.json';
24+
import { TestRunner } from '../_test-common/test-apps-test-utils';
25+
import { provisionTestUser } from '../_test-common/signup';
26+
import { createTestFunctions, createTestOrchestrator } from './test-utils';
27+
28+
// Configure Amplify with Gen2 outputs
29+
Amplify.configure(amplifyconfig);
30+
31+
// ============================================================
32+
// Main Test Execution
33+
// ============================================================
34+
35+
async function runAllTests(): Promise<void> {
36+
console.log('🚀 Starting Mood Board Gen2 Test Script\n');
37+
console.log('This script tests:');
38+
console.log(' 1. GraphQL Queries (Boards, MoodItems)');
39+
console.log(' 2. Board CRUD Operations');
40+
console.log(' 3. MoodItem CRUD Operations');
41+
console.log(' 4. Lambda Function Operations (Emoji, Kinesis)');
42+
console.log(' 5. S3 Storage Operations');
43+
console.log(' 6. Cleanup (Delete Test Data)');
44+
45+
// Provision user via admin APIs, then sign in here so tokens stay in this module's Amplify scope
46+
const { signinValue, testUser } = await provisionTestUser(amplifyconfig);
47+
48+
try {
49+
await signIn({ username: signinValue, password: testUser.password });
50+
const currentUser = await getCurrentUser();
51+
console.log(`✅ Signed in as: ${currentUser.username}`);
52+
} catch (error: any) {
53+
console.error('❌ SignIn failed:', error.message || error);
54+
process.exit(1);
55+
}
56+
57+
const runner = new TestRunner();
58+
const testFunctions = createTestFunctions();
59+
const {
60+
runQueryTests,
61+
runBoardMutationTests,
62+
runMoodItemMutationTests,
63+
runLambdaTests,
64+
runStorageTests,
65+
runCleanupTests,
66+
} = createTestOrchestrator(testFunctions, runner);
67+
68+
// Part 1: Query tests
69+
await runQueryTests();
70+
71+
// Part 2: Board mutations
72+
const boardId = await runBoardMutationTests();
73+
74+
// Part 3: MoodItem mutations (requires board)
75+
let moodItemId: string | null = null;
76+
if (boardId) {
77+
moodItemId = await runMoodItemMutationTests(boardId);
78+
}
79+
80+
// Part 4: Lambda functions (requires auth)
81+
await runLambdaTests();
82+
83+
// Part 5: S3 Storage
84+
await runStorageTests();
85+
86+
// Part 6: Cleanup
87+
await runCleanupTests(boardId, moodItemId);
88+
89+
// Sign out
90+
try {
91+
await signOut();
92+
console.log('✅ Signed out successfully');
93+
} catch (error: any) {
94+
console.error('❌ Sign out error:', error.message || error);
95+
}
96+
97+
// Print summary and exit with appropriate code
98+
runner.printSummary();
99+
}
100+
101+
// Run all tests
102+
void runAllTests();

amplify-migration-apps/mood-board/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ type Board @model @auth(rules: [{ allow: public }]) {
1515

1616
type Query {
1717
getRandomEmoji: String @function(name: "moodboardGetRandomEmoji-${env}") @auth(rules: [{ allow: private }])
18-
getKinesisEvents: AWSJSON @function(name: "moodboardKinesisreader-${env}") @auth(rules: [{ allow: private }])
18+
getKinesisEvents: AWSJSON @function(name: "moodboardKinesisReader-${env}") @auth(rules: [{ allow: private }])
1919
}

0 commit comments

Comments
 (0)