Skip to content

Commit

Permalink
Merge a79ab8e into adf70e4
Browse files Browse the repository at this point in the history
  • Loading branch information
yants95 committed May 2, 2021
2 parents adf70e4 + a79ab8e commit 55dceec
Show file tree
Hide file tree
Showing 19 changed files with 1,193 additions and 1,182 deletions.
2,234 changes: 1,123 additions & 1,111 deletions package-lock.json

Large diffs are not rendered by default.

63 changes: 31 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,54 @@
"test:coveralls": "npm run test:ci && coveralls < coverage/lcov.info"
},
"devDependencies": {
"@shelf/jest-mongodb": "^1.2.1",
"@types/bcrypt": "^3.0.0",
"@types/express": "^4.17.9",
"@types/express-serve-static-core": "^4.17.14",
"@types/faker": "^5.1.4",
"@shelf/jest-mongodb": "^1.2.4",
"@types/bcrypt": "^3.0.1",
"@types/express": "^4.17.11",
"@types/express-serve-static-core": "^4.17.19",
"@types/faker": "^5.5.3",
"@types/graphql": "^14.5.0",
"@types/graphql-iso-date": "^3.4.0",
"@types/jest": "^26.0.15",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.5.34",
"@types/node": "^14.14.10",
"@types/supertest": "^2.0.10",
"@types/jest": "^26.0.23",
"@types/jsonwebtoken": "^8.5.1",
"@types/mongodb": "^3.6.12",
"@types/node": "^15.0.1",
"@types/supertest": "^2.0.11",
"@types/swagger-ui-express": "^4.1.2",
"@types/validator": "^13.1.0",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"apollo-server-integration-testing": "^2.3.0",
"bson-objectid": "^1.3.1",
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"apollo-server-integration-testing": "^3.0.0",
"copyfiles": "^2.4.1",
"coveralls": "^3.1.0",
"eslint": "^7.14.0",
"eslint-config-standard-with-typescript": "^19.0.1",
"eslint": "^7.25.0",
"eslint-config-standard-with-typescript": "^20.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"faker": "^5.1.0",
"git-commit-msg-linter": "^3.0.0",
"husky": "^4.2.5",
"faker": "^5.5.3",
"git-commit-msg-linter": "^3.1.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.2",
"mockdate": "^3.0.2",
"lint-staged": "^10.5.4",
"mockdate": "^3.0.5",
"rimraf": "^3.0.2",
"supertest": "^6.0.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
"supertest": "^6.1.3",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4"
},
"dependencies": {
"apollo-server-express": "^2.19.0",
"bcrypt": "^5.0.0",
"apollo-server-express": "^2.24.0",
"bcrypt": "^5.0.1",
"express": "^4.17.1",
"graphql": "^15.4.0",
"graphql": "^15.5.0",
"graphql-iso-date": "^3.6.1",
"jsonwebtoken": "^8.5.1",
"module-alias": "^2.2.2",
"mongo-round": "^1.0.0",
"mongodb": "^3.6.3",
"nodemon": "^2.0.6",
"swagger-ui-express": "^4.1.5",
"validator": "^13.1.1"
"mongodb": "^3.6.6",
"nodemon": "^2.0.7",
"swagger-ui-express": "^4.1.6",
"validator": "^13.6.0"
},
"engines": {
"node": "12.x"
Expand Down
3 changes: 2 additions & 1 deletion src/main/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Express, Router } from 'express'
import { readdirSync } from 'fs'
import { resolve } from 'path'

export default (app: Express): void => {
const router = Router()
app.use('/api', router)
readdirSync(`${__dirname}/../routes`).map(async file => {
readdirSync(resolve(__dirname, '..', 'routes')).map(async file => {
if (!file.endsWith('.map')) {
(await import(`../routes/${file}`)).default(router)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/data/mocks/mock-cryptography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hasher, HashComparer, Encrypter, Decrypter } from '@/data/protocols'
import faker from 'faker'

export class HasherSpy implements Hasher {
digest = faker.random.uuid()
digest = faker.datatype.uuid()
plaintext: string

async hash (plaintext: string): Promise<string> {
Expand All @@ -25,7 +25,7 @@ export class HashComparerSpy implements HashComparer {
}

export class EncrypterSpy implements Encrypter {
ciphertext = faker.random.uuid()
ciphertext = faker.datatype.uuid()
plaintext: string

async encrypt (plaintext: string): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions tests/data/mocks/mock-db-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AddAccountRepositorySpy implements AddAccountRepository {
export class LoadAccountByEmailRepositorySpy implements LoadAccountByEmailRepository {
email: string
result = {
id: faker.random.uuid(),
id: faker.datatype.uuid(),
name: faker.name.findName(),
password: faker.internet.password()
}
Expand All @@ -40,7 +40,7 @@ export class LoadAccountByTokenRepositorySpy implements LoadAccountByTokenReposi
token: string
role: string
result = {
id: faker.random.uuid()
id: faker.datatype.uuid()
}

async loadByToken (token: string, role?: string): Promise<LoadAccountByTokenRepository.Result> {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/usecases/db-check-survey-by-id.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let surveyId: string

describe('DbLoadSurveyById', () => {
beforeEach(() => {
surveyId = faker.random.uuid()
surveyId = faker.datatype.uuid()
})

test('Should call CheckSurveyByIdRepository', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/usecases/db-load-account-by-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let role: string

describe('DbLoadAccountByToken Usecase', () => {
beforeEach(() => {
token = faker.random.uuid()
token = faker.datatype.uuid()
role = faker.random.word()
})

Expand Down
2 changes: 1 addition & 1 deletion tests/data/usecases/db-load-answers-by-survey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let surveyId: string

describe('DbLoadAnswersBySurvey', () => {
beforeEach(() => {
surveyId = faker.random.uuid()
surveyId = faker.datatype.uuid()
})

test('Should call LoadAnswersBySurveyRepository', async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/data/usecases/db-load-survey-result.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe('DbLoadSurveyResult UseCase', () => {
})

beforeEach(() => {
surveyId = faker.random.uuid()
accountId = faker.random.uuid()
surveyId = faker.datatype.uuid()
accountId = faker.datatype.uuid()
})

test('Should call LoadSurveyResultRepository with correct values', async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/data/usecases/db-load-surveys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ describe('DbLoadSurveys', () => {

test('Should call LoadSurveysRepository', async () => {
const { sut, loadSurveysRepositorySpy } = makeSut()
const accountId = faker.random.uuid()
const accountId = faker.datatype.uuid()
await sut.load(accountId)
expect(loadSurveysRepositorySpy.accountId).toBe(accountId)
})

test('Should return a list of Surveys on success', async () => {
const { sut, loadSurveysRepositorySpy } = makeSut()
const surveys = await sut.load(faker.random.uuid())
const surveys = await sut.load(faker.datatype.uuid())
expect(surveys).toEqual(loadSurveysRepositorySpy.result)
})

test('Should throw if LoadSurveysRepository throws', async () => {
const { sut, loadSurveysRepositorySpy } = makeSut()
jest.spyOn(loadSurveysRepositorySpy, 'loadAll').mockImplementationOnce(throwError)
const promise = sut.load(faker.random.uuid())
const promise = sut.load(faker.datatype.uuid())
await expect(promise).rejects.toThrow()
})
})
20 changes: 10 additions & 10 deletions tests/domain/mocks/mock-survey-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import { SaveSurveyResult } from '@/domain/usecases'
import faker from 'faker'

export const mockSaveSurveyResultParams = (): SaveSurveyResult.Params => ({
accountId: faker.random.uuid(),
surveyId: faker.random.uuid(),
accountId: faker.datatype.uuid(),
surveyId: faker.datatype.uuid(),
answer: faker.random.word(),
date: faker.date.recent()
})

export const mockSurveyResultModel = (): SurveyResultModel => ({
surveyId: faker.random.uuid(),
surveyId: faker.datatype.uuid(),
question: faker.random.words(),
answers: [{
answer: faker.random.word(),
count: faker.random.number({ min: 0, max: 1000 }),
percent: faker.random.number({ min: 0, max: 100 }),
isCurrentAccountAnswer: faker.random.boolean()
count: faker.datatype.number({ min: 0, max: 1000 }),
percent: faker.datatype.number({ min: 0, max: 100 }),
isCurrentAccountAnswer: faker.datatype.boolean()
}, {
answer: faker.random.word(),
image: faker.image.imageUrl(),
count: faker.random.number({ min: 0, max: 1000 }),
percent: faker.random.number({ min: 0, max: 100 }),
isCurrentAccountAnswer: faker.random.boolean()
count: faker.datatype.number({ min: 0, max: 1000 }),
percent: faker.datatype.number({ min: 0, max: 100 }),
isCurrentAccountAnswer: faker.datatype.boolean()
}],
date: faker.date.recent()
})

export const mockEmptySurveyResultModel = (): SurveyResultModel => ({
surveyId: faker.random.uuid(),
surveyId: faker.datatype.uuid(),
question: faker.random.words(),
answers: [{
answer: faker.random.word(),
Expand Down
2 changes: 1 addition & 1 deletion tests/domain/mocks/mock-survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import faker from 'faker'

export const mockSurveyModel = (): SurveyModel => {
return {
id: faker.random.uuid(),
id: faker.datatype.uuid(),
question: faker.random.words(),
answers: [{
answer: faker.random.word()
Expand Down
6 changes: 3 additions & 3 deletions tests/infra/db/mongodb/account-mongo-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('AccountMongoRepository', () => {
const res = await accountCollection.insertOne(mockAddAccountParams())
const fakeAccount = res.ops[0]
expect(fakeAccount.accessToken).toBeFalsy()
const accessToken = faker.random.uuid()
const accessToken = faker.datatype.uuid()
await sut.updateAccessToken(fakeAccount._id, accessToken)
const account = await accountCollection.findOne({ _id: fakeAccount._id })
expect(account).toBeTruthy()
Expand All @@ -86,13 +86,13 @@ describe('AccountMongoRepository', () => {
let name = faker.name.findName()
let email = faker.internet.email()
let password = faker.internet.password()
let accessToken = faker.random.uuid()
let accessToken = faker.datatype.uuid()

beforeEach(() => {
name = faker.name.findName()
email = faker.internet.email()
password = faker.internet.password()
accessToken = faker.random.uuid()
accessToken = faker.datatype.uuid()
})

test('Should return an account on loadByToken without role', async () => {
Expand Down
7 changes: 3 additions & 4 deletions tests/infra/db/mongodb/survey-mongo-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SurveyMongoRepository, MongoHelper } from '@/infra/db'
import { mockAddSurveyParams, mockAddAccountParams } from '@/tests/domain/mocks'

import { Collection } from 'mongodb'
import FakeObjectId from 'bson-objectid'

let surveyCollection: Collection
let surveyResultCollection: Collection
Expand Down Expand Up @@ -85,7 +84,7 @@ describe('SurveyMongoRepository', () => {

test('Should return null if survey does not exists', async () => {
const sut = makeSut()
const survey = await sut.loadById(FakeObjectId.generate())
const survey = await sut.loadById('any-valid-id')
expect(survey).toBeFalsy()
})
})
Expand All @@ -101,7 +100,7 @@ describe('SurveyMongoRepository', () => {

test('Should return empty array if survey does not exists', async () => {
const sut = makeSut()
const answers = await sut.loadAnswers(FakeObjectId.generate())
const answers = await sut.loadAnswers('any-valid-id')
expect(answers).toEqual([])
})
})
Expand All @@ -116,7 +115,7 @@ describe('SurveyMongoRepository', () => {

test('Should return false if survey exists', async () => {
const sut = makeSut()
const exists = await sut.checkById(FakeObjectId.generate())
const exists = await sut.checkById('any-valid-id')
expect(exists).toBe(false)
})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/main/decorators/log-controller-decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LogErrorRepositorySpy } from '@/tests/data/mocks'
import faker from 'faker'

class ControllerSpy implements Controller {
httpResponse = ok(faker.random.uuid())
httpResponse = ok(faker.datatype.uuid())
request: any

async handle (request: any): Promise<HttpResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import MockDate from 'mockdate'
import faker from 'faker'

const mockRequest = (): LoadSurveyResultController.Request => ({
accountId: faker.random.uuid(),
surveyId: faker.random.uuid()
accountId: faker.datatype.uuid(),
surveyId: faker.datatype.uuid()
})

type SutTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { throwError } from '@/tests/domain/mocks'
import MockDate from 'mockdate'
import faker from 'faker'

const mockRequest = (): LoadSurveysController.Request => ({ accountId: faker.random.uuid() })
const mockRequest = (): LoadSurveysController.Request => ({ accountId: faker.datatype.uuid() })

type SutTypes = {
sut: LoadSurveysController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import MockDate from 'mockdate'
import faker from 'faker'

const mockRequest = (answer: string = null): SaveSurveyResultController.Request => ({
surveyId: faker.random.uuid(),
surveyId: faker.datatype.uuid(),
answer,
accountId: faker.random.uuid()
accountId: faker.datatype.uuid()
})

type SutTypes = {
Expand Down
4 changes: 2 additions & 2 deletions tests/presentation/mocks/mock-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AddAccountSpy implements AddAccount {
export class AuthenticationSpy implements Authentication {
params: Authentication.Params
result = {
accessToken: faker.random.uuid(),
accessToken: faker.datatype.uuid(),
name: faker.name.findName()
}

Expand All @@ -29,7 +29,7 @@ export class LoadAccountByTokenSpy implements LoadAccountByToken {
accessToken: string
role: string
result = {
id: faker.random.uuid()
id: faker.datatype.uuid()
}

async load (accessToken: string, role?: string): Promise<LoadAccountByToken.Result> {
Expand Down

0 comments on commit 55dceec

Please sign in to comment.