Skip to content

Commit 1ec8d79

Browse files
authored
Merge pull request #643 from nachikamod/fix/nk-bdd-create-wallet
fix(bdd): create new wallet
2 parents c8a9640 + f1d8700 commit 1ec8d79

File tree

12 files changed

+264
-39
lines changed

12 files changed

+264
-39
lines changed

CHANGELOG.md

Lines changed: 206 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ git clone https://github.com/Greenstand/treetracker-wallet-app.git
3232
cd treetracker-wallet-app && yarn install
3333
```
3434

35+
### 🔧 **Environment Variables**
36+
```bash
37+
# Setup environment (first time only)
38+
39+
# For backend user api and bdds
40+
cp apps/user/.env.example apps/user/.dev.env
41+
# → Edit .dev.env with your configuration
42+
43+
# For web development and bdd
44+
cp apps/web/.env.example apps/user/.env
45+
# → Edit .env with your configuration
46+
47+
# For keycloak package e2e testing
48+
cp packages/keycloak/.env.example packages/keycloak/.env
49+
# → Edit .env with your configuration
50+
51+
# For wallet package e2e testing
52+
cp packages/wallet/.env.example packages/wallet/.env
53+
# → Edit .env with your configuration
54+
```
55+
3556
### 🏃‍♂️ Start Development
3657

3758
#### Option 1: Quick Web Development

apps/bdd/features/create-wallet.feature

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@ Feature: Create wallet
2222
Then I should see text "Wallet name already exists"
2323

2424

25-
@discovery
26-
Scenario: As a user, I can create a new wallet (but has problem)
25+
@web
26+
Scenario: As a user, I can create a new wallet
2727
#Given test@greenstand.org is registered in the system
2828
Given I am on the login page
2929
And I login with an account
3030
And I am on the wallet page
3131
When I create a new wallet
32-
Then I noticed that I can click the create button, and the pop-up dialog disappear but nothing happens, no new wallet shows up, and in the devtool network panel, there are 404 error shown below:
33-
#http://localhost:3000/wallets
34-
#Request Method
35-
#POST
36-
#Status Code 404 Not Found
37-
32+
Then I should see my new wallet in the list of wallets

apps/bdd/features/step-definitions/steps.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import { Given, When, Then } from "@wdio/cucumber-framework";
1717
import { expect, $ } from "@wdio/globals";
1818

19+
// State object to share data between steps
20+
const stepState: Record<string, string> = {
21+
walletName: "", // We need unique walletName for each test, so we use a global state object to share the walletName between steps
22+
};
23+
1924
// Map page names to routes
2025
const routes: Record<string, string> = {
2126
login: "login",
@@ -83,7 +88,13 @@ Then(
8388
);
8489

8590
Then(/^I should see my new wallet in the list of wallets$/, async () => {
86-
await expect($(".wallet-list")).toBeDisplayed();
91+
await expect($("[data-test=wallet-list]")).toBeDisplayed();
92+
const walletItemSelector = `[data-test=wallet-item-name-${stepState.walletName}]`;
93+
// Wait for the wallet item to be displayed assuming API latency
94+
await $(walletItemSelector).waitForDisplayed({
95+
timeout: 3000,
96+
timeoutMsg: `Wallet item with name "${stepState.walletName}" did not appear in the list`,
97+
});
8798
});
8899

89100
// ============================================================================
@@ -180,8 +191,16 @@ When("I login with an account", async () => {
180191
});
181192

182193
When("I create a new wallet", async () => {
194+
const ts = Date.now();
195+
stepState.walletName = `wallet${ts}`;
183196
await $("[data-test=wallet-create-open]").click();
184-
await $('[data-test="wallet-create-name"] input').setValue("wallet1");
197+
// Wallet creation drawer takes some time to open, so we wait for the input to be displayed
198+
await $('[data-test="wallet-create-name"] input').waitForDisplayed({
199+
timeout: 3000,
200+
});
201+
await $('[data-test="wallet-create-name"] input').setValue(
202+
stepState.walletName,
203+
);
185204
await $('[data-test="wallet-create-description"] input').setValue("desc");
186205
await $('[data-test="wallet-create-submit"]').click();
187206
});

apps/bdd/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test:web:headless": "cross-env wdio run ./wdio.web.conf.ts --headless",
1515
"test:web:login": "cross-env wdio run ./wdio.web.conf.ts --spec ./features/login.feature",
1616
"test:web:register": "cross-env wdio run ./wdio.web.conf.ts --spec ./features/register.feature",
17+
"test:web:wallet": "cross-env wdio run ./wdio.web.conf.ts --spec ./features/create-wallet.feature",
1718
"test:web:debug": "cross-env wdio run ./wdio.debug.conf.ts --logLevel debug",
1819
"test:update-driver": "yarn add -D chromedriver@latest",
1920
"report:cucumber": "node scripts/generate-cucumber-report.js",

apps/user/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "user",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "greenstand-wallet-app-api",
55
"author": "",
66
"private": true,

apps/web/.env.example

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
1-
2-
NEXT_PUBLIC_WALLET_APP_API=http://localhost:8080
3-
4-
5-
NEXT_PUBLIC_BASE_URL=http://localhost:3000
6-
7-
# this is for the keycloak API
8-
KEYCLOAK_REALM = treetracker
9-
10-
KEYCLOAK_BASE_URL = https://dev-k8s.treetracker.org/keycloak
11-
12-
KEYCLOAK_CLIENT_SECRET =
13-
14-
KEYCLOAK_CLIENT_ID = wallet-app-user-dev-svc
15-
1+
NEXT_PUBLIC_WALLET_APP_API = http://localhost:8080
2+
NEXT_PUBLIC_TREETRACKER_API = # Get from slack

apps/web/src/components/WalletItem.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export default function WalletItem({
2020
display: "flex",
2121
justifyContent: "space-between",
2222
alignItems: "center",
23-
}}>
23+
}}
24+
>
2425
<Box>
25-
<Typography variant="body2">{name}</Typography>
26+
<Typography variant="body2" data-test={`wallet-item-name-${name}`}>
27+
{name}
28+
</Typography>
2629
<Typography variant="body2" color="text.secondary">
2730
{created_at}
2831
</Typography>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"bdd:e2e:local": "yarn workspace @treetracker/bdd run test:local",
4444
"bdd:e2e:login": "yarn workspace @treetracker/bdd run test:login",
4545
"bdd:e2e:register": "yarn workspace @treetracker/bdd run test:register",
46+
"bdd:e2e:wallet": "yarn workspace @treetracker/bdd run test:web:wallet",
4647
"bdd:e2e:debug": "yarn workspace @treetracker/bdd test:debug",
4748
"bdd:e2e:update-driver": "yarn workspace @treetracker/bdd run test:update-driver",
4849
"bdd:report": "yarn workspace @treetracker/bdd run report:cucumber",

packages/wallet/src/api/createWallet.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios, { isAxiosError } from "axios";
22
import { Wallet } from "../types/wallet";
3-
import { TREETRACKER_API, WALLET_API_KEY } from "../utils/config";
3+
import { TREETRACKER_API } from "../utils/config";
44

55
async function createWallet(walletData: Wallet, token: string) {
66
try {
@@ -12,7 +12,6 @@ async function createWallet(walletData: Wallet, token: string) {
1212
},
1313
{
1414
headers: {
15-
"treetracker-api-key": WALLET_API_KEY,
1615
"Content-Type": "application/json",
1716
Authorization: `Bearer ${token}`,
1817
},

0 commit comments

Comments
 (0)