Skip to content

Commit 0363880

Browse files
authored
Merge pull request #18 from PerfectFit-project/354-disconnect-user
new endpoint for disconnecting user
2 parents 0bd41ec + 16ea922 commit 0363880

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

niceday-api/api/openapi.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,31 @@ paths:
140140
responses:
141141
"200":
142142
description: Success
143+
"500":
144+
description: Failed
143145
x-swagger-router-controller: ConnectionRequests
146+
/removecontact:
147+
post:
148+
summary: Remove the contact of the user specified in the body
149+
operationId: removeContact
150+
requestBody:
151+
content:
152+
application/json:
153+
schema:
154+
required:
155+
- user_id
156+
type: object
157+
properties:
158+
user_id:
159+
type: string
160+
description: ID of the user to be removed
161+
example: "38527"
162+
responses:
163+
"200":
164+
description: Success
165+
"500":
166+
description: Failed
167+
x-swagger-router-controller: RemoveContact
144168
/usertrackers/statuses:
145169
post:
146170
summary: Enable or disable trackers for a user
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const utils = require('../utils/writer.jsx');
2+
const RemoveContact = require('../service/RemoveContactService');
3+
4+
// eslint-disable-next-line no-unused-vars
5+
module.exports.removeContact = function removeContact(req, res, next, body) {
6+
RemoveContact.removeContact(req, body)
7+
.then((response) => {
8+
utils.writeJson(res, response);
9+
})
10+
.catch((response) => {
11+
utils.writeJson(res, utils.respondWithCode(500, response));
12+
});
13+
};

niceday-api/index.test.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const MOCK_PENDING_REQUESTS = [
2727
invitationId: MOCK_REQUEST_ID,
2828
},
2929
];
30-
const MOCK_ACCEPT_REQUESTS = {};
30+
const MOCK_EMPTY_RESPONSE = {};
3131

3232
// Contains all tests which require a mocked Senseserver
3333
describe('Tests on niceday-api server using mocked goalie-js', () => {
@@ -74,7 +74,10 @@ describe('Tests on niceday-api server using mocked goalie-js', () => {
7474
resolve(MOCK_PENDING_REQUESTS);
7575
}),
7676
acceptInvitation: () => new Promise((resolve) => {
77-
resolve(MOCK_ACCEPT_REQUESTS);
77+
resolve(MOCK_EMPTY_RESPONSE);
78+
}),
79+
removeContactFromUserContact: () => new Promise((resolve) => {
80+
resolve(MOCK_EMPTY_RESPONSE);
7881
}),
7982
})),
8083
Authentication: jest.fn().mockImplementation(() => ({
@@ -255,7 +258,30 @@ describe('Tests on niceday-api server using mocked goalie-js', () => {
255258
})
256259
.then((response) => response.json())
257260
.then((responseBody) => {
258-
expect(responseBody).toEqual(MOCK_ACCEPT_REQUESTS);
261+
expect(responseBody).toEqual(MOCK_EMPTY_RESPONSE);
262+
})
263+
.catch((error) => {
264+
throw new Error(`Error during fetch: ${error}`);
265+
});
266+
});
267+
268+
it('Test remove contact /removecontact endpoint', () => {
269+
/*
270+
Sends a POST to the /acceptconnection endpoint.
271+
*/
272+
273+
const urlreq = `http://localhost:${NICEDAY_TEST_SERVERPORT}/removecontact`;
274+
const data = JSON.stringify({
275+
user_id: NICEDAY_TEST_USER_ID.toString(),
276+
});
277+
return fetch(urlreq, {
278+
method: 'post',
279+
headers: { 'Content-Type': 'application/json' },
280+
body: data,
281+
})
282+
.then((response) => response.json())
283+
.then((responseBody) => {
284+
expect(responseBody).toEqual(MOCK_EMPTY_RESPONSE);
259285
})
260286
.catch((error) => {
261287
throw new Error(`Error during fetch: ${error}`);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.removeContact = (req, body) => new Promise((resolve, reject) => {
22+
console.log(req.app.get('token'), req.app.get('therapistId'), body.user_id);
23+
contacts.removeContactFromUserContact(req.app.get('token'), req.app.get('therapistId'), body.user_id)
24+
.then((result) => {
25+
resolve(result);
26+
})
27+
.catch((error) => {
28+
reject(Error(`Error during contact temoval: ${error}`));
29+
});
30+
});

0 commit comments

Comments
 (0)