Skip to content

Commit

Permalink
feat: get non existant wallet address test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Mar 9, 2024
1 parent b94f452 commit 82e84d6
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 246 deletions.
9 changes: 4 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 34 additions & 26 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,46 @@ describe('Integration tests', (): void => {
senderWalletAddress = await c9.opClient.walletAddress.get({
url: senderWalletAddressUrl
})

console.log({ receiverWalletAddress, senderWalletAddress })
// TODO: better expect.
// tried jestOpenapi.toSatifyApiSpec but loading throws errors
// for invalid spec? something not right there because that works in other pkgs
expect(receiverWalletAddress).toBeTruthy()
expect(senderWalletAddress).toBeTruthy()

expect(receiverWalletAddress.id).toBe(
receiverWalletAddressUrl.replace('http', 'https')
)
expect(senderWalletAddress.id).toBe(
senderWalletAddressUrl.replace('http', 'https')
)
})

// TODO: fix account not found error in webhook handler
test.skip('Get Non-Existing Wallet Address Triggers Not Found Webhook Event', async (): Promise<void> => {
let walletAddress
test('Can Get Non-Existing Wallet Address', async (): Promise<void> => {
const notFoundWalletAddress =
'https://host.docker.internal:4000/accounts/asmith'

const handleWebhookEventSpy = jest.spyOn(
c9.integrationServer.webhookEventHandler,
hlb.integrationServer.webhookEventHandler,
'handleWebhookEvent'
)
try {
walletAddress = await c9.opClient.walletAddress.get({
url: 'http://host.docker.internal:4000/accounts/asmith'
})
} catch (e) {
// 404 error from client is expected - swallow it
if (!(e instanceof OpenPaymentsClientError)) throw e
}

expect(walletAddress).toBeUndefined()
// Poll in case the webhook response to create wallet address is slow,
// but initial request may very well resolve immediately.
const walletAddress = await poll(
async () =>
c9.opClient.walletAddress.get({
url: notFoundWalletAddress
}),
(responseData) => responseData.id === notFoundWalletAddress,
5,
0.5
)

assert(walletAddress)
expect(walletAddress.id).toBe(notFoundWalletAddress)
expect(handleWebhookEventSpy).toHaveBeenCalledWith(
expect.objectContaining({
type: WebhookEventType.WalletAddressNotFound,
data: expect.any(Object)
data: expect.objectContaining({
walletAddressUrl: notFoundWalletAddress
})
})
)
})
Expand Down Expand Up @@ -315,7 +325,8 @@ describe('Integration tests', (): void => {

// ----------------------------------------------------------
// Grant Continuation via Polling.
// Alternative to getting the redirect url with interact_ref.
// Alternative to gettiang the redirect url with interact_ref.
// TODO: Test this way as well when OP client doesnt require interact_ref.
test.skip('Grant Request Outgoing Payment', async (): Promise<void> => {
const grant = await hlb.opClient.grant.request(
{
Expand Down Expand Up @@ -361,20 +372,17 @@ describe('Integration tests', (): void => {
accessToken: access_token.value,
url: uri
},
{
interact_ref: '' // TODO: update OP spec/client to not need body/interact_ref here
}
// TODO: pull in latest spec which shouldn't need interact_ref
{ interact_ref: '' }
),
(responseData) => 'accessToken' in responseData,
// TODO: update timing to be based on the grant.continue.wait
10,
2
)
console.log({ grantContinue })
expect(true).toBe(true)
})
// ^^^
// Grant Continuation via Polling.
// Alternative to getting the redirect url with interact_ref.
// ----------------------------------------------------------

test('Create Outgoing Payment', async (): Promise<void> => {
Expand Down
229 changes: 229 additions & 0 deletions test/integration/lib/AdminClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import type { NormalizedCacheObject } from '@apollo/client'
import { ApolloClient, gql } from '@apollo/client'
import { GraphqlTypes } from 'mock-account-servicing-lib'

export class AdminClient {
private apolloClient: ApolloClient<NormalizedCacheObject>

constructor(apolloClient: ApolloClient<NormalizedCacheObject>) {
this.apolloClient = apolloClient
}

async createReceiver(
input: GraphqlTypes.CreateReceiverInput
): Promise<GraphqlTypes.CreateReceiverResponse> {
return await this.apolloClient
.mutate({
mutation: gql`
mutation CreateReceiver($input: CreateReceiverInput!) {
createReceiver(input: $input) {
code
message
receiver {
completed
createdAt
expiresAt
metadata
id
incomingAmount {
assetCode
assetScale
value
}
walletAddressUrl
receivedAmount {
assetCode
assetScale
value
}
updatedAt
}
success
}
}
`,
variables: { input }
})
.then(({ data }): GraphqlTypes.CreateReceiverResponse => {
return data.createReceiver
})
}

async createQuote(
input: GraphqlTypes.CreateQuoteInput
): Promise<GraphqlTypes.QuoteResponse> {
return await this.apolloClient
.mutate({
mutation: gql`
mutation CreateQuote($input: CreateQuoteInput!) {
createQuote(input: $input) {
code
message
quote {
createdAt
expiresAt
highEstimatedExchangeRate
id
lowEstimatedExchangeRate
maxPacketAmount
minExchangeRate
walletAddressId
receiveAmount {
assetCode
assetScale
value
}
receiver
debitAmount {
assetCode
assetScale
value
}
}
}
}
`,
variables: { input }
})
.then(({ data }): GraphqlTypes.QuoteResponse => {
return data.createQuote
})
}

async createOutgoingPayment(
input: GraphqlTypes.CreateOutgoingPaymentInput
): Promise<GraphqlTypes.OutgoingPaymentResponse> {
return await this.apolloClient
.mutate({
mutation: gql`
mutation CreateOutgoingPayment($input: CreateOutgoingPaymentInput!) {
createOutgoingPayment(input: $input) {
code
message
payment {
createdAt
error
metadata
id
walletAddressId
receiveAmount {
assetCode
assetScale
value
}
receiver
debitAmount {
assetCode
assetScale
value
}
sentAmount {
assetCode
assetScale
value
}
state
stateAttempts
}
success
}
}
`,
variables: { input }
})
.then(({ data }): GraphqlTypes.OutgoingPaymentResponse => {
return data.createOutgoingPayment
})
}

async getOutgoingPayment(id: string): Promise<GraphqlTypes.OutgoingPayment> {
return await this.apolloClient
.query({
query: gql`
query GetOutgoingPayment($id: String!) {
outgoingPayment(id: $id) {
createdAt
error
metadata
id
walletAddressId
quote {
id
}
receiveAmount {
assetCode
assetScale
value
}
receiver
debitAmount {
assetCode
assetScale
value
}
sentAmount {
assetCode
assetScale
value
}
state
stateAttempts
}
}
`,
variables: { id }
})
.then((response): GraphqlTypes.OutgoingPayment => {
return response.data.outgoingPayment
})
}

async depositOutgoingPaymentLiquidity(
input: GraphqlTypes.DepositOutgoingPaymentLiquidityInput
): Promise<GraphqlTypes.LiquidityMutationResponse> {
return await this.apolloClient
.mutate({
mutation: gql`
mutation DepositOutgoingPaymentLiquidity(
$input: DepositOutgoingPaymentLiquidityInput!
) {
depositOutgoingPaymentLiquidity(input: $input) {
code
success
message
error
}
}
`,
variables: { input }
})
.then(({ data }): GraphqlTypes.LiquidityMutationResponse => {
return data.depositOutgoingPaymentLiquidity
})
}

async createWalletAddress(
input: GraphqlTypes.CreateWalletAddressInput
): Promise<GraphqlTypes.CreateWalletAddressMutationResponse> {
return await this.apolloClient
.mutate({
mutation: gql`
mutation CreateWalletAddress($input: CreateWalletAddressInput!) {
createWalletAddress(input: $input) {
success
walletAddress {
id
url
publicName
}
}
}
`,
variables: { input }
})
.then(({ data }): GraphqlTypes.CreateWalletAddressMutationResponse => {
console.log({ data })
return data.createWalletAddress
})
}
}
Loading

0 comments on commit 82e84d6

Please sign in to comment.