Skip to content

Commit

Permalink
Merge pull request #21 from joshuaalpuerto/wip/add-unit-test-app-layer
Browse files Browse the repository at this point in the history
add unit test app layer
  • Loading branch information
joshuaalpuerto authored May 22, 2018
2 parents 143a319 + cc88578 commit 22767a4
Show file tree
Hide file tree
Showing 24 changed files with 654 additions and 80 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"npx": "10.2.0",
"pre-commit": "1.2.2",
"semantic-release": "15.4.1",
"sinon": "5.0.7",
"sinon-chai": "3.0.0",
"supertest": "3.0.0",
"travis-deploy-once": "5.0.0"
},
Expand All @@ -85,7 +87,8 @@
"expect",
"describe",
"it",
"config"
"config",
"beforeEach"
]
},
"repository": {
Expand Down
17 changes: 8 additions & 9 deletions src/app/company/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
module.exports = ({ companyRepository }) => {
// code for getting all the items
const remove = ({ id }) => {
return new Promise(async (resolve, reject) => {
try {
const companyEntity = await companyRepository.update({
return Promise
.resolve()
.then(() =>
companyRepository.update({
isDeleted: 1
}, {
where: { id }
})

resolve(companyEntity)
} catch (error) {
reject(error)
}
})
)
.catch((error) => {
throw new Error(error)
})
}

return {
Expand Down
17 changes: 8 additions & 9 deletions src/app/company/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ const { Company } = require('src/domain/company')
module.exports = ({ companyRepository }) => {
// code for getting all the items
const create = ({ body }) => {
return new Promise(async (resolve, reject) => {
try {
return Promise
.resolve()
.then(() => {
const company = Company(body)
const companyEntity = await companyRepository.create(company)

resolve(companyEntity)
} catch (error) {
reject(error)
}
})
return companyRepository.create(company)
})
.catch((error) => {
throw new Error(error)
})
}

return {
Expand Down
17 changes: 8 additions & 9 deletions src/app/user/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
module.exports = ({ userRepository }) => {
// code for getting all the items
const remove = ({ id }) => {
return new Promise(async (resolve, reject) => {
try {
const userEntity = await userRepository.update({
return Promise
.resolve()
.then(() =>
userRepository.update({
isDeleted: 1
}, {
where: { id }
})

resolve(userEntity)
} catch (error) {
reject(error)
}
})
)
.catch((error) => {
throw new Error(error)
})
}

return {
Expand Down
17 changes: 8 additions & 9 deletions src/app/user/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ const { User } = require('src/domain/user')
module.exports = ({ userRepository }) => {
// code for getting all the items
const create = ({ body }) => {
return new Promise(async (resolve, reject) => {
try {
return Promise
.resolve()
.then(() => {
const password = body.password || 'test'
const entity = Object.assign({}, body, {
password
})
const user = User(entity)
const userEntity = await userRepository.create(user)

resolve(userEntity)
} catch (error) {
reject(error)
}
})
return userRepository.create(user)
})
.catch((error) => {
throw new Error(error)
})
}

return {
Expand Down
16 changes: 11 additions & 5 deletions test/api/companies/delete_companies.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')
const companyRepository = require('src/infra/repositories/company')

describe('Routes: DELETE Companies', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const CompanyModel = repository('companies')
const CompanyUseCase = CompanyModel(companyRepository)
const UserUseCase = compose(
repository(userRepository),
models
)('users')

const CompanyUseCase = compose(
repository(companyRepository),
models
)('companies')

const signIn = app.resolve('jwt').signin()
let token
Expand Down
16 changes: 11 additions & 5 deletions test/api/companies/get_companies.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')
const companyRepository = require('src/infra/repositories/company')

describe('Routes: GET Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const CompanyModel = repository('companies')
const CompanyUseCase = CompanyModel(companyRepository)
const UserUseCase = compose(
repository(userRepository),
models
)('users')

const CompanyUseCase = compose(
repository(companyRepository),
models
)('companies')

const signIn = app.resolve('jwt').signin()
let token
Expand Down
16 changes: 11 additions & 5 deletions test/api/companies/post_companies.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')
const companyRepository = require('src/infra/repositories/company')

describe('Routes: POST Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const CompanyModel = repository('companies')
const CompanyUseCase = CompanyModel(companyRepository)
const UserUseCase = compose(
repository(userRepository),
models
)('users')

const CompanyUseCase = compose(
repository(companyRepository),
models
)('companies')

const signIn = app.resolve('jwt').signin()
let token
Expand Down
16 changes: 11 additions & 5 deletions test/api/companies/put_companies.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')
const companyRepository = require('src/infra/repositories/company')

describe('Routes: PUT Companies', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const CompanyModel = repository('companies')
const CompanyUseCase = CompanyModel(companyRepository)
const UserUseCase = compose(
repository(userRepository),
models
)('users')

const CompanyUseCase = compose(
repository(companyRepository),
models
)('companies')

const signIn = app.resolve('jwt').signin()
let token
Expand Down
10 changes: 7 additions & 3 deletions test/api/token.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')

describe('Routes: Login', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const UserUseCase = compose(
repository(userRepository),
models
)('users')

beforeEach((done) => {
// we need to add user before we can request our token
Expand Down
11 changes: 8 additions & 3 deletions test/api/users/delete_users.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')

describe('Routes: DELETE Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const UserUseCase = compose(
repository(userRepository),
models
)('users')

const signIn = app.resolve('jwt').signin()
let token
let userId
Expand Down
11 changes: 8 additions & 3 deletions test/api/users/get_users.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')

describe('Routes: GET Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const UserUseCase = compose(
repository(userRepository),
models
)('users')

const signIn = app.resolve('jwt').signin()
let token

Expand Down
11 changes: 8 additions & 3 deletions test/api/users/post_users.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')

describe('Routes: POST Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const UserUseCase = compose(
repository(userRepository),
models
)('users')

const signIn = app.resolve('jwt').signin()
let token

Expand Down
11 changes: 8 additions & 3 deletions test/api/users/put_users.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-env mocha */
const { repository } = require('test/factory')
const { compose } = require('ramda')
const { models, repository } = require('test/factory')
const userRepository = require('src/infra/repositories/user')

describe('Routes: PUT Users', () => {
const BASE_URI = `/api/${config.version}`
const UserModel = repository('users')
const UserUseCase = UserModel(userRepository)

const UserUseCase = compose(
repository(userRepository),
models
)('users')

const signIn = app.resolve('jwt').signin()
let token
let userId
Expand Down
12 changes: 7 additions & 5 deletions test/factory.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* We need to find a way to user the repositories for our test that it we will have minimum impact once we change our ORM or our DATABASE
*/
const { compose } = require('ramda')
const { curry } = require('ramda')

// we will call each repo on thier test cases here we will just compose the items.

const repository = (model) => {
const entity = app.resolve('database').models[model]
return (repo) => compose(repo)(entity)
}
const models = (name) => app.resolve('database').models[name]

const repository = curry((repo, model) => {
return repo(model)
})

module.exports = {
models,
repository
}
Loading

0 comments on commit 22767a4

Please sign in to comment.