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

Exam Scheduling API - NodeJS Backend Challenge #8

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
67b3e5e
added .gitignore
Sep 19, 2019
613f5fd
added package.json
Sep 19, 2019
dcd6843
initial ts configuration
Sep 19, 2019
a3494f6
first route to test initial config
Sep 19, 2019
ed59bae
nodemon setup
Sep 19, 2019
4a8652f
add initial config swagger openapi specification
Sep 19, 2019
b2d7951
initial docker and docker compose config
Sep 19, 2019
924173b
refactor: created app class to server
Sep 19, 2019
bd6b259
added routes file for separation of responsablitities
Sep 20, 2019
5a09e41
added route test swagger
Sep 20, 2019
09f1636
initial config jest for test
Sep 20, 2019
f18c743
added call for exams api and its unit test
Sep 20, 2019
6b0e5dc
refactor exam service
Sep 20, 2019
6bf708a
renamed service request external api
Sep 20, 2019
f371eb5
replace of axios with request
Sep 21, 2019
1326742
exam listing route completed
Sep 21, 2019
06ce7a5
add simulated database in memory
Sep 21, 2019
f2c825c
unit test database connection
Sep 21, 2019
58d7667
division unit test files
Sep 21, 2019
cdae307
adjustoment unit test database
Sep 21, 2019
42b8e74
added service to save customer and unit test
Sep 21, 2019
e74281a
added customer save route
Sep 21, 2019
696f239
handling for cpf already exists unit test
Sep 21, 2019
3439ec1
adjustment response db and save route
Sep 21, 2019
d2bc07a
added service and unit test update customer
Sep 21, 2019
5f1fee5
added route update customer
Sep 21, 2019
318bf9f
added remove route customer
Sep 21, 2019
ed11fa2
added service find customer by cpf and unit test
Sep 21, 2019
789c024
added customer find route
Sep 21, 2019
f8b969e
added list route
Sep 21, 2019
196be45
refactor customer unit test
Sep 21, 2019
cb40a6c
rename dir inut test customer
Sep 21, 2019
5d1261f
added utils for unit test file
Sep 21, 2019
18e65bb
refactor exam list
Sep 22, 2019
ffd2500
fixed unity test external api
Sep 22, 2019
2667e28
added unit test schedule exam
Sep 22, 2019
611986a
added unit test when same time
Sep 22, 2019
3c0dabb
added schedule route
Sep 22, 2019
d1b2f1f
adjustment unit test
Sep 22, 2019
2c2f767
adjustment route schedule
Sep 22, 2019
95ebfab
added service for get exam bu cpf and sum price and unit test
Sep 22, 2019
83d34ba
added id schedule
Sep 22, 2019
580db5d
added test unit and service for edit schedule
Sep 22, 2019
831ba87
added route update schedule
Sep 22, 2019
76ea798
added service delete schedule and unit test
Sep 22, 2019
48291c1
added route remove schedule
Sep 22, 2019
6a471fc
added interface and other types
Sep 22, 2019
e1370e3
fixed route scedule by cpf
Sep 22, 2019
1021db7
refactor with all routes
Sep 22, 2019
30c76cc
added package-lock
Sep 22, 2019
e499fa1
swagger increments inital
Sep 22, 2019
d5145a4
config env files
Sep 22, 2019
1662ced
adjustment to work default max 2 customer by time in same exam
Sep 22, 2019
66020a3
add travis and adjustment
Sep 22, 2019
4a35d9d
swagger complete
Sep 22, 2019
158279c
added doc with request postman
Sep 22, 2019
ddfb54d
added middlewares layer to complete the architecture
Sep 22, 2019
5067b5b
updated config docker-compose
Sep 22, 2019
ca277f8
updated unit test sintaxe
Sep 22, 2019
c815dde
updated singleton DB
Sep 22, 2019
00fb9af
updated declaration variables
Sep 22, 2019
76ee039
added README.md
Sep 23, 2019
419b745
added selo travis
Sep 23, 2019
ac7cdef
updated format README.md
Sep 23, 2019
5613b1d
Update README.md
LUIZFH Oct 25, 2019
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
Prev Previous commit
Next Next commit
refactor customer unit test
Luiz Filho committed Sep 21, 2019
commit 196be4598ac72aefc046eaf10fc4a9d5481f1c19
119 changes: 52 additions & 67 deletions tests/unit/exam/customer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,107 @@
import DB from '../../../data/db'
import CustomerService from '../../../src/services/customer'
import { cursorTo } from 'readline'
import Faker from 'faker'
import { copyFileSync } from 'fs'
import { getDefaultWatermarks } from 'istanbul-lib-report'

const getCpf = () => Faker.random.number({ 'min': 100000000,'max': 999999999 }) + '-' + Faker.random.number({ 'min': 10, 'max': 99 })

test('should save a customer to the database by service', () => {

const customer = {
name: 'Luiz Filho',
cpf: '464444466-44'
const fullName = () => Faker.name.firstName + ' ' + Faker.name.lastName

const getDate = () => Faker.date.between('1920-01-01', '2019-09-01')

let customer = {
cpf: '',
name: '',
dateOfBirth: new Date()
}
let service = new CustomerService()

beforeEach(() => {
DB.resetForUnitTest()
customer = {
name: fullName(),
cpf: getCpf(),
dateOfBirth: getDate()
}
})

const service = new CustomerService()
test('should save a customer to the database by service', () => {
const customerStored = service.save(customer)
expect(customer).toEqual(customerStored.data)
})

test('should not save a customer', () => {

const customer = {
name: 'Luiz Carlos',
cpf: '888555333-44'
}

const service = new CustomerService()
service.save(customer)

const otherService = new CustomerService()
const responseOtherService = otherService.save({ ...customer, name: 'João Silva' })

const responseOtherService = otherService.save({ ...customer, name: fullName() })
expect(responseOtherService.success).toEqual(false)
})

test('should update a customer to the database by service', () => {

let customer = {
name: 'Nathalia Souza',
cpf: '961965000-44'
}

const service = new CustomerService()
service.save(customer)
customer = { ...customer, name: 'Geisiane Pereira'}
customer = { ...customer, name: Faker.name.firstName + ' ' + fullName() }
const customerUpdated = service.update(customer)

expect(customerUpdated.data).toEqual(customer)
})

test('should not update a customer', () => {

let customer = {
name: 'Hamilton Vicente',
cpf: '464444466-44'
}

const service = new CustomerService()
service.save(customer)
customer = { cpf: '333161615-46', name: 'João Rodrigues'}
customer = {
cpf: getCpf(),
name: fullName(),
dateOfBirth: getDate()
}
const customerUpdated = service.update(customer)

expect(customerUpdated.success).toEqual(false)
})

test('should remove a customer to the database by service', () => {

let customer = {
name: 'Fernanda Pereira',
cpf: '464999966-44'
}

const service = new CustomerService()
service.save(customer)
const customerRemoved = service.remove(customer.cpf)

expect(customerRemoved.success).toEqual(true)
expect(customerRemoved.data).toEqual(customer)
})

test('should not delete a customer', () => {

let customer = {
name: 'Luiz Filho',
cpf: '464444466-44'
}

const service = new CustomerService()
service.save(customer)
customer = { ...customer, cpf: '111222333-44' }
customer = {
...customer,
cpf: getCpf()
}
const customerRemoved = service.remove(customer.cpf)

expect(customerRemoved.success).toEqual(false)
})

test('should be returned a customer by cpf', () => {

const customer = {
name: 'Giovanni Santos',
cpf: '101010101-10'
}

const service = new CustomerService()
service.save(customer)
const customerSeached = service.find(customer.cpf)

expect(customerSeached.success).toEqual(true)
expect(customerSeached.data).toEqual(customer)
})

test('should not return a customer by cpf', () => {

const customer = {
name: 'Giovanni Santos',
cpf: '101010101-10'
}

const service = new CustomerService()
service.save(customer)
customer.cpf = '121121121-12'
customer.cpf = getCpf()
const customerSeached = service.find(customer.cpf)

expect(customerSeached.success).toEqual(false)
expect(customerSeached.data).toEqual(null)
})

test('should returned all customers', () => {
const service = new CustomerService()
for(let index = 0; index < 10; index++) {
let customer = {
cpf: getCpf(),
name: fullName()
}

service.save(customer)
}

let customers = service.list()
expect(customers.data.length).toEqual(10)

})