Skip to content

Commit

Permalink
test(core): move 'accounts' integration tests (#3806)
Browse files Browse the repository at this point in the history
* test(core): remove update-default-id integration test

This is covered by 'account-update-default-wallet-id' tests in
public-ln-receive bats tests.

* test(core): move wallet-from-non-existent-account test to wallets-repo tests

* chore(core): remove redundant 'addWallet' function

* chore(core): remove redundant 'addWalletIfNonexistent' function

* chore(core): remove create-usd-wallets debug script
  • Loading branch information
vindard authored Jan 12, 2024
1 parent 4497a64 commit dc98869
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 193 deletions.
44 changes: 0 additions & 44 deletions core/api/src/app/accounts/add-wallet.ts

This file was deleted.

1 change: 0 additions & 1 deletion core/api/src/app/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AccountsRepository, WalletsRepository } from "@/services/mongoose"

export * from "./account-limit"
export * from "./add-new-contact"
export * from "./add-wallet"
export * from "./create-account"
export * from "./get-account-transactions-for-contact"
export * from "./get-contact-by-username"
Expand Down
45 changes: 0 additions & 45 deletions core/api/src/debug/create-usd-wallets.ts

This file was deleted.

36 changes: 8 additions & 28 deletions core/api/test/helpers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { lndOutside1, safePay } from "./lightning"

import { randomPhone, randomUserId } from "."

import { addWallet, createAccountWithPhoneIdentifier } from "@/app/accounts"
import { addWalletIfNonexistent } from "@/app/accounts/add-wallet"
import { createAccountWithPhoneIdentifier } from "@/app/accounts"
import { getAdminAccounts, getDefaultAccountsConfig } from "@/config"

import { CouldNotFindAccountFromKratosIdError, CouldNotFindError } from "@/domain/errors"
Expand Down Expand Up @@ -155,12 +154,6 @@ export const createUserAndWalletFromPhone = async (
const accountIP = await AccountsIpsRepository().update(accountIp)
if (!(accountIP instanceof CouldNotFindError) && accountIP instanceof Error)
throw accountIP

await addWalletIfNonexistent({
currency: WalletCurrency.Usd,
accountId: account.id,
type: WalletType.Checking,
})
}

if (account instanceof Error) throw account
Expand Down Expand Up @@ -190,20 +183,14 @@ export const createRandomUserAndWallets = async (): Promise<{
const phone = randomPhone()
const btcWalletDescriptor = await createUserAndWallet(phone)

const usdWallet = await addWalletIfNonexistent({
currency: WalletCurrency.Usd,
accountId: btcWalletDescriptor.accountId,
type: WalletType.Checking,
})
if (usdWallet instanceof Error) throw usdWallet
const accountWallets = await WalletsRepository().findAccountWalletsByAccountId(
btcWalletDescriptor.accountId,
)
if (accountWallets instanceof Error) throw accountWallets

return {
btcWalletDescriptor,
usdWalletDescriptor: {
id: usdWallet.id,
currency: WalletCurrency.Usd,
accountId: usdWallet.accountId,
},
usdWalletDescriptor: accountWallets.USD,
}
}

Expand Down Expand Up @@ -256,12 +243,6 @@ export const createUserAndWallet = async (
const accountIP = await AccountsIpsRepository().update(accountIp)
if (!(accountIP instanceof CouldNotFindError) && accountIP instanceof Error)
throw accountIP

await addWalletIfNonexistent({
currency: WalletCurrency.Usd,
accountId: account.id,
type: WalletType.Checking,
})
}

if (account instanceof Error) throw account
Expand All @@ -286,11 +267,10 @@ export const addNewWallet = async ({
accountId: AccountId
currency: WalletCurrency
}): Promise<Wallet> => {
// Create wallet for account (phone number)
const wallet = await addWallet({
currency,
const wallet = await WalletsRepository().persistNew({
accountId,
type: WalletType.Checking,
currency,
})
if (wallet instanceof Error) throw wallet

Expand Down
17 changes: 17 additions & 0 deletions core/api/test/integration/services/wallets-repository.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { randomUUID } from "crypto"

import mongoose from "mongoose"

import {
CouldNotFindAccountFromIdError,
CouldNotFindWalletFromAccountIdAndCurrencyError,
MultipleWalletsFoundForAccountIdAndCurrency,
RepositoryError,
} from "@/domain/errors"
import { WalletCurrency } from "@/domain/shared"
import { WalletsRepository } from "@/services/mongoose"
import { Wallet } from "@/services/mongoose/schema"
import { WalletType } from "@/domain/wallets"

const wallets = WalletsRepository()
const accountId = randomUUID() as AccountId
Expand Down Expand Up @@ -82,4 +86,17 @@ describe("WalletsRepository", () => {
expect((accountWallets as RepositoryError).message).toBe(WalletCurrency.Usd)
})
})

describe("persistNew", () => {
it("fail to create a wallet with non-existent account", async () => {
const id = new mongoose.Types.ObjectId()

const newWallet = await wallets.persistNew({
accountId: id as unknown as AccountId,
type: WalletType.Checking,
currency: WalletCurrency.Btc,
})
expect(newWallet).toBeInstanceOf(CouldNotFindAccountFromIdError)
})
})
})

This file was deleted.

0 comments on commit dc98869

Please sign in to comment.