-
Notifications
You must be signed in to change notification settings - Fork 57
Add tests for Dev Portal helpers #1631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mishayouknowme
merged 11 commits into
main
from
michaelpopov-corplat-374-add-tests-for-dev-portal-helpers
Sep 12, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42f1707
Add create team tests
mishayouknowme f4aa208
add test for create-action
mishayouknowme 863761c
Add test for graphql proxy
mishayouknowme a86dec3
Remove helper
mishayouknowme a7dfb1c
Merge branch 'main' into michaelpopov-corplat-374-add-tests-for-dev-p…
mishayouknowme 195355c
Fix format issues
mishayouknowme 509f073
Update env.development
mishayouknowme db47505
Update imports
mishayouknowme 4fa122c
Fix formatting
mishayouknowme 0633436
Fix
mishayouknowme 16385f3
Update id generation
mishayouknowme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ AWS_REGION=eu-west-1 | |
| AWS_ACCESS_KEY_ID= | ||
| AWS_SECRET_ACCESS_KEY= | ||
|
|
||
| NAME_SLUG= | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,16 @@ | ||
| // Global setup for API tests - validates required environment variables | ||
|
|
||
| const requiredEnvVars = ["INTERNAL_API_URL", "NAME_SLUG"]; | ||
|
|
||
| beforeAll(() => { | ||
| const missingEnvVars = requiredEnvVars.filter( | ||
| (envVar) => !process.env[envVar], | ||
| ); | ||
|
|
||
| if (missingEnvVars.length > 0) { | ||
| throw new Error( | ||
| `Required environment variables are not set: ${missingEnvVars.join(", ")}\n` + | ||
| "Please check your environment configuration.", | ||
| ); | ||
| } | ||
| }); |
This file contains hidden or 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,90 @@ | ||
| import axios from "axios"; | ||
| import { | ||
| createTestApiKey, | ||
| createTestApp, | ||
| createTestTeam, | ||
| createTestUser, | ||
| deleteTestAction, | ||
| deleteTestApiKey, | ||
| deleteTestApp, | ||
| deleteTestTeam, | ||
| deleteTestUser, | ||
| } from "helpers"; | ||
|
|
||
| const INTERNAL_API_URL = process.env.INTERNAL_API_URL; | ||
| const NAME_SLUG = process.env.NAME_SLUG; | ||
|
|
||
| describe("Dev Portal Helpers API Endpoints", () => { | ||
| describe("POST /api/v2/create-action/[app_id]", () => { | ||
| let cleanUpFunctions: Array<() => Promise<unknown>> = []; | ||
|
|
||
| afterEach(async () => { | ||
| await cleanUpFunctions.reduce<Promise<unknown>>( | ||
| (promise, callback) => promise.then(() => callback()), | ||
| Promise.resolve(), | ||
| ); | ||
|
|
||
| cleanUpFunctions = []; | ||
| }); | ||
|
|
||
| it("Create Action Successfully with API Key", async () => { | ||
| // Setup test data | ||
| const teamId = await createTestTeam("Test Team"); | ||
| cleanUpFunctions.push(async () => await deleteTestTeam(teamId)); | ||
|
|
||
| const userEmail = `qa+${NAME_SLUG}+${Date.now()}@toolsforhumanity.com`; | ||
| const userId = await createTestUser(userEmail, teamId); | ||
| cleanUpFunctions.push(async () => await deleteTestUser(userId)); | ||
|
|
||
| const appId = await createTestApp("Test App", teamId); | ||
| cleanUpFunctions.push(async () => await deleteTestApp(appId)); | ||
|
|
||
| // Create API key for authentication | ||
| const { apiKeyId, apiKeyHeader } = await createTestApiKey( | ||
| teamId, | ||
| "Test Key for Create Action", | ||
| ); | ||
| cleanUpFunctions.push(async () => await deleteTestApiKey(apiKeyId)); | ||
|
|
||
| // Test data | ||
| const actionData = { | ||
| action: `test_action_${Date.now()}`, | ||
| name: "Test Action", | ||
| description: "Test action description", | ||
| max_verifications: 5, | ||
| }; | ||
|
|
||
| const response = await axios.post( | ||
| `${INTERNAL_API_URL}/api/v2/create-action/${appId}`, | ||
| actionData, | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Authorization: `Bearer ${apiKeyHeader}`, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.data).toEqual( | ||
| expect.objectContaining({ | ||
| action: expect.objectContaining({ | ||
| id: expect.any(String), | ||
| action: actionData.action, | ||
| name: actionData.name, | ||
| description: actionData.description, | ||
| max_verifications: actionData.max_verifications, | ||
| external_nullifier: expect.any(String), | ||
| status: "active", | ||
| }), | ||
| }), | ||
| ); | ||
bdoof marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Extract action_id from response for cleanup | ||
| const createdActionId = response.data.action.id; | ||
| cleanUpFunctions.push( | ||
| async () => await deleteTestAction(createdActionId), | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,136 @@ | ||
| import axios from "axios"; | ||
| import { | ||
| createTestUser, | ||
| deleteTestTeam, | ||
| deleteTestUser, | ||
| findUserByAuth0Id, | ||
| } from "helpers"; | ||
| import { createAppSession } from "helpers/auth0"; | ||
|
|
||
| const INTERNAL_API_URL = process.env.INTERNAL_API_URL; | ||
| const NAME_SLUG = process.env.NAME_SLUG; | ||
|
|
||
| describe("Dev Portal Helpers API Endpoints", () => { | ||
| describe("POST /api/create-team", () => { | ||
| let cleanUpFunctions: Array<() => Promise<unknown>> = []; | ||
|
|
||
| afterEach(async () => { | ||
| await cleanUpFunctions.reduce<Promise<unknown>>( | ||
| (promise, callback) => promise.then(() => callback()), | ||
| Promise.resolve(), | ||
| ); | ||
|
|
||
| cleanUpFunctions = []; | ||
| }); | ||
|
|
||
| it("Create team successfully for existing user", async () => { | ||
| const userEmail = `qa+${NAME_SLUG}+${Date.now()}@toolsforhumanity.com`; | ||
| const testUserId = await createTestUser(userEmail); | ||
|
|
||
| // Add cleanup functions | ||
| cleanUpFunctions.push(async () => await deleteTestUser(testUserId)); | ||
|
|
||
| // Generate unique auth0Id to prevent constraint violations | ||
| const uniqueAuth0Id = `auth0|test_existing_user_${Date.now()}`; | ||
|
|
||
| const existingUserSession = await createAppSession({ | ||
| user: { | ||
| sub: uniqueAuth0Id, | ||
| email: userEmail, | ||
| hasura: { | ||
| id: testUserId, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const teamData = { | ||
| team_name: "Test Team for API Tests", | ||
| hasUser: true, | ||
| }; | ||
|
|
||
| const response = await axios.post( | ||
| `${INTERNAL_API_URL}/api/create-team`, | ||
| teamData, | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Cookie: existingUserSession, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect( | ||
| response.status, | ||
| `Create team request resolved with a wrong code:\n${JSON.stringify(response.data, null, 2)}`, | ||
| ).toBe(200); | ||
|
|
||
| expect(response.data).toEqual( | ||
| expect.objectContaining({ | ||
| returnTo: expect.stringMatching(/^\/teams\/team_[a-f0-9]{32}$/), | ||
| }), | ||
| ); | ||
|
|
||
| // Extract team_id from returnTo URL for cleanup | ||
| const createdTeamId = response.data.returnTo.split("/teams/")[1]; | ||
| cleanUpFunctions.push(async () => await deleteTestTeam(createdTeamId)); | ||
| }); | ||
|
|
||
| it("Create an initial team along with the user", async () => { | ||
| const userEmail = `qa+${NAME_SLUG}+${Date.now()}@toolsforhumanity.com`; | ||
| const teamData = { | ||
| team_name: "Test Team for New User", | ||
| hasUser: false, | ||
| }; | ||
|
|
||
| // Generate unique auth0Id to prevent constraint violations | ||
| const uniqueAuth0Id = `auth0|test_new_user_${Date.now()}`; | ||
|
|
||
| const auth0Session = { | ||
| user: { | ||
| sub: uniqueAuth0Id, | ||
| email: userEmail, | ||
| hasura: { | ||
| id: `test_hasura_user_id_${Date.now()}`, | ||
| }, | ||
| }, | ||
bdoof marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const sessionCookie = await createAppSession(auth0Session); | ||
|
|
||
| const response = await axios.post( | ||
| `${INTERNAL_API_URL}/api/create-team`, | ||
| teamData, | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Cookie: sessionCookie, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect( | ||
| response.status, | ||
| `Create team request resolved with a wrong code:\n${JSON.stringify(response.data, null, 2)}`, | ||
| ).toBe(200); | ||
| expect(response.data).toEqual( | ||
| expect.objectContaining({ | ||
| returnTo: expect.stringMatching( | ||
| /^\/teams\/team_[a-f0-9]{32}\/apps\/$/, | ||
| ), | ||
| }), | ||
| ); | ||
|
|
||
| // Extract team_id from returnTo URL for cleanup | ||
| const createdTeamId = response.data.returnTo | ||
| .split("/teams/")[1] | ||
| .split("/apps/")[0]; | ||
| cleanUpFunctions.push(async () => await deleteTestTeam(createdTeamId)); | ||
|
|
||
| // Find and cleanup the created user by auth0Id | ||
| const createdUserId = await findUserByAuth0Id(uniqueAuth0Id); | ||
| if (createdUserId) { | ||
| cleanUpFunctions.push(async () => await deleteTestUser(createdUserId)); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to add a value in the pipeline.