Skip to content

Commit

Permalink
Merge pull request #138 from mia-ajuda/develop
Browse files Browse the repository at this point in the history
Versão 2.1.0
  • Loading branch information
sudjoao authored Aug 26, 2022
2 parents df45f04 + 5e2f5c9 commit ca7cf87
Show file tree
Hide file tree
Showing 44 changed files with 4,028 additions and 2,127 deletions.
Binary file added .DS_Store
Binary file not shown.
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@
"max-len": [
"error",
{
"code": 120
"code": 120,
"ignoreStrings": true
}
],
"no-useless-catch": 0,
"class-methods-use-this": 0
"class-methods-use-this": 0,
"no-multiple-empty-lines": ["error", { "max": 2, "maxBOF": 2, "maxEOF": 0 }]
},
"settings": {
"import/extensions": [".js",".jsx",".ts",".tsx"],
"import/resolver": {
"node": {
"extensions": [".js",".jsx",".ts",".tsx"]
}
}
}
}
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: build, test and lint

on:
push :
branches : [ "**" ]
pull_request:
types: [ opened ]

jobs:
build-test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash

steps:
- name: 🏗 Setup repo
uses: actions/checkout@v3

- name: 🏗 Setup node
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn
cache-dependency-path: yarn.lock

- name: 🏗 Config files
run: |
echo "$FIREBASE_CONFIG_DEV" > ./src/config/firebaseAuthConfig.js
env:
FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }}

- name: 📦 Install dependencies
run: yarn install --pure-lockfile --non-interactive

- name: 📦 Run test
run: yarn test

- name: 📦 Run lint
run: yarn lint
43 changes: 43 additions & 0 deletions .github/workflows/submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: submit image to dockerhub

on:
push :
branches : [ master, develop ]


jobs:
deploy:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }}
FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }}
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
RCLONE_CONFIG: ${{ secrets.RCLONE_CONFIG }}

steps:
- name: 🏗 Setup repo
uses: actions/checkout@v3

- name: 🏗 Config dev files
if: github.ref == 'refs/heads/develop'
run: |
echo "$FIREBASE_CONFIG_DEV" > ./src/config/firebaseAuthConfig.js
echo "$RCLONE_CONFIG" > ./config/rclone.conf
echo "TAG=latest" >> "$GITHUB_ENV"
- name: 🏗 Config prod files
if: github.ref == 'refs/heads/master'
run: |
echo "$FIREBASE_CONFIG" > ./src/config/firebaseAuthConfig.js
echo "$RCLONE_CONFIG" > ./config/rclone.conf
echo "TAG=stable" >> "$GITHUB_ENV"
- name: 📦 Docker login
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: 📦 Docker push image
run: |
docker build . -t "$IMAGE_NAME"
docker push "$IMAGE_NAME"
docker tag "$IMAGE_NAME" ${{ secrets.DOCKER_REPOSITORY }}:"$TAG"
docker push ${{ secrets.DOCKER_REPOSITORY }}:"$TAG"
52 changes: 0 additions & 52 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:12.2.0-alpine
FROM node:lts-alpine

# Define o diretório de trabalho como /app
WORKDIR /app
Expand Down
57 changes: 57 additions & 0 deletions __test__/services/UserService.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const UserRepository = require('../../src/repository/UserRepository');
const UserService = require('../../src/services/UserService');

const service = new UserService();

jest.mock('../../src/repository/UserRepository', () => {
return jest.fn().mockImplementation(() => ({
getById: jest.fn().mockImplementation(id => {
if(id === 1234) return { id: 1234 }
return undefined
}),
getUserByEmail: jest.fn().mockImplementation(email => {
if(email === '[email protected]') return { id: 1234 }
return undefined
}),
}));
});

describe('#UserService', () => {
describe('#getUser', () => {
it('succes case with getUserByEmail', async () => {
const result = await service.getUser({ email: '[email protected]' });

expect(result).toEqual({ id: 1234 });
})

it('succes case with getById', async () => {
const result = await service.getUser({ id: 1234, email: undefined });

expect(result).toEqual({ id: 1234 });
});

it('throw error if id or email is undefined', () => {
const callGetUser = async () => {
await service.getUser({ id: undefined, email: undefined });
};

expect(callGetUser).rejects.toThrow(new Error('Nenhum identificador encontrado'));
});

it('throw error if user is undefinied by getById', () => {
const callGetUser = async () => {
await service.getUser({ id: 2 });
}

expect(callGetUser).rejects.toThrow(new Error('Usuário não encontrado'));
});

it('throw error if user is undefinied by getByUserEmail', () => {
const callGetUser = async () => {
await service.getUser({ email: '[email protected]' });
}

expect(callGetUser).rejects.toThrow(new Error('Usuário não encontrado'));
});
});
});
16 changes: 0 additions & 16 deletions docker-compose.prod.yml

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ setRoutes(app);

app.use(Sentry.Handlers.errorHandler());

server.listen(8000);
server.listen(process.env.PORT || 8000);
Loading

0 comments on commit ca7cf87

Please sign in to comment.