Skip to content

Commit

Permalink
Merge pull request #13 from matheuspiment/development
Browse files Browse the repository at this point in the history
first release
  • Loading branch information
matheuspiment authored Oct 9, 2019
2 parents 9384365 + f9d8258 commit 1baeac7
Show file tree
Hide file tree
Showing 38 changed files with 11,298 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["@babel/env", "@babel/typescript"],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/transform-runtime"
]
}
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PORT=
MONGO_URI=
JWT_SECRET=
GOOGLE_MAPS_API_KEY=
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
env: {
es6: true,
node: true,
jest: true
},
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'standard'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {}
}
140 changes: 140 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

# Created by https://www.gitignore.io/api/node,macos,visualstudiocode
# Edit at https://www.gitignore.io/?templates=node,macos,visualstudiocode

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# react / gatsby
public/

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

# End of https://www.gitignore.io/api/node,macos,visualstudiocode

mongo/
dist/
11 changes: 11 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/github", {
"assets": [
{"path": "dist.zip", "label": "NodeJS distribution"},
]
}],
],
}
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: node_js
services: mongodb
cache:
directories:
- ~/.yarn
notifications:
email: false
node_js:
- "12"
before_script:
- sleep 15
script:
- yarn lint
- yarn test
- yarn build
after_success:
- yarn zip-dist
- yarn travis-deploy-once "yarn semantic-release"
- yarn report-coverage
branches:
only:
- master
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# alumnet-developer
The backend test for a developer position at Alumnet
# Postfy

An awesome post API.

[![travis build](https://img.shields.io/travis/matheuspiment/postfy.svg)](https://travis-ci.org/matheuspiment/postfy)
[![codecov coverage](https://img.shields.io/codecov/c/github/matheuspiment/postfy.svg)](https://codecov.io/gh/matheuspiment/postfy)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

- [Running the app](#running-the-app)

## Running the app

1. Download this repository.
2. In a terminal, enter the repository folder.
3. Follow the steps according to the option you want:
- [Development server](#development-server).
- [Production server](#production-server).

### Development server

#### With node

1. Create a `.env` file with the content of the `.env.example`.
2. Run the command `yarn install` to install the dependencies.
3. A mongo database is required. You can run the `docker-compose up -d` command to setup a mongo database. Feel free to edit the `docker-compose.yml` file.
4. Run the command `yarn dev`.
5. Make requests to `http://localhost:<port>`, where `<port>` is the port set in the `.env` file.

### Production server

#### With node

1. Create a `.env` file with the content of the `.env.example`.
2. Run the command `yarn install` to install the dependencies.
3. Run the command `yarn build`.
4. A mongo database is required. You can run the `docker-compose up -d` command to setup a mongo database. Feel free to edit the `docker-compose.yml` file.
5. Run the command `yarn start`.
6. Make requests to `http://localhost:<port>`, where `<port>` is the port set in the `.env` file.

Done! 😎
17 changes: 17 additions & 0 deletions __tests__/factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import faker from 'faker'
import { factory } from 'factory-girl'

import User from '../src/schemas/User'
import Post from '../src/schemas/Post'

factory.define('User', User, {
name: faker.name.findName(),
email: faker.internet.email(),
password: faker.internet.password()
})

factory.define('Post', Post, {
text: faker.lorem.text()
})

export default factory
30 changes: 30 additions & 0 deletions __tests__/helpers/MongooseConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '../../src/bootstrap'

import mongoose from 'mongoose'

class MongooseConnection {
async connect (testSuitName: string): Promise<void> {
mongoose.connect(`${process.env.MONGO_URI}-${testSuitName}`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
}, async (error) => {
if (error) {
throw error
}
})
}

async disconnect (): Promise<void> {
await mongoose.connection.close()
}

async truncate (): Promise<void> {
const collections = Object.keys(mongoose.connection.collections)
for (const collection of collections) {
await mongoose.connection.collections[collection].deleteMany({})
}
}
}

export default new MongooseConnection()
17 changes: 17 additions & 0 deletions __tests__/helpers/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Response } from 'express'

function createResponseObject (): Response {
return {
status: function (code) {
this.statusCode = code
return this
},
json: function () {
return {
status: this.statusCode
}
}
} as Response
}

export default createResponseObject
Loading

0 comments on commit 1baeac7

Please sign in to comment.