Skip to content

Commit de60cbb

Browse files
committed
Merge branch 'feature/payment-processing' into feature/work-periods
2 parents d24bfd8 + 4410565 commit de60cbb

File tree

7 files changed

+398
-5
lines changed

7 files changed

+398
-5
lines changed

app-constants.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ const Scopes = {
4747
ALL_WORK_PERIOD_PAYMENT: 'all:taas-workPeriodPayments'
4848
}
4949

50+
const ChallengeStatus = {
51+
DRAFT: 'Draft',
52+
ACTIVE: 'Active',
53+
COMPLETED: 'Completed'
54+
}
55+
5056
module.exports = {
5157
UserRoles,
5258
FullManagePermissionRoles,
53-
Scopes
59+
Scopes,
60+
ChallengeStatus
5461
}

config/default.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,11 @@ module.exports = {
138138
// SendGrid email template ID for requesting extension
139139
REQUEST_EXTENSION_SENDGRID_TEMPLATE_ID: process.env.REQUEST_EXTENSION_SENDGRID_TEMPLATE_ID,
140140
// the URL where TaaS App is hosted
141-
TAAS_APP_URL: process.env.TAAS_APP_URL || 'https://platform.topcoder-dev.com/taas/myteams'
141+
TAAS_APP_URL: process.env.TAAS_APP_URL || 'https://platform.topcoder-dev.com/taas/myteams',
142+
// environment variables for Payment Service
143+
ROLE_ID_SUBMITTER: process.env.ROLE_ID_SUBMITTER || '732339e7-8e30-49d7-9198-cccf9451e221',
144+
TYPE_ID_TASK: process.env.TYPE_ID_TASK || 'ecd58c69-238f-43a4-a4bb-d172719b9f31',
145+
DEFAULT_TIMELINE_TEMPLATE_ID: process.env.DEFAULT_TIMELINE_TEMPLATE_ID || '53a307ce-b4b3-4d6f-b9a1-3741a58f77e6',
146+
DEFAULT_TRACK_ID: process.env.DEFAULT_TRACK_ID || '9b6fc876-f4d9-4ccb-9dfd-419247628825'
147+
142148
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"services:logs": "docker-compose -f ./local/docker-compose.yml logs",
2727
"local:init": "npm run local:reset && npm run data:import -- --force",
2828
"local:reset": "npm run delete-index -- --force || true && npm run create-index -- --force && npm run init-db force",
29-
"cov": "nyc --reporter=html --reporter=text mocha test/unit/*.test.js --timeout 30000 --exit"
29+
"cov": "nyc --reporter=html --reporter=text mocha test/unit/*.test.js --timeout 30000 --exit",
30+
"demo-payment": "node scripts/demo-payment"
3031
},
3132
"keywords": [],
3233
"author": "",
@@ -85,4 +86,4 @@
8586
"test/unit/**"
8687
]
8788
}
88-
}
89+
}

scripts/demo-payment/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### DEMO PAYMENT SCRIPT
2+
3+
This demo script tests the functionality of PaymentService.
4+
5+
Parameters for creating payments are hardcoded in the script. There are severel groups of parameters, each of them tests a certain functionality of the demo service. You can always insert new group of parameters to run in the script.
6+
7+
Before start set the following environment variables:
8+
AUTH0_URL=
9+
AUTH0_AUDIENCE=
10+
AUTH0_AUDIENCE_UBAHN=
11+
AUTH0_CLIENT_ID=
12+
AUTH0_CLIENT_SECRET=
13+
14+
To run the script use the following commands:
15+
16+
```
17+
npm install
18+
npm run lint
19+
npm run demo-payment
20+
```
21+
22+
Read the logger to see results.

scripts/demo-payment/index.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
require('../../src/bootstrap')
2+
const logger = require('../../src/common/logger')
3+
const paymentService = require('../../src/services/PaymentService')
4+
5+
const options = [
6+
{
7+
name: 'Test joi validation for projectId-1',
8+
content: {
9+
userHandle: 'pshah_manager',
10+
amount: 3,
11+
billingAccountId: 80000069,
12+
name: 'test payment for pshah_manager',
13+
description: '## test payment'
14+
}
15+
},
16+
{
17+
name: 'Test joi validation for projectId-2',
18+
content: {
19+
projectId: 'project',
20+
userHandle: 'pshah_manager',
21+
amount: 3,
22+
billingAccountId: 80000069,
23+
name: 'test payment for pshah_manager',
24+
description: '## test payment'
25+
}
26+
},
27+
{
28+
name: 'Test joi validation for userHandle',
29+
content: {
30+
projectId: 17234,
31+
amount: 3,
32+
billingAccountId: 80000069,
33+
name: 'test payment for pshah_manager',
34+
description: '## test payment'
35+
}
36+
},
37+
{
38+
name: 'Test joi validation for amount-1',
39+
content: {
40+
projectId: 17234,
41+
userHandle: 'pshah_manager',
42+
billingAccountId: 80000069,
43+
name: 'test payment for pshah_manager',
44+
description: '## test payment'
45+
}
46+
},
47+
{
48+
name: 'Test joi validation for amount-2',
49+
content: {
50+
projectId: 17234,
51+
userHandle: 'pshah_manager',
52+
amount: -10,
53+
billingAccountId: 80000069,
54+
name: 'test payment for pshah_manager',
55+
description: '## test payment'
56+
}
57+
},
58+
{
59+
name: 'Successful payment creation',
60+
content: {
61+
projectId: 17234,
62+
userHandle: 'pshah_manager',
63+
amount: 3,
64+
billingAccountId: 80000069,
65+
name: 'test payment for pshah_manager',
66+
description: '## test payment'
67+
}
68+
},
69+
{
70+
name: 'Successful payment creation without name and description',
71+
content: {
72+
projectId: 17234,
73+
userHandle: 'pshah_customer',
74+
amount: 2,
75+
billingAccountId: 80000069
76+
}
77+
},
78+
{
79+
name: 'Failing payment creation with no active billing account',
80+
content: {
81+
projectId: 16839,
82+
userHandle: 'pshah_customer',
83+
amount: 2,
84+
billingAccountId: 80000069,
85+
name: 'test payment for pshah_customer',
86+
description: '## test payment'
87+
}
88+
},
89+
{
90+
name: 'Failing payment creation with non existing user',
91+
content: {
92+
projectId: 17234,
93+
userHandle: 'eisbilir',
94+
amount: 2,
95+
billingAccountId: 80000069
96+
}
97+
}
98+
]
99+
100+
const test = async () => {
101+
for (const option of options) {
102+
logger.info({ component: 'demo-payment', context: 'test', message: `Starting to create payment for: ${option.name}` })
103+
await paymentService.createPayment(option.content)
104+
.then(data => {
105+
logger.info({ component: 'demo-payment', context: 'test', message: `Payment successfuly created for: ${option.name}` })
106+
})
107+
// eslint-disable-next-line handle-callback-err
108+
.catch(err => {
109+
logger.error({ component: 'demo-payment', context: 'test', message: `Payment can't be created for: ${option.name}` })
110+
})
111+
}
112+
}
113+
// wait for bootstrap to complete it's job.
114+
setTimeout(test, 2000)

src/common/helper.js

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,82 @@ async function deleteProjectMember (currentUser, projectId, projectMemberId) {
11761176
}
11771177
}
11781178

1179+
/**
1180+
* Create a new challenge
1181+
*
1182+
* @param {Object} data challenge data
1183+
* @param {String} token m2m token
1184+
* @returns {Object} the challenge created
1185+
*/
1186+
async function createChallenge (data, token) {
1187+
if (!token) {
1188+
token = await getM2MToken()
1189+
}
1190+
const url = `${config.TC_API}/challenges`
1191+
localLogger.debug({ context: 'createChallenge', message: `EndPoint: POST ${url}` })
1192+
localLogger.debug({ context: 'createChallenge', message: `Request Body: ${JSON.stringify(data)}` })
1193+
const { body: challenge, status: httpStatus } = await request
1194+
.post(url)
1195+
.set('Authorization', `Bearer ${token}`)
1196+
.set('Content-Type', 'application/json')
1197+
.set('Accept', 'application/json')
1198+
.send(data)
1199+
localLogger.debug({ context: 'createChallenge', message: `Status Code: ${httpStatus}` })
1200+
localLogger.debug({ context: 'createChallenge', message: `Response Body: ${JSON.stringify(challenge)}` })
1201+
return challenge
1202+
}
1203+
1204+
/**
1205+
* Update a challenge
1206+
*
1207+
* @param {String} challengeId id of the challenge
1208+
* @param {Object} data challenge data
1209+
* @param {String} token m2m token
1210+
* @returns {Object} the challenge updated
1211+
*/
1212+
async function updateChallenge (challengeId, data, token) {
1213+
if (!token) {
1214+
token = await getM2MToken()
1215+
}
1216+
const url = `${config.TC_API}/challenges/${challengeId}`
1217+
localLogger.debug({ context: 'updateChallenge', message: `EndPoint: PATCH ${url}` })
1218+
localLogger.debug({ context: 'updateChallenge', message: `Request Body: ${JSON.stringify(data)}` })
1219+
const { body: challenge, status: httpStatus } = await request
1220+
.patch(url)
1221+
.set('Authorization', `Bearer ${token}`)
1222+
.set('Content-Type', 'application/json')
1223+
.set('Accept', 'application/json')
1224+
.send(data)
1225+
localLogger.debug({ context: 'updateChallenge', message: `Status Code: ${httpStatus}` })
1226+
localLogger.debug({ context: 'updateChallenge', message: `Response Body: ${JSON.stringify(challenge)}` })
1227+
return challenge
1228+
}
1229+
1230+
/**
1231+
* Create a challenge resource
1232+
*
1233+
* @param {Object} data resource
1234+
* @param {String} token m2m token
1235+
* @returns {Object} the resource created
1236+
*/
1237+
async function createChallengeResource (data, token) {
1238+
if (!token) {
1239+
token = await getM2MToken()
1240+
}
1241+
const url = `${config.TC_API}/resources`
1242+
localLogger.debug({ context: 'createChallengeResource', message: `EndPoint: POST ${url}` })
1243+
localLogger.debug({ context: 'createChallengeResource', message: `Request Body: ${JSON.stringify(data)}` })
1244+
const { body: resource, status: httpStatus } = await request
1245+
.post(url)
1246+
.set('Authorization', `Bearer ${token}`)
1247+
.set('Content-Type', 'application/json')
1248+
.set('Accept', 'application/json')
1249+
.send(data)
1250+
localLogger.debug({ context: 'createChallengeResource', message: `Status Code: ${httpStatus}` })
1251+
localLogger.debug({ context: 'createChallengeResource', message: `Response Body: ${JSON.stringify(resource)}` })
1252+
return resource
1253+
}
1254+
11791255
module.exports = {
11801256
getParamFromCliArgs,
11811257
promptUser,
@@ -1219,5 +1295,8 @@ module.exports = {
12191295
createProjectMember,
12201296
listProjectMembers,
12211297
listProjectMemberInvites,
1222-
deleteProjectMember
1298+
deleteProjectMember,
1299+
createChallenge,
1300+
updateChallenge,
1301+
createChallengeResource
12231302
}

0 commit comments

Comments
 (0)