Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "buchu", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Uniform, auditable and secure use case javascript library. Influenced by Clean Architecture and Trailblazer", | ||
@@ -13,6 +13,6 @@ "main": "./src/buchu.js", | ||
"type": "git", | ||
"url": "https://github.com/dalssoft/buchu.git" | ||
"url": "https://github.com/herbsjs/buchu.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dalssoft/buchu/issues/" | ||
"url": "https://github.com/herbsjs/buchu/issues/" | ||
}, | ||
@@ -28,2 +28,3 @@ "engines": { | ||
"author": "David Lojudice Sb", | ||
"homepage": "https://github.com/herbsjs/buchu#readme", | ||
"license": "MIT", | ||
@@ -30,0 +31,0 @@ "dependencies": { |
class Ok { | ||
constructor(value) { | ||
this.value = value; | ||
this.value = value | ||
if (value instanceof Ok) | ||
this.value = value.value | ||
} | ||
@@ -23,3 +25,5 @@ | ||
constructor(error) { | ||
this._error = error; | ||
this._error = error | ||
if (error instanceof Err) | ||
this._error = error._error | ||
} | ||
@@ -26,0 +30,0 @@ |
@@ -59,3 +59,7 @@ const { Ok, Err } = require('./results') | ||
} | ||
return Ok({ ...this.context.ret }) | ||
const ret = this.context.ret | ||
if (ret.__proto__ === Ok().__proto__) | ||
return Ok(ret) | ||
else | ||
return Ok({ ...ret }) | ||
} | ||
@@ -62,0 +66,0 @@ |
@@ -167,2 +167,88 @@ const { usecase } = require('../../src/usecase') | ||
describe('the simplest use case with context returning multiple Oks or Errs', () => { | ||
context('returning Ok', () => { | ||
const givenAnUseCaseWithOkReturn = () => { | ||
const uc = usecase('A use case', { | ||
'Change return': step({ | ||
'step r1': step((ctx) => { ctx.ret = Ok('uc ret'); return Ok('step1 ret') }), | ||
}) | ||
}) | ||
return uc | ||
} | ||
it('should run', async () => { | ||
//given | ||
const uc = givenAnUseCaseWithOkReturn() | ||
//when | ||
const ret = await uc.run() | ||
//then | ||
assert.ok(ret.isOk) | ||
assert.deepEqual(ret.value, 'uc ret') | ||
}) | ||
it('should audit', async () => { | ||
//given | ||
const uc = givenAnUseCaseWithOkReturn() | ||
//when | ||
await uc.run() | ||
//then | ||
assert.deepEqual(uc.auditTrail, { | ||
type: 'use case', | ||
description: 'A use case', | ||
transactionId: uc._mainStep._auditTrail.transactionId, | ||
return: Ok('uc ret'), steps: [ | ||
{ | ||
type: 'step', description: 'Change return', return: Ok('uc ret'), steps: [ | ||
{ type: 'step', description: 'step r1', return: Ok('step1 ret') }, | ||
] | ||
}] | ||
}) | ||
}) | ||
}) | ||
context('returning Err', () => { | ||
const givenAnUseCaseWithErrReturn = () => { | ||
const uc = usecase('A use case', { | ||
'Change return': step({ | ||
'step r1': step((ctx) => { ctx.ret = Err('uc ret'); return Err('step1 ret') }), | ||
}) | ||
}) | ||
return uc | ||
} | ||
it('should run', async () => { | ||
//given | ||
const uc = givenAnUseCaseWithErrReturn() | ||
//when | ||
const ret = await uc.run() | ||
//then | ||
assert.ok(ret.isErr) | ||
assert.deepEqual(ret.err, 'step1 ret') | ||
}) | ||
it('should audit', async () => { | ||
//given | ||
const uc = givenAnUseCaseWithErrReturn() | ||
//when | ||
await uc.run() | ||
//then | ||
assert.deepEqual(uc.auditTrail, { | ||
type: 'use case', | ||
description: 'A use case', | ||
transactionId: uc._mainStep._auditTrail.transactionId, | ||
return: Err('step1 ret'), steps: [ | ||
{ | ||
type: 'step', description: 'Change return', return: Err('step1 ret'), steps: [ | ||
{ type: 'step', description: 'step r1', return: Err('step1 ret') }, | ||
] | ||
}] | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('the simplest use case with request', () => { | ||
@@ -221,3 +307,3 @@ | ||
}, | ||
type: "use case", | ||
type: "use case", | ||
description: "A use case", | ||
@@ -224,0 +310,0 @@ steps: [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
147846
2260
0