-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(embed): adding uptime tests for embed
- Loading branch information
1 parent
7f88078
commit a76ad9d
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,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', | ||
}); | ||
}); | ||
}); |
This file contains 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 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,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; | ||
} | ||
} |