Skip to content
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
20 changes: 20 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [
["@babel/plugin-transform-classes", {
"loose": true
}],
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}
]
]
}
43 changes: 43 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
jobs:
build:
docker:
-
image: "circleci/node:7.10"
environment:
CC_TEST_REPORTER_ID: 5262e6177c408baee184d02578537b904e960e78435782f2ae2db1b75743683c
steps:
- checkout
-
restore_cache:
keys:
- "v1-dependencies-{{ checksum \"package.json\" }}"
- v1-dependencies-
-
run:
command: "npm install\n"
name: "Install dependecies"
-
save_cache:
key: "v1-dependencies-{{ checksum \"package.json\" }}"
paths:
- node_modules
-
run:
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
name: "Setup Code Climate test-reporter"
-
run:
command: |
mkdir /tmp/test-results
./cc-test-reporter before-build
npm test
name: "Run tests"
-
run:
command: "./cc-test-reporter after-build -t lcov --exit-code $?\n"
name: "Codeclimate test coverage"
working_directory: ~/api
version: 2.0
39 changes: 39 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"extends": "airbnb-base",
"env": {
"browser": true,
"es6": true,
"jquery": true,
"node": true,
"jest": true
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, {
"commonjs": true
}],
"no-shadow": ["error", {
"allow": ["req", "res", "err"]
}],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}],
"max-len": ["error", { "code": 80 }]
}
}
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# 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

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://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/

# 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

# next.js build output
.next
/dist
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Software Developer Application Test

[![CircleCI](https://circleci.com/gh/cavdy-dev/backend-developer-test/tree/develop.svg?style=svg)](https://circleci.com/gh/cavdy-dev/backend-developer-test/tree/develop) [![Test Coverage](https://api.codeclimate.com/v1/badges/778bfb183a909711484e/test_coverage)](https://codeclimate.com/github/cavdy-dev/backend-developer-test/test_coverage)

Create a API that serves the latest scores of fixtures of matches in a “**Mock Premier League**”

## User Types
Expand Down
86 changes: 86 additions & 0 deletions __test__/adminSignIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import request from 'supertest';
import app from '../api';

describe('Admin Signin', () => {
const signinRoute = '/api/v1/auth/admin/signin';
it('Successful', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'admin@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('token');
expect(res.body).toHaveProperty('refreshToken');
expect(res.body.status).toBe(200);
expect(res.body.message).toBe('Successfully Signed In');
});

it('when no data', async () => {
const res = await request(app)
.post(signinRoute)
.send();
expect(res.statusCode).toEqual(400);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('email');
expect(res.body.data).toHaveProperty('password');
expect(res.body.status).toBe(400);
expect(res.body.message).toBe('Fields are required');
expect(res.body.data.email).toBe('Please put in a valid email');
expect(res.body.data.password)
.toBe('Password should be at least 7 characters long');
});

it('Email dont exist', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'freddy48@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(404);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('email');
expect(res.body.status).toBe(404);
expect(res.body.message).toBe('Email error');
expect(res.body.data.email).toBe('Email does not exist');
});

it('Incorrect Password', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'admin@test.com',
password: 'password22'
});
expect(res.statusCode).toEqual(400);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('password');
expect(res.body.status).toBe(400);
expect(res.body.message).toBe('Password error');
expect(res.body.data.password).toBe('Password is incorrect');
});

it('when not admin', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'freddy@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(401);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body.status).toBe(401);
expect(res.body.message).toBe('Unauthorized Account');
});
});
Loading