Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api-gateway): add husky actions to api-gateway #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ if [ ${#messagesPackageFiles} -gt 0 ]; then
# Run pre-commit actions only if there are changes in the messages package.
cd packages/messages && yarn precommit
fi

apiGatewayPackageFiles=$(echo "$fileList" | grep -E 'packages\/api-gateway\/.+$' || echo '')
if [ ${#apiGatewayPackageFiles} -gt 0 ]; then
# Run pre-commit actions only if there are changes in the api-gateway package.
cd packages/api-gateway && yarn precommit
fi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Given a client that wants to get the Places data', () => {
describe('When the server cannot connect to db', () => {
beforeAll(() => {
getPlaces.mockImplementation(new Error());
})
});
test('Then the back must return a 500 status code', async () => {
const response = await fastify.inject({
method: 'GET',
Expand Down
5 changes: 2 additions & 3 deletions packages/api-gateway/__tests__/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ jest.mock('@booking-services/places', () => ({
getPlaces: jest.fn(() => []),
deletePlace: jest.fn((id) => {
if (typeof id !== 'number' || id >= 1000) {
throw new Error();
throw new Error();
}
return;
}),
}),
}));

jest.mock('@booking-services/messages');
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ const { listChatMessages } = require('@booking-services/messages');
const { fastify } = require('../../../../../../src/drivers/http/server');

// Mocks
const customerID = faker.datatype.uuid();
const hostID = faker.datatype.uuid();

const mockListChatMessages = [
{
_id: faker.datatype.uuid(),
bookingId: faker.datatype.uuid(),
hostId: hostID,
customerId: customerID,
createdAt: faker.datatype.datetime(),
updatedAt: faker.datatype.datetime(),
deletedAt: null,
},
];
const mockUserId = faker.datatype.uuid();

const mockListChatMessages = {
page: 1,
messages: [
{
_id: faker.datatype.uuid(),
chatId: faker.datatype.uuid(),
text: faker.lorem.sentence(),
createdBy: mockUserId,
createdAt: faker.datatype.datetime(),
deletedAt: null,
},
],
};

describe('GET /chats/{chatId}/messages', () => {
describe('given an authenticated user and a valid chatId', () => {
// TODO: Change this once we have authentication ready
const bearerToken = customerID;
const bearerToken = mockUserId;
const chatId = 1;

const headers = {
Expand Down
3 changes: 2 additions & 1 deletion packages/api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"test": "jest --runInBand",
"test:watch": "jest --watch",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"precommit": "yarn lint && yarn test"
},
"bugs": {
"url": "https://github.com/gh0stl1m/backend-services/issues"
Expand Down
16 changes: 11 additions & 5 deletions packages/api-gateway/src/drivers/http/adapters/users/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function createUser(req, reply) {

return reply
.code(200)
.header("Content-Type", "application/json; chartset:utf-8")
.header('Content-Type', 'application/json; chartset:utf-8')
.send({ result });
} catch (error) {
return errorHandler(error, reply);
Expand All @@ -70,11 +70,13 @@ async function validateUser(req, reply) {
phoneNumber,
emergencyNumber,
passport,
address: { country, city, state, address, zip },
address: {
country, city, state, address, zip,
},
} = req.body;
const { userId } = req.params;

req.log.info("[http-server]: Creating user with: ", {
req.log.info('[http-server]: Creating user with: ', {
userId,
firstName,
secondName,
Expand All @@ -89,7 +91,9 @@ async function validateUser(req, reply) {
phoneNumber,
emergencyNumber,
passport,
address: { country, city, state, address, zip },
address: {
country, city, state, address, zip,
},
});

const result = await this.userServices.validateUser({
Expand All @@ -107,7 +111,9 @@ async function validateUser(req, reply) {
phoneNumber,
emergencyNumber,
passport,
address: { country, city, state, address, zip },
address: {
country, city, state, address, zip,
},
});

if (result.isBoom === true) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-gateway/src/drivers/http/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { userAdapter } = require('../../adapters');
const { createUserSchema, validateUserSchema} = require('./schema');
const { createUserSchema, validateUserSchema } = require('./schema');

async function UserRouter(fastify) {
await fastify.post('/', { schema: createUserSchema }, userAdapter.createUser);
Expand Down