-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testsing): splitting integration tests (#503)
- Loading branch information
1 parent
f060240
commit 3b0c4dd
Showing
11 changed files
with
364 additions
and
335 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getTestSetup } from './init'; | ||
|
||
describe('Generators', () => { | ||
const { baseUrl, projectId, httpClient } = getTestSetup(); | ||
|
||
it('onramp Pay SDK URL', async () => { | ||
const expected_host = 'https://pay.coinbase.com/buy/select-asset'; | ||
const address = '0x1234567890123456789012345678901234567890'; | ||
const partnerUserId = 'someUserID'; | ||
const payload = { | ||
partnerUserId, | ||
destinationWallets:[{ address }], | ||
}; | ||
let resp: any = await httpClient.post( | ||
`${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, | ||
payload | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(typeof resp.data).toBe('object') | ||
expect(typeof resp.data.url).toBe('string') | ||
expect(resp.data.url).toContain(expected_host) | ||
expect(resp.data.url).toContain(address) | ||
expect(resp.data.url).toContain(partnerUserId) | ||
}) | ||
it('onramp Pay SDK URL wrong payload', async () => { | ||
const address = '0x1234567890123456789012345678901234567890'; | ||
const partnerUserId = 'someUserID'; | ||
// Creating the wrong payload | ||
const payload = { | ||
partner: partnerUserId, | ||
someWallets:[{ address }], | ||
}; | ||
let resp: any = await httpClient.post( | ||
`${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, | ||
payload | ||
) | ||
expect(resp.status).toBe(400) | ||
}) | ||
}) |
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,14 @@ | ||
import { getTestSetup } from './init'; | ||
|
||
describe('Health', () => { | ||
it('is healthy', async () => { | ||
const { baseUrl, projectId, httpClient } = getTestSetup(); | ||
const resp: any = await httpClient.get(`${baseUrl}/health`) | ||
|
||
expect(resp.status).toBe(200) | ||
expect(resp.data).toContain('OK v') | ||
expect(resp.data).toContain('hash:') | ||
expect(resp.data).toContain('features:') | ||
expect(resp.data).toContain('uptime:') | ||
}) | ||
}) |
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 { getTestSetup } from './init'; | ||
|
||
describe('Transactions history', () => { | ||
const { baseUrl, projectId, httpClient } = getTestSetup(); | ||
|
||
const fulfilled_address = '0x63755B7B300228254FB7d16321eCD3B87f98ca2a' | ||
const empty_history_address = '0x739ff389c8eBd9339E69611d46Eec6212179BB67' | ||
|
||
it('fulfilled history', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/account/${fulfilled_address}/history?projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(typeof resp.data.data).toBe('object') | ||
expect(resp.data.data).toHaveLength(50) | ||
expect(typeof resp.data.next).toBe('string') | ||
expect(resp.data.next).toHaveLength(80) | ||
|
||
for (const item of resp.data.data) { | ||
expect(item.id).toBeDefined() | ||
expect(typeof item.metadata).toBe('object') | ||
// expect chain to be null or caip-2 format | ||
if (item.metadata.chain !== null) { | ||
expect(item.metadata.chain).toEqual(expect.stringMatching(/^(eip155:)?\d+$/)); | ||
} else { | ||
expect(item.metadata.chain).toBeNull(); | ||
} | ||
expect(typeof item.metadata.application).toBe('object') | ||
expect(typeof item.transfers).toBe('object') | ||
} | ||
}) | ||
it('empty history', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/account/${empty_history_address}/history?projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(typeof resp.data.data).toBe('object') | ||
expect(resp.data.data).toHaveLength(0) | ||
expect(resp.data.next).toBeNull() | ||
}) | ||
it('wrong address', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/account/0X${fulfilled_address}/history?projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(400) | ||
}) | ||
it('onramp Coinbase provider', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/account/${fulfilled_address}/history?onramp=coinbase&projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(typeof resp.data.next).toBe('string') | ||
expect(typeof resp.data.data).toBe('object') | ||
|
||
const first = resp.data.data[0] | ||
expect(first.id).toBeDefined() | ||
expect(first.metadata.sentFrom).toBe('Coinbase') | ||
expect(first.metadata.operationType).toBe('buy') | ||
expect(first.metadata.status).toEqual(expect.stringMatching(/^ONRAMP_TRANSACTION_STATUS_/)); | ||
}) | ||
it('onramp wrong provider', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/account/${fulfilled_address}/history?onramp=some&projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(400) | ||
}) | ||
}) |
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,20 @@ | ||
import { getTestSetup } from './init'; | ||
|
||
describe('Identity', () => { | ||
const { baseUrl, projectId, httpClient } = getTestSetup(); | ||
|
||
it('known ens', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63?chainId=eip155%3A1&projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(resp.data.name).toBe('cyberdrk.eth') | ||
}) | ||
it('unknown ens', async () => { | ||
let resp: any = await httpClient.get( | ||
`${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA64?chainId=eip155%3A1&projectId=${projectId}`, | ||
) | ||
expect(resp.status).toBe(200) | ||
expect(resp.data.name).toBe(null) | ||
}) | ||
}) |
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,23 @@ | ||
import axios from 'axios' | ||
|
||
interface TestSetup { | ||
baseUrl: string; | ||
projectId: string; | ||
httpClient: any; | ||
} | ||
|
||
export const getTestSetup = (): TestSetup => { | ||
const baseUrl = process.env.RPC_URL; | ||
if (!baseUrl) { | ||
throw new Error('RPC_URL environment variable not set'); | ||
} | ||
const projectId = process.env.PROJECT_ID; | ||
if (!projectId) { | ||
throw new Error('PROJECT_ID environment variable not set'); | ||
} | ||
const httpClient = axios.create({ | ||
validateStatus: (_status) => true, | ||
}) | ||
|
||
return { baseUrl, projectId, httpClient }; | ||
}; |
Oops, something went wrong.