Skip to content

Commit

Permalink
chore: fix language test? (GaloyMoney#854)
Browse files Browse the repository at this point in the history
* chore: fix language test?

because of the optimisic mutation (?), it seems there is a race condition where we click on predefined before the previous mutation has been back from the server.

a short pausing should mitigate the issue

* chore: also rest language remotely

* fix: test expected is undefined

* chore: prettier:fix
  • Loading branch information
nicolasburtey authored Jan 12, 2023
1 parent 50b221e commit de16288
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 42 deletions.
70 changes: 70 additions & 0 deletions app/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,30 @@ export type UserDefaultWalletIdQuery = {
readonly userDefaultWalletId: string
}

export type WalletsQueryVariables = Exact<{ [key: string]: never }>

export type WalletsQuery = {
readonly __typename?: "Query"
readonly me?: {
readonly __typename?: "User"
readonly defaultAccount: {
readonly __typename?: "ConsumerAccount"
readonly wallets: ReadonlyArray<
| {
readonly __typename?: "BTCWallet"
readonly walletCurrency: WalletCurrency
readonly id: string
}
| {
readonly __typename?: "UsdWallet"
readonly walletCurrency: WalletCurrency
readonly id: string
}
>
}
} | null
}

export type PriceSubscriptionVariables = Exact<{
input: PriceInput
}>
Expand Down Expand Up @@ -4139,6 +4163,52 @@ export type UserDefaultWalletIdQueryResult = Apollo.QueryResult<
UserDefaultWalletIdQuery,
UserDefaultWalletIdQueryVariables
>
export const WalletsDocument = gql`
query wallets {
me {
defaultAccount {
wallets {
walletCurrency
id
}
}
}
}
`

/**
* __useWalletsQuery__
*
* To run a query within a React component, call `useWalletsQuery` and pass it any options that fit your needs.
* When your component renders, `useWalletsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useWalletsQuery({
* variables: {
* },
* });
*/
export function useWalletsQuery(
baseOptions?: Apollo.QueryHookOptions<WalletsQuery, WalletsQueryVariables>,
) {
const options = { ...defaultOptions, ...baseOptions }
return Apollo.useQuery<WalletsQuery, WalletsQueryVariables>(WalletsDocument, options)
}
export function useWalletsLazyQuery(
baseOptions?: Apollo.LazyQueryHookOptions<WalletsQuery, WalletsQueryVariables>,
) {
const options = { ...defaultOptions, ...baseOptions }
return Apollo.useLazyQuery<WalletsQuery, WalletsQueryVariables>(
WalletsDocument,
options,
)
}
export type WalletsQueryHookResult = ReturnType<typeof useWalletsQuery>
export type WalletsLazyQueryHookResult = ReturnType<typeof useWalletsLazyQuery>
export type WalletsQueryResult = Apollo.QueryResult<WalletsQuery, WalletsQueryVariables>
export const PriceDocument = gql`
subscription price($input: PriceInput!) {
price(input: $input) {
Expand Down
12 changes: 12 additions & 0 deletions app/graphql/operation/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,17 @@ export default gql`
userDefaultWalletId(username: $username)
}
# test only. could be in a dedicated file
query wallets {
me {
defaultAccount {
wallets {
walletCurrency
id
}
}
}
}
${Fragments}
`
4 changes: 2 additions & 2 deletions docs/e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ GALOY_TOKEN_2={SECOND_WALLET_TOKEN}
E2E_DEVICE={ios or android}
```

to simplify your workflow, you can put those env variables in a .env and use [direnv](https://direnv.net/)

## Running Single Tests that Require Authentication

To run the authenticated tests you need to set the env variable `GALOY_TOKEN`.

State in the application in cleared between testing invocations. The following command will always run tests 01 and 02 in order to authenticate the app, then run the test specified by the `TEST` env variable.


```
TEST="03" yarn test:e2e:ios:auth
```


## Troubleshooting

If you have any issues with appium then run `yarn appium-doctor`
Expand Down
6 changes: 6 additions & 0 deletions e2e/01-welcome-screen-flow.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { i18nObject } from "../app/i18n/i18n-util"
import { loadLocale } from "../app/i18n/i18n-util.sync"
import { selector } from "./utils"
import { resetLanguage } from "./utils/graphql"

describe("Welcome Screen Flow", async () => {
loadLocale("en")
Expand All @@ -12,6 +13,11 @@ describe("Welcome Screen Flow", async () => {
await browser.setClipboard("", "plaintext")
})

it("reset language is case previous test has failed", async () => {
const res = await resetLanguage()
expect(res.data.userUpdateLanguage.language).toBeFalsy()
})

it("loads and clicks 'Get Started button' ", async () => {
const getStartedButton = await $(selector(LL.GetStartedScreen.getStarted(), "Button"))
await getStartedButton.waitForDisplayed({ timeout })
Expand Down
4 changes: 0 additions & 4 deletions e2e/04-payments-receive-flow.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ describe("Receive Payment Flow", async () => {
const timeout = 30000
let invoice

it("Clear the clipboard", async () => {
await browser.setClipboard("", "plaintext")
})

it("Click 'Back Home' on the stablesats tutorial modal", async () => {
try {
const backHomeButton = await $(selector(LL.common.backHome(), "Button"))
Expand Down
2 changes: 2 additions & 0 deletions e2e/06-change-language.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ describe("Chang Language Flow", async () => {
const languageButton = await $(selector(enLL.Languages.es(), "StaticText"))
await languageButton.waitForDisplayed({ timeout })
await languageButton.click()
await browser.pause(2000)
})

it("clicks Predetermined", async () => {
const languageButton = await $(selector(esLL.Languages.DEFAULT(), "StaticText"))
await languageButton.waitForDisplayed({ timeout })
await languageButton.click()
await browser.pause(2000)
})

it("click go back to settings screen", async () => {
Expand Down
65 changes: 29 additions & 36 deletions e2e/utils/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
ApolloQueryResult,
InMemoryCache,
createHttpLink,
gql,
} from "@apollo/client"
import {
LnNoAmountInvoiceCreateDocument,
LnNoAmountInvoicePaymentSendDocument,
MeFragment,
UserUpdateLanguageDocument,
WalletsDocument,
} from "../../app/graphql/generated"

import fetch from "cross-fetch"
Expand All @@ -32,30 +33,25 @@ const createGaloyServerClient = (config) => (authToken) => {
})
}

const authToken = process.env.GALOY_TOKEN_2
const authToken = process.env.GALOY_TOKEN
const authTokenOther = process.env.GALOY_TOKEN_2

export const getInvoice = async () => {
const client = createGaloyServerClient(config)(authToken)
// get BTC wallet id
const getDefaultWalletId = async (client) => {
const accountResult: ApolloQueryResult<{ me: MeFragment }> = await client.query({
query: gql`
{
me {
defaultAccount {
wallets {
walletCurrency
id
}
}
}
}
`,
query: WalletsDocument,
fetchPolicy: "no-cache",
})
const walletId = accountResult.data.me.defaultAccount.wallets.filter(
(w) => w.walletCurrency === "BTC",
)[0].id

return walletId
}

export const getInvoice = async () => {
const client = createGaloyServerClient(config)(authTokenOther)
const walletId = await getDefaultWalletId(client)

const result = await client.mutate({
variables: { input: { walletId } }, // (lookup wallet 2 id from graphql) i.e "8914b38f-b0ea-4639-9f01-99c03125eea5"
mutation: LnNoAmountInvoiceCreateDocument,
Expand All @@ -67,25 +63,8 @@ export const getInvoice = async () => {
}

export const payInvoice = async (invoice: string) => {
const client = createGaloyServerClient(config)(authToken)
const accountResult: ApolloQueryResult<{ me: MeFragment }> = await client.query({
query: gql`
{
me {
defaultAccount {
wallets {
walletCurrency
id
}
}
}
}
`,
fetchPolicy: "no-cache",
})
const walletId = accountResult.data.me.defaultAccount.wallets.filter(
(w) => w.walletCurrency === "BTC",
)[0].id
const client = createGaloyServerClient(config)(authTokenOther)
const walletId = await getDefaultWalletId(client)

return client.mutate({
variables: {
Expand All @@ -99,3 +78,17 @@ export const payInvoice = async (invoice: string) => {
fetchPolicy: "no-cache",
})
}

export const resetLanguage = async () => {
const client = createGaloyServerClient(config)(authToken)

return client.mutate({
variables: {
input: {
language: "",
},
},
mutation: UserUpdateLanguageDocument,
fetchPolicy: "no-cache",
})
}

0 comments on commit de16288

Please sign in to comment.