Skip to content

Commit

Permalink
feat: include integration and unit folders to segregate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maikvortx committed Jan 2, 2022
1 parent de3ce60 commit 22c5260
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 84 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "Domain entities javascript library.",
"main": "./src/herbs2knex.js",
"scripts": {
"test": "mocha --timeout 999999 --colors --recursive ./test",
"testdb-pg": "mocha --timeout 999999 --colors --exit --recursive ./testdb/pg",
"testdb-mssql": "mocha --timeout 999999 --colors --exit --recursive ./testdb/mssql",
"testdb-mysql": "mocha --timeout 999999 --colors --exit --recursive ./testdb/mysql",
"test": "mocha --timeout 999999 --colors --recursive ./test/unit",
"test:integration:pg": "mocha --timeout 999999 --colors --exit --recursive ./test/integration/pg",
"test:integration:mssql": "mocha --timeout 999999 --colors --exit --recursive ./test/integration/mssql",
"test:integration:mysql": "mocha --timeout 999999 --colors --exit --recursive ./test/integration/mysql",
"coverage-report": "nyc --reporter=html --reporter=text mocha --recursive ./test --timeout 10000",
"coverage": "nyc --reporter=text mocha --recursive ./test --timeout 10000",
"semantic-release": "semantic-release",
Expand Down Expand Up @@ -50,9 +50,9 @@
"@semantic-release/github": "^7.2.3",
"@semantic-release/npm": "^7.1.3",
"@semantic-release/release-notes-generator": "^9.0.3",
"bluebird": "^3.7.2",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^10.0.0",
"bluebird": "^3.7.2",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
Expand All @@ -61,14 +61,15 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^4.1.0",
"lodash": "^4.17.21",
"mocha": "^9.0.1",
"mssql": "^7.2.1",
"mysql2": "^2.3.2",
"nyc": "^15.1.0",
"pg": "^8.7.1",
"prettier": "^2.3.1",
"semantic-release": "^17.4.4",
"pg": "^8.7.1",
"tedious": "^13.1.0",
"mssql": "^7.2.1",
"mysql2": "^2.3.2"
"tedious": "^13.1.0"
},
"peerDependencies": {
"pg": "^8.7.1",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mssql/insert.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/delete.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/find.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/findByID.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/first.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/insert.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pg/update.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const db = require('./db')
const connection = require('../connection')
const assert = require('assert')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/convention.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Convetion = require('../src/convention')
const Convetion = require('../../src/convention')
const assert = require('assert')

describe('Convetion', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/dataMapper.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const DataMapper = require('../src/dataMapper')
const DataMapper = require('../../src/dataMapper')
const { entity, field } = require('@herbsjs/gotu')
const assert = require('assert')

Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/delete.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require("@herbsjs/gotu")
const Repository = require("../../src/repository")
const Repository = require("../../../src/repository")
const assert = require("assert")

describe("Delete an Entity", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/find.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const assert = require('assert')

describe('Query Find', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/findAll.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const assert = require('assert')

describe('Query Find All', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/findByID.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const assert = require('assert')

describe('Query Find by ID', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/first.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../src/repository')
const Repository = require('../../../src/repository')
const assert = require('assert')

describe('Query First', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queries/insert.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require("@herbsjs/gotu")
const Repository = require("../../src/repository")
const Repository = require("../../../src/repository")
const assert = require("assert")

describe("Insert an Entity", () => {
Expand Down
131 changes: 72 additions & 59 deletions test/unit/queries/update.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { entity, field } = require("@herbsjs/gotu")
const Repository = require("../../src/repository")
const assert = require("assert")
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../../../src/repository')
const assert = require('assert')

describe("Update an Entity", () => {
describe('Update an Entity', () => {
const givenAnEntity = () => {
const ParentEntity = entity('A Parent Entity', {})

Expand All @@ -11,74 +11,70 @@ describe("Update an Entity", () => {
stringTest: field(String),
booleanTest: field(Boolean),
entityTest: field(ParentEntity),
entitiesTest: field([ParentEntity]),
entitiesTest: field([ParentEntity])
})
}

const givenAnRepositoryClass = (options) => {
const givenAnRepositoryClass = options => {
return class ItemRepositoryBase extends Repository {
constructor(options) {
constructor (options) {
super(options)
}
}
}

const knexMySQL = (ret, spy = {}) => (
() => ({
client: { "driverName": "mysql"},
where: (w, v) => {
spy.where = w
spy.value = v
return {
returning: (f) => {
spy.fields = f
return {
update: (p) => {
spy.payload = p
return 1
}
const knexMySQL = (ret, spy = {}) => () => ({
client: { driverName: 'mysql' },
where: (w, v) => {
spy.where = w
spy.value = v
return {
returning: f => {
spy.fields = f
return {
update: p => {
spy.payload = p
return 1
}
}
}
}
})
)

const knex = (ret, spy = {}) => (
() => ({
where: (w, v) => {
spy.where = w
spy.value = v
return {
returning: (f) => {
spy.fields = f
return {
update: (p) => {
spy.payload = p
return ret
}
}
})

const knex = (ret, spy = {}) => () => ({
where: (w, v) => {
spy.where = w
spy.value = v
return {
returning: f => {
spy.fields = f
return {
update: p => {
spy.payload = p
return ret
}
}
}
}
})
)
}
})

it("should update an entity", async () => {
it('should update an entity', async () => {
//given
let spy = {}
const retFromDeb = [{ id: 3 }]
const anEntity = givenAnEntity()
const ItemRepository = givenAnRepositoryClass()
const itemRepo = new ItemRepository({
entity: anEntity,
table: "aTable",
ids: ["id"],
table: 'aTable',
ids: ['id'],
knex: knex(retFromDeb, spy)
})

anEntity.id = 1
anEntity.stringTest = "test"
anEntity.stringTest = 'test'
anEntity.booleanTest = true

//when
Expand All @@ -89,26 +85,28 @@ describe("Update an Entity", () => {
assert.deepStrictEqual(spy.where, 'id')
assert.deepStrictEqual(spy.value, 1)
assert.deepStrictEqual(spy.fields, ['id', 'string_test', 'boolean_test'])
assert.deepStrictEqual(spy.payload, { id: 1, string_test: 'test', boolean_test: true })
assert.deepStrictEqual(spy.payload, {
id: 1,
string_test: 'test',
boolean_test: true
})
})



it("should update an entity when driver is mysql", async () => {
it('should update an entity when driver is mysql', async () => {
//given
let spy = {}
const retFromDeb = [{ id: 3 }]
const anEntity = givenAnEntity()
const ItemRepository = givenAnRepositoryClass()
const itemRepo = new ItemRepository({
entity: anEntity,
table: "aTable",
ids: ["id"],
table: 'aTable',
ids: ['id'],
knex: knexMySQL(retFromDeb, spy)
})

anEntity.id = 1
anEntity.stringTest = "test"
anEntity.stringTest = 'test'
anEntity.booleanTest = true

//when
Expand All @@ -119,25 +117,31 @@ describe("Update an Entity", () => {
assert.deepStrictEqual(spy.where, 'id')
assert.deepStrictEqual(spy.value, 1)
assert.deepStrictEqual(spy.fields, ['id', 'string_test', 'boolean_test'])
assert.deepStrictEqual(spy.payload, { id: 1, string_test: 'test', boolean_test: true })
assert.deepStrictEqual(spy.payload, {
id: 1,
string_test: 'test',
boolean_test: true
})
})

it("should update an entity with foreign key", async () => {
it('should update an entity with foreign key', async () => {
//given
let spy = {}
const retFromDeb = [{ id: 1, string_test: 'x', boolean_test: false, fk_field: 41 }]
const retFromDeb = [
{ id: 1, string_test: 'x', boolean_test: false, fk_field: 41 }
]
const anEntity = givenAnEntity()
const ItemRepository = givenAnRepositoryClass()
const itemRepo = new ItemRepository({
entity: anEntity,
table: "aTable",
ids: ["id"],
table: 'aTable',
ids: ['id'],
foreignKeys: [{ fkField: String }],
knex: knex(retFromDeb, spy)
})

anEntity.id = 1
anEntity.stringTest = "test"
anEntity.stringTest = 'test'
anEntity.booleanTest = true
anEntity.fkField = 42

Expand All @@ -148,8 +152,17 @@ describe("Update an Entity", () => {
assert.deepStrictEqual(ret.id, 1)
assert.deepStrictEqual(spy.where, 'id')
assert.deepStrictEqual(spy.value, 1)
assert.deepStrictEqual(spy.fields, ['id', 'string_test', 'boolean_test', 'fk_field'])
assert.deepStrictEqual(spy.payload, { id: 1, string_test: 'test', boolean_test: true, fk_field: 42 })
assert.deepStrictEqual(spy.fields, [
'id',
'string_test',
'boolean_test',
'fk_field'
])
assert.deepStrictEqual(spy.payload, {
id: 1,
string_test: 'test',
boolean_test: true,
fk_field: 42
})
})

})
2 changes: 1 addition & 1 deletion test/unit/repository.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { entity, field } = require('@herbsjs/gotu')
const Repository = require('../src/repository')
const Repository = require('../../src/repository')
const assert = require('assert')

describe('Repository', () => {
Expand Down

0 comments on commit 22c5260

Please sign in to comment.