Skip to content

Commit

Permalink
test(embed): adding uptime tests for embed
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jan 27, 2025
1 parent 7f88078 commit a76ad9d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions system_tests/.env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
67 changes: 67 additions & 0 deletions system_tests/src/tests/embed.test.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
1 change: 1 addition & 0 deletions system_tests/src/tests/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions system_tests/src/users/EmbedUser.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit a76ad9d

Please sign in to comment.