-
Notifications
You must be signed in to change notification settings - Fork 0
/
spenmo.test.ts
254 lines (220 loc) · 8.4 KB
/
spenmo.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import request from "supertest";
import * as configurations from "./config/configurations";
import * as userData from "./data/userData";
import "dotenv/config";
let orgid;
let userid;
let wallet_amount;
let member_available_balance;
let reference_number;
let from_amount = "1";
let amountSent;
let member_updated_available_balance;
describe("Admin should be able to send amount to wallet of member", () => {
it("A Admin should be able to get authenticated and fetch token for next request", async () => {
const response = await request(process.env.TESTURL)
.post(configurations.appConfig.apiURLs.login)
.send(userData.loginDataAdmin);
expect(response.body.status).toBe(200);
expect(response.body.payload.status_message).toContain(
"token generated successfully"
);
expect(response.body.payload.org_id).toHaveLength(36);
expect(response.body.payload.user_id).toHaveLength(36);
process.env.ADMINACCESSTOKEN = response.body.payload.access_token;
orgid = response.body.payload.org_id;
userid = response.body.payload.user_id;
console.log(response.body.payload.user_id);
});
it("B Admin should be able to get current wallet balance", async () => {
const headers = {
authorization: "Bearer " + process.env.ADMINACCESSTOKEN,
access: "application/json",
};
const response = await request(process.env.TESTURL)
.get("/org/" + orgid + "/team/f341412a-86e6-11eb-b045-0242ac110003")
.set(headers);
expect(response.body.status).toBe(200);
expect(response.body.payload.status_message).toContain("OK");
expect(response.body.payload.team.wallet_amount).not.toBeNull();
expect(response.body.payload.team.your_role).toBe("Admin");
wallet_amount = response.body.payload.team.wallet_amount;
console.log("Wallet amount with admin is: " + wallet_amount);
});
it("C Login as team member", async () => {
const response = await request(process.env.TESTURL)
.post(configurations.appConfig.apiURLs.login)
.send(userData.loginDataNonAdmin);
expect(response.body.status).toBe(200);
expect(response.body.payload.status_message).toContain(
"token generated successfully"
);
expect(response.body.payload.org_id).toHaveLength(36);
expect(response.body.payload.user_id).toHaveLength(36);
process.env.MEMBERACCESSTOKEN = response.body.payload.access_token;
orgid = response.body.payload.org_id;
userid = response.body.payload.user_id;
console.log(response.body.payload.user_id);
});
it("D Team Member should be able to get current wallet balance", async () => {
const headers = {
authorization: "Bearer " + process.env.MEMBERACCESSTOKEN,
access: "application/json",
};
const response = await request(process.env.TESTURL)
.get("/org/" + orgid + "/team/f341412a-86e6-11eb-b045-0242ac110003")
.set(headers);
expect(response.body.status).toBe(200);
expect(response.body.payload.status_message).toContain("OK");
expect(response.body.payload.team.wallet_amount).not.toBeNull();
expect(response.body.payload.team.your_role).toBe("Member");
member_available_balance =
response.body.payload.team.your_membership_details.user_wallet
.available_balance;
member_available_balance = JSON.stringify(member_available_balance);
console.log(
"Available balance with non admin is: " + member_available_balance
);
});
it("E Send fund from admin wallet to member id", async () => {
const headers = {
authorization: "Bearer " + process.env.ADMINACCESSTOKEN,
access: "application/json",
};
// converting json object to string
const postData = {
amount: JSON.stringify({
to_amount: from_amount,
to_currency: "SGD",
from_amount: from_amount,
from_currency: "SGD",
fee: 0,
}),
sender: JSON.stringify({
team_id: "f341412a-86e6-11eb-b045-0242ac110003",
type: "team",
user_id: "f34e5608-86e6-11eb-bd0a-0242ac110003",
}),
receiver: JSON.stringify({
team_id: "f341412a-86e6-11eb-b045-0242ac110003",
type: "user",
user_id: "e460d858-96d3-11eb-96f7-0242ac110003",
}),
organisation_id: orgid,
};
const res = await request(process.env.TESTURL)
.post(configurations.appConfig.apiURLs.sendFund)
.set(headers)
.send(postData);
reference_number = res.body.payload.reference_number;
amountSent = res.body.payload.amount;
console.log("Reference number is: " + reference_number);
console.log("Amount sent is : " + amountSent);
expect(amountSent).toBe(from_amount);
});
it("F Get all transactions and grep if last transaction reference id is present", async () => {
const headers = {
authorization: "Bearer " + process.env.ADMINACCESSTOKEN,
access: "application/json",
};
// converting json object to string
const postData = {
fields: JSON.stringify({
id: true,
transaction_number: true,
amount: true,
past_balance: true,
available_balance: true,
currency_id: true,
user_id: true,
organisation_id: true,
created_at: true,
type: true,
description: true,
vendor_transaction_id: true,
merchant: true,
card_type: true,
card_last_four: true,
foreign_currency_amount: true,
foreign_currency_code: true,
vendor_fee_amount: true,
subwallet_id: true,
team_id: true,
isCredit: true,
receipts: true,
category: true,
running_balance: true,
simplified_merchant_name: true,
}),
filters: JSON.stringify({
organisation_id: "f33ee556-86e6-11eb-9d9d-0242ac110003",
}),
search_filters: JSON.stringify({}),
organisation_id: orgid,
pg: 0,
limit: 100,
};
const res = await request(process.env.TESTURL)
.post(configurations.appConfig.apiURLs.getTransactions)
.set(headers)
.send(postData);
let transactions = await res.body.payload.transactions[0];
console.log(transactions);
let transaction_number = transactions.transaction_number;
console.log("transaction_number is: " + transaction_number);
expect(transaction_number).toStrictEqual(reference_number);
let isCredit = transactions.isCredit;
expect(isCredit).toStrictEqual("0");
let org_new_balance = JSON.stringify(
transactions.running_balance.org_new_balance
);
let org_previous_balance = JSON.stringify(
transactions.running_balance.org_previous_balance
);
console.log("org_previous_balance: " + org_previous_balance);
console.log("org_new_balance: " + org_new_balance);
if (isCredit === "0") {
expect(wallet_amount).toBe(transactions.past_balance);
expect(parseFloat(transactions.available_balance)).toBe(
transactions.past_balance - parseInt(from_amount)
);
expect(org_new_balance).toEqual(org_previous_balance);
} // did not understood when isCredit will be 1
else if (isCredit === "1") {
expect(parseFloat(transactions.available_balance)).toBe(
transactions.past_balance + parseInt(from_amount)
);
}
});
it("G Team Member current balence should be equal to previous balance plus amount sent", async () => {
const headers = {
authorization: "Bearer " + process.env.MEMBERACCESSTOKEN,
access: "application/json",
};
const response = await request(process.env.TESTURL)
.get("/org/" + orgid + "/team/f341412a-86e6-11eb-b045-0242ac110003")
.set(headers);
expect(response.body.status).toBe(200);
expect(response.body.payload.status_message).toContain("OK");
expect(response.body.payload.team.wallet_amount).not.toBeNull();
expect(response.body.payload.team.your_role).toBe("Member");
console.log(response.body);
member_updated_available_balance =
response.body.payload.team.your_membership_details.user_wallet
.available_balance;
member_updated_available_balance = JSON.stringify(
member_updated_available_balance
);
expect(parseFloat(member_updated_available_balance)).toEqual(
parseInt(from_amount) + parseFloat(member_available_balance)
);
console.log(
"Available balance" +
member_updated_available_balance +
"with non admin after Sending amount equal to " +
from_amount +
"+ " +
member_available_balance
);
});
});