Skip to content

Commit 0461569

Browse files
authored
Merge pull request #14 from PerfectFit-project/248-onboarding
248 onboarding
2 parents a402303 + 0703d2c commit 0461569

File tree

4 files changed

+220
-3
lines changed

4 files changed

+220
-3
lines changed

niceday-api/api/openapi.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ paths:
6767
"200":
6868
description: Success
6969
x-swagger-router-controller: UserData
70+
/connectionrequests:
71+
get:
72+
summary: Get the pending connection requests
73+
operationId: getConnectionRequests
74+
responses:
75+
"200":
76+
description: Success
77+
content:
78+
application/json:
79+
schema:
80+
description: List of connection requests
81+
type: array
82+
items:
83+
$ref: '#/components/schemas/ConnectionRequest'
84+
x-swagger-router-controller: ConnectionRequests
7085
/usertrackers/smoking/{userId}:
7186
get:
7287
summary: Get smoking tracker data for specific user
@@ -106,6 +121,26 @@ paths:
106121
items:
107122
$ref: '#/components/schemas/SmokingTrackerEntry'
108123
x-swagger-router-controller: UserTrackers
124+
/acceptconnection:
125+
post:
126+
summary: Accept the connection request specified in the body
127+
operationId: setAcceptConnection
128+
requestBody:
129+
content:
130+
application/json:
131+
schema:
132+
required:
133+
- invitation_id
134+
type: object
135+
properties:
136+
invitation_id:
137+
type: string
138+
description: ID of the connection request
139+
example: "38527"
140+
responses:
141+
"200":
142+
description: Success
143+
x-swagger-router-controller: ConnectionRequests
109144
/usertrackers/statuses:
110145
post:
111146
summary: Enable or disable trackers for a user
@@ -319,3 +354,63 @@ components:
319354
description: after
320355
example: 60
321356

357+
ConnectionRequest:
358+
description: Connection request object
359+
type: object
360+
properties:
361+
id:
362+
type: integer
363+
description: User ID
364+
example: 38527
365+
hashId:
366+
type: string
367+
description: Uhashed ID
368+
example: '9o0xZ0JGRauKnlY31dYJjA'
369+
firstName:
370+
type: string
371+
description: First Name
372+
example: 'Name'
373+
lastName:
374+
type: string
375+
description: Last Name
376+
example: 'Last Name'
377+
bio:
378+
type: string
379+
description: Bio
380+
example: ''
381+
location:
382+
type: string
383+
description: Location
384+
example: ''
385+
gender:
386+
type: string
387+
description: Gender
388+
example: 'NOT_DEFINED'
389+
birthDate:
390+
type: string
391+
description: birth date
392+
example: '1970-01-01'
393+
email:
394+
type: string
395+
description: email
396+
example: 'email@mail.com'
397+
registerDate:
398+
type: string
399+
description: Register Date
400+
example: '2023-01-26T16:16:35.575Z'
401+
image:
402+
type: string
403+
description: User ID
404+
example: 'https://image.jpg'
405+
invitationCreatedAt:
406+
type: string
407+
description: User ID
408+
example: '2023-06-06T11:37:57.700Z'
409+
invitationId:
410+
type: integer
411+
description: Invitation ID
412+
example: 18994,
413+
proposedBy:
414+
type: string
415+
description: User ID
416+
example: ''
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const utils = require('../utils/writer.jsx');
2+
const ConnectionRequest = require('../service/ConnectionRequestsService');
3+
4+
// eslint-disable-next-line no-unused-vars
5+
module.exports.getConnectionRequests = function getConnectionRequests(req, res, next, body) {
6+
ConnectionRequest.getConnectionRequests(req)
7+
.then((response) => {
8+
utils.writeJson(res, response);
9+
})
10+
.catch((response) => {
11+
utils.writeJson(res, utils.respondWithCode(500, response));
12+
});
13+
};
14+
15+
// eslint-disable-next-line no-unused-vars
16+
module.exports.setAcceptConnection = function setAcceptConnection(req, res, next, body) {
17+
ConnectionRequest.setAcceptConnection(req, body)
18+
.then((response) => {
19+
utils.writeJson(res, response);
20+
})
21+
.catch((response) => {
22+
utils.writeJson(res, utils.respondWithCode(500, response));
23+
});
24+
};

niceday-api/index.test.js

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const MOCK_TRACKER_REMINDER_RESPONSE = {
1717
owner: NICEDAY_TEST_USER_ID,
1818
startTime: '2022-05-17T15:10:00.000Z',
1919
};
20+
const MOCK_REQUEST_ID = '18981';
21+
const MOCK_PENDING_REQUESTS = [
22+
{
23+
id: NICEDAY_TEST_USER_ID,
24+
invitationId: MOCK_REQUEST_ID,
25+
},
26+
];
27+
const MOCK_ACCEPT_REQUESTS = {};
2028

2129
// Contains all tests which require a mocked Senseserver
2230
describe('Tests on niceday-api server using mocked goalie-js', () => {
@@ -41,6 +49,12 @@ describe('Tests on niceday-api server using mocked goalie-js', () => {
4149
getConnectedContacts: () => new Promise((resolve) => {
4250
resolve(MOCK_USER_DATA);
4351
}),
52+
getRequestedContacts: () => new Promise((resolve) => {
53+
resolve(MOCK_PENDING_REQUESTS);
54+
}),
55+
acceptInvitation: () => new Promise((resolve) => {
56+
resolve(MOCK_ACCEPT_REQUESTS);
57+
}),
4458
})),
4559
Authentication: jest.fn().mockImplementation(() => ({
4660
login: () => new Promise((resolve) => {
@@ -136,9 +150,9 @@ describe('Tests on niceday-api server using mocked goalie-js', () => {
136150
});
137151

138152
it('Test getting smoking tracker data with /usertrackers/smoking/ endpoint', () => {
139-
/*
140-
Sends a GET to the /usertrackers/smoking endpoint.
141-
*/
153+
/*
154+
Sends a GET to the /usertrackers/smoking endpoint.
155+
*/
142156

143157
const urlreq = `http://localhost:${NICEDAY_TEST_SERVERPORT}/usertrackers/smoking/${NICEDAY_TEST_USER_ID}?`;
144158
const params = new URLSearchParams({
@@ -187,4 +201,43 @@ describe('Tests on niceday-api server using mocked goalie-js', () => {
187201
throw new Error(`Error during fetch: ${error}`);
188202
});
189203
});
204+
205+
it('Test getting pending contact request with /connectionrequests endpoint', () => {
206+
/*
207+
Sends a GET to the /connectionrequests endpoint.
208+
*/
209+
210+
const urlreq = `http://localhost:${NICEDAY_TEST_SERVERPORT}/connectionrequests`;
211+
return fetch(urlreq)
212+
.then((response) => response.json())
213+
.then((responseBody) => {
214+
expect(responseBody).toEqual(MOCK_PENDING_REQUESTS);
215+
})
216+
.catch((error) => {
217+
throw new Error(`Error during fetch: ${error}`);
218+
});
219+
});
220+
221+
it('Test accepting contact request /acceptconnection endpoint', () => {
222+
/*
223+
Sends a POST to the /acceptconnection endpoint.
224+
*/
225+
226+
const urlreq = `http://localhost:${NICEDAY_TEST_SERVERPORT}/acceptconnection`;
227+
const data = JSON.stringify({
228+
invitation_id: MOCK_REQUEST_ID,
229+
});
230+
return fetch(urlreq, {
231+
method: 'post',
232+
headers: { 'Content-Type': 'application/json' },
233+
body: data,
234+
})
235+
.then((response) => response.json())
236+
.then((responseBody) => {
237+
expect(responseBody).toEqual(MOCK_ACCEPT_REQUESTS);
238+
})
239+
.catch((error) => {
240+
throw new Error(`Error during fetch: ${error}`);
241+
});
242+
});
190243
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { Contacts, SenseServer } = require('@sense-os/goalie-js');
2+
require('isomorphic-fetch');
3+
4+
const { ENVIRONMENT } = process.env;
5+
let selectedServer;
6+
7+
if (ENVIRONMENT === 'dev') {
8+
selectedServer = SenseServer.Alpha;
9+
} else {
10+
selectedServer = SenseServer.Production;
11+
}
12+
13+
const contacts = new Contacts(selectedServer);
14+
15+
/**
16+
* Get the pending connection requests.
17+
* Returns the JSON as received from the SenseServer.
18+
* @param req - The node.js express request object
19+
* @param body - The node.js express body object.
20+
* */
21+
exports.getConnectionRequests = (req) => new Promise((resolve, reject) => {
22+
contacts.getRequestedContacts(req.app.get('token'))
23+
.then((result) => {
24+
resolve(result);
25+
})
26+
.catch((error) => {
27+
reject(Error(`Error during connections requests retrieval: ${error}`));
28+
});
29+
});
30+
31+
/**
32+
* Accept the pending connection request indentified by the id in the request body.
33+
* Returns the JSON as received from the SenseServer.
34+
* @param req - The node.js express request object
35+
* @param body - The node.js express body object. Should contain invitation id.
36+
* */
37+
exports.setAcceptConnection = (req, body) => new Promise((resolve, reject) => {
38+
contacts.acceptInvitation(req.app.get('token'), body.invitation_id)
39+
.then((result) => {
40+
resolve(result);
41+
})
42+
.catch((error) => {
43+
reject(Error(`Error during connections requests acceptance: ${error}`));
44+
});
45+
});

0 commit comments

Comments
 (0)