Skip to content

Commit

Permalink
Merge pull request #92 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Merge para despliegue - Tercera entrega
  • Loading branch information
iyanfdezz authored Apr 7, 2024
2 parents d6164f5 + 1735c89 commit 5262bbe
Show file tree
Hide file tree
Showing 61 changed files with 29,240 additions and 22,329 deletions.
174 changes: 174 additions & 0 deletions gatewayservice/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
port: 8001,
address: '127.0.0.1',
syscall: 'connect',
code: 'ECONNREFUSED',
errno: -4078,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ 'xhr', 'http' ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: null },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, \*/\*',
'Content-Type': undefined,
'User-Agent': 'axios/1.6.5',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
params: { username: 'admin' },
method: 'get',
url: 'http://localhost:8001/users/search',
data: undefined
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError],
socket: [Function: handleRequestSocket]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: Infinity,
protocol: 'http:',
path: '/users/search?username=admin',
method: 'GET',
headers: [Object: null prototype],
agents: [Object],
auth: undefined,
family: undefined,
beforeRedirect: [Function: dispatchBeforeRedirect],
beforeRedirects: [Object],
hostname: 'localhost',
port: '8001',
agent: undefined,
nativeProtocols: [Object],
pathname: '/users/search',
search: '?username=admin'
},
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [Socket],
_header: 'GET /users/search?username=admin HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'User-Agent: axios/1.6.5\r\n' +
'Accept-Encoding: gzip, compress, deflate, br\r\n' +
'Host: localhost:8001\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/users/search?username=admin',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'localhost',
protocol: 'http:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kEndCalled)]: true,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kUniqueHeaders)]: null
},
_currentUrl: 'http://localhost:8001/users/search?username=admin',
[Symbol(kCapture)]: false
},
cause: Error: connect ECONNREFUSED 127.0.0.1:8001
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8001
}
}
53 changes: 53 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ app.get("/health", (req, res) => {
});

returnError = (res, error) => {
console.log(error);
res.status(error.response.status).json({ error: error.response.data.error });
}

Expand Down Expand Up @@ -81,6 +82,58 @@ app.post("/saveGameList", async (req, res) => {
}
});

app.get("/friends", async (req, res) => {
try {
// Forward the question request to the user service
const userResponse = await axios.get(
userServiceUrl + "/friends",
{ params: req.query }
);
res.json(userResponse.data);
} catch (error) {
returnError(res, error);
}
});

app.get("/users/search", async (req, res) => {
try {
// Forward the question request to the user service
const userResponse = await axios.get(
userServiceUrl + "/users/search",
{ params: req.query }
);
res.json(userResponse.data);
} catch (error) {
returnError(res, error);
}
});

app.post("/users/add-friend", async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(
userServiceUrl + "/users/add-friend",
req.body
);
res.json(gameResponse.data);
} catch (error) {
returnError(res, error);
}
});

app.post("/users/remove-friend", async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(
userServiceUrl + "/users/remove-friend",
req.body
);
res.json(gameResponse.data);
} catch (error) {
returnError(res, error);
}
});

app.get("/questions", async (req, res) => {
try {
// Forward the question request to the question service
Expand Down
40 changes: 40 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,44 @@ describe("Gateway Service", () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ saved: true });
});

// Prueba para la ruta /friends
it("should forward friends request to user service", async () => {
axios.get.mockResolvedValueOnce({ data: { friends: ["friend1", "friend2"] } });

const response = await request(app).get("/friends").query({ userId: "testuser" });

expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ friends: ["friend1", "friend2"] });
});

// Prueba para la ruta /users/search
it("should forward search users request to user service", async () => {
axios.get.mockResolvedValueOnce({ data: { users: ["user1", "user2"] } });

const response = await request(app).get("/users/search").query({ query: "test" });

expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ users: ["user1", "user2"] });
});

// Prueba para la ruta /users/add-friend
it("should forward add friend request to user service", async () => {
axios.post.mockResolvedValueOnce({ data: { success: true } });

const response = await request(app).post("/users/add-friend").send({ userId: "user1", friendId: "user2" });

expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ success: true });
});

// Prueba para la ruta /users/remove-friend
it("should forward remove friend request to user service", async () => {
axios.post.mockResolvedValueOnce({ data: { success: true } });

const response = await request(app).post("/users/remove-friend").send({ userId: "user1", friendId: "user2" });

expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ success: true });
});
});
Loading

0 comments on commit 5262bbe

Please sign in to comment.