diff --git a/system_tests/.env.example b/system_tests/.env.example index 62a9140a7..415f96b3c 100644 --- a/system_tests/.env.example +++ b/system_tests/.env.example @@ -1,5 +1,6 @@ SCORER_API_BASE_URL=http://localhost:8002 IAM_BASE_URL=http://localhost:80 +EMBED_BASE_URL=http://localhost:8004 DOMAIN=staging.passport.xyz ALCHEMY_API_KEY=abc TEST_API_SCORER_ID=1 diff --git a/system_tests/src/tests/embed.test.ts b/system_tests/src/tests/embed.test.ts new file mode 100644 index 000000000..166a6e72d --- /dev/null +++ b/system_tests/src/tests/embed.test.ts @@ -0,0 +1,67 @@ +import { testRequest } from '../utils/testRequest'; +import { EmbedUser } from '../users/EmbedUser'; +import { AuthStrategy } from '../types'; +import { HeaderKeyAuth } from '../auth/strategies'; + +const { EMBED_BASE_URL } = process.env; + +const url = (subpath: string) => EMBED_BASE_URL + '/' + subpath; + +describe('Embed', () => { + let authStrategy: AuthStrategy; + let address: string; + let apiKey: string; + let scorerId: string; + + beforeAll(async () => { + ({ apiKey, scorerId, address } = await EmbedUser.get()); + authStrategy = new HeaderKeyAuth({ key: apiKey, header: 'X-API-Key' }); + }); + + it('POST /embed/verify', async () => { + const response = await testRequest({ + url: url('embed/verify'), + method: 'POST', + authStrategy, + payload: { + address, + scorerId, + credentialIds: [], + }, + }); + + expect(response).toHaveStatus(200); + + expect(response.data).toMatchObject({ + address, + score: expect.any(String), + passing_score: expect.any(Boolean), + threshold: expect.any(String), + error: null, + stamps: expect.any(Object), + }); + }); + + it('GET /embed/stamps/metadata', async () => { + const response = await testRequest<{ valid?: boolean; code?: number }[]>({ + url: url(`embed/stamps/metadata`), + method: 'GET', + authStrategy, + }); + + expect(response).toHaveStatus(200); + expect(response.data.length).toBeGreaterThan(0); + }); + + it('GET /health', async () => { + const response = await testRequest({ + url: url('health'), + method: 'GET', + }); + + expect(response).toHaveStatus(200); + expect(response.data).toMatchObject({ + message: 'Ok', + }); + }); +}); diff --git a/system_tests/src/tests/setup.test.ts b/system_tests/src/tests/setup.test.ts index d7b4036df..713dae12f 100644 --- a/system_tests/src/tests/setup.test.ts +++ b/system_tests/src/tests/setup.test.ts @@ -8,6 +8,7 @@ describe('Test Environment', () => { 'TEST_UI_SCORER_ID', 'TEST_INTERNAL_API_SECRET', 'IAM_BASE_URL', + 'EMBED_BASE_URL', 'NFT_HOLDER_PRIVATE_KEY', 'DOMAIN', 'DB_CONNECTION_STRING', diff --git a/system_tests/src/users/EmbedUser.ts b/system_tests/src/users/EmbedUser.ts new file mode 100644 index 000000000..5206ed447 --- /dev/null +++ b/system_tests/src/users/EmbedUser.ts @@ -0,0 +1,18 @@ +import { PassportUIUser } from './PassportUIUser'; +import { RegistryAPIUser } from './RegistryAPIUser'; +import { BaseUser } from './User'; + +export class EmbedUser extends BaseUser { + declare apiKey: string; + declare scorerId: string; + declare address: string; + + async init() { + const passportUIUser = await PassportUIUser.get(); + const registryAPIUser = await RegistryAPIUser.get(); + + this.apiKey = registryAPIUser.apiKey; + this.scorerId = registryAPIUser.scorerId; + this.address = passportUIUser.address; + } +}