-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuchu.js
88 lines (71 loc) · 2.33 KB
/
buchu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const { ok, deepEqual } = require('assert')
const {usecase, step, Ok, Err} = require('../src/commonjs/herbs.cjs')
describe('A use case', () => {
describe('the simplest use case', () => {
const givenTheSimplestUseCase = () => {
const uc = usecase('A use case', {
'A step': step(() => { return Ok() }),
'A second step': step({
'step 1': step(() => { return Ok() }),
'step 2': step(() => { return Ok() }),
})
})
return uc
}
it('should initiate', () => {
//given
const uc = givenTheSimplestUseCase()
//then
ok(uc.description == 'A use case')
})
context('returning Ok', () => {
it('should run', async () => {
//given
const uc = givenTheSimplestUseCase()
//when
const ret = await uc.run()
//then
ok(ret.isOk)
})
it('should audit', async () => {
//given
const uc = givenTheSimplestUseCase()
//when
await uc.run()
//then
deepEqual(uc.auditTrail, {
type: 'use case',
description: 'A use case',
transactionId: uc._mainStep._auditTrail.transactionId,
elapsedTime: uc._mainStep._auditTrail.elapsedTime,
return: { Ok: {} },
request: null,
steps: [
{ type: 'step', description: 'A step', return: { Ok: '' }, elapsedTime: uc._auditTrail.steps[0].elapsedTime },
{
type: 'step', description: 'A second step', return: { Ok: {} }, elapsedTime: uc._auditTrail.steps[1].elapsedTime, steps: [
{ type: 'step', description: 'step 1', return: { Ok: '' }, elapsedTime: uc._auditTrail.steps[1].steps[0].elapsedTime },
{ type: 'step', description: 'step 2', return: { Ok: '' }, elapsedTime: uc._auditTrail.steps[1].steps[1].elapsedTime }
]
}]
})
})
})
context('returning Err', () => {
const givenTheSimplestUseCaseWithError = () => {
const uc = usecase('A use case', {
'A misstep': step(() => { return Err() })
})
return uc
}
it('should run', async () => {
//given
const uc = givenTheSimplestUseCaseWithError()
//when
const ret = await uc.run()
//then
ok(ret.isErr)
})
})
})
})