Skip to content

Commit d8d5260

Browse files
committed
Pulling through Command.Process as TaskEither into the tests
1 parent a2dcebe commit d8d5260

File tree

7 files changed

+264
-165
lines changed

7 files changed

+264
-165
lines changed

tests/commands/area/add-owner.test.ts

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ import {faker} from '@faker-js/faker';
33
import {NonEmptyString, UUID} from 'io-ts-types';
44
import {constructEvent} from '../../../src/types';
55
import {v4} from 'uuid';
6-
import {arbitraryActor} from '../../helpers';
6+
import {arbitraryActor, getRightOrFail} from '../../helpers';
77
import {addOwner} from '../../../src/commands/area/add-owner';
8+
import { initTestFramework, TestFramework } from '../../read-models/test-framework';
9+
import { pipe } from 'fp-ts/lib/function';
810

911
describe('add-owner', () => {
12+
let framework: TestFramework;
13+
14+
beforeEach(async () => {
15+
framework = await initTestFramework();
16+
});
17+
afterEach(() => {
18+
framework.close();
19+
});
20+
21+
1022
const areaId = v4() as UUID;
1123
const areaName = faker.commerce.productName() as NonEmptyString;
1224
const memberNumber = faker.number.int();
@@ -37,35 +49,45 @@ describe('add-owner', () => {
3749
});
3850

3951
describe('when the area does not exist', () => {
40-
const result = addOwner.process({
41-
command,
42-
events: [],
43-
});
52+
it('does nothing', async () => {
53+
const result = pipe(
54+
await addOwner.process({
55+
command,
56+
events: [],
57+
deps: framework
58+
})(),
59+
getRightOrFail,
60+
);
4461

45-
it('does nothing', () => {
4662
expect(result).toStrictEqual(O.none);
4763
});
4864
});
4965

5066
describe('when the area has been removed', () => {
51-
const result = addOwner.process({
52-
command,
53-
events: [areaCreated, areaRemoved],
54-
});
55-
56-
it('does nothing', () => {
67+
it('does nothing', async () => {
68+
const result = pipe(
69+
await addOwner.process({
70+
command,
71+
events: [areaCreated, areaRemoved],
72+
deps: framework,
73+
})(),
74+
getRightOrFail
75+
);
5776
expect(result).toStrictEqual(O.none);
5877
});
5978
});
6079

6180
describe('when the area exists', () => {
6281
describe('and the member was never an owner of it', () => {
63-
const result = addOwner.process({
64-
command,
65-
events: [areaCreated],
66-
});
67-
68-
it('adds them as owner', () => {
82+
it('adds them as owner', async () => {
83+
const result = pipe(
84+
await addOwner.process({
85+
command,
86+
events: [areaCreated],
87+
deps: framework,
88+
})(),
89+
getRightOrFail
90+
);
6991
expect(result).toStrictEqual(
7092
O.some(
7193
expect.objectContaining({
@@ -79,12 +101,15 @@ describe('add-owner', () => {
79101
});
80102

81103
describe('and the member is no longer an owner of it', () => {
82-
const result = addOwner.process({
83-
command,
84-
events: [areaCreated, ownerAdded, ownerRemoved],
85-
});
86-
87-
it('adds them as owner', () => {
104+
it('adds them as owner', async () => {
105+
const result = pipe(
106+
await addOwner.process({
107+
command,
108+
events: [areaCreated, ownerAdded, ownerRemoved],
109+
deps: framework,
110+
})(),
111+
getRightOrFail
112+
);
88113
expect(result).toStrictEqual(
89114
O.some(
90115
expect.objectContaining({
@@ -98,12 +123,15 @@ describe('add-owner', () => {
98123
});
99124

100125
describe('and the member is an owner', () => {
101-
const result = addOwner.process({
102-
command,
103-
events: [areaCreated, ownerAdded],
104-
});
105-
106-
it('does nothing', () => {
126+
it('does nothing', async () => {
127+
const result = pipe(
128+
await addOwner.process({
129+
command,
130+
events: [areaCreated, ownerAdded],
131+
deps: framework,
132+
})(),
133+
getRightOrFail,
134+
);
107135
expect(result).toStrictEqual(O.none);
108136
});
109137
});

tests/commands/area/create.test.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,34 @@ import {NonEmptyString, UUID} from 'io-ts-types';
44
import {create} from '../../../src/commands/area/create';
55
import {constructEvent} from '../../../src/types';
66
import {v4} from 'uuid';
7-
import {arbitraryActor} from '../../helpers';
7+
import {arbitraryActor, getRightOrFail} from '../../helpers';
8+
import { pipe } from 'fp-ts/lib/function';
9+
import { initTestFramework, TestFramework } from '../../read-models/test-framework';
810

911
describe('create-area', () => {
12+
let framework: TestFramework;
13+
beforeEach(async () => {
14+
framework = await initTestFramework();
15+
});
16+
afterEach(() => {
17+
framework.close();
18+
});
19+
1020
describe('when the area does not yet exist', () => {
1121
const areaName = faker.commerce.productName() as NonEmptyString;
12-
const result = create.process({
13-
command: {
14-
id: v4() as UUID,
15-
name: areaName,
16-
actor: arbitraryActor(),
17-
},
18-
events: [],
19-
});
20-
it('creates the area', () => {
22+
it('creates the area', async () => {
23+
const result = pipe(
24+
await create.process({
25+
command: {
26+
id: v4() as UUID,
27+
name: areaName,
28+
actor: arbitraryActor(),
29+
},
30+
events: [],
31+
deps: framework
32+
})(),
33+
getRightOrFail,
34+
);
2135
expect(result).toStrictEqual(
2236
O.some(
2337
expect.objectContaining({
@@ -31,21 +45,25 @@ describe('create-area', () => {
3145

3246
describe('when the area already exists', () => {
3347
const areaName = faker.commerce.productName() as NonEmptyString;
34-
const result = create.process({
35-
command: {
36-
id: v4() as UUID,
37-
name: areaName,
38-
actor: arbitraryActor(),
39-
},
40-
events: [
41-
constructEvent('AreaCreated')({
42-
id: v4() as UUID,
43-
name: areaName,
44-
actor: arbitraryActor(),
45-
}),
46-
],
47-
});
48-
it('does nothing', () => {
48+
it('does nothing', async () => {
49+
const result = pipe(
50+
await create.process({
51+
command: {
52+
id: v4() as UUID,
53+
name: areaName,
54+
actor: arbitraryActor(),
55+
},
56+
events: [
57+
constructEvent('AreaCreated')({
58+
id: v4() as UUID,
59+
name: areaName,
60+
actor: arbitraryActor(),
61+
}),
62+
],
63+
deps: framework,
64+
})(),
65+
getRightOrFail
66+
);
4967
expect(result).toStrictEqual(O.none);
5068
});
5169
});

tests/commands/area/remove-area.test.ts

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ import {faker} from '@faker-js/faker';
33
import {NonEmptyString, UUID} from 'io-ts-types';
44
import {constructEvent} from '../../../src/types';
55
import {v4} from 'uuid';
6-
import {arbitraryActor} from '../../helpers';
6+
import {arbitraryActor, getRightOrFail} from '../../helpers';
77
import {removeArea} from '../../../src/commands/area/remove-area';
8+
import { initTestFramework, TestFramework } from '../../read-models/test-framework';
9+
import { pipe } from 'fp-ts/lib/function';
810

911
describe('remove-area', () => {
12+
let framework: TestFramework;
13+
beforeEach(async () => {
14+
framework = await initTestFramework();
15+
});
16+
afterEach(() => {
17+
framework.close();
18+
});
19+
1020
const areaId = v4() as UUID;
1121
const areaName = faker.commerce.productName() as NonEmptyString;
1222
const command = {
@@ -15,29 +25,36 @@ describe('remove-area', () => {
1525
};
1626

1727
describe('when the area does not yet exist', () => {
18-
const result = removeArea.process({
19-
command,
20-
events: [],
21-
});
28+
it('does nothing', async () => {
29+
const result = pipe(
30+
await removeArea.process({
31+
command,
32+
events: [],
33+
deps: framework,
34+
})(),
35+
getRightOrFail,
36+
);
2237

23-
it('does nothing', () => {
2438
expect(result).toStrictEqual(O.none);
2539
});
2640
});
2741

2842
describe('when the area already exists', () => {
29-
const result = removeArea.process({
30-
command,
31-
events: [
32-
constructEvent('AreaCreated')({
33-
id: areaId,
34-
name: areaName,
35-
actor: arbitraryActor(),
36-
}),
37-
],
38-
});
39-
40-
it('removes the area', () => {
43+
it('removes the area', async () => {
44+
const result = pipe(
45+
await removeArea.process({
46+
command,
47+
events: [
48+
constructEvent('AreaCreated')({
49+
id: areaId,
50+
name: areaName,
51+
actor: arbitraryActor(),
52+
}),
53+
],
54+
deps: framework,
55+
})(),
56+
getRightOrFail,
57+
);
4158
expect(result).toStrictEqual(
4259
O.some(
4360
expect.objectContaining({
@@ -50,22 +67,25 @@ describe('remove-area', () => {
5067
});
5168

5269
describe('when the area is already removed', () => {
53-
const result = removeArea.process({
54-
command: {
55-
id: areaId,
56-
actor: arbitraryActor(),
57-
},
58-
events: [
59-
constructEvent('AreaCreated')({
60-
id: areaId,
61-
name: areaName,
62-
actor: arbitraryActor(),
63-
}),
64-
constructEvent('AreaRemoved')({id: areaId, actor: arbitraryActor()}),
65-
],
66-
});
67-
68-
it('does nothing', () => {
70+
it('does nothing', async () => {
71+
const result = pipe(
72+
await removeArea.process({
73+
command: {
74+
id: areaId,
75+
actor: arbitraryActor(),
76+
},
77+
events: [
78+
constructEvent('AreaCreated')({
79+
id: areaId,
80+
name: areaName,
81+
actor: arbitraryActor(),
82+
}),
83+
constructEvent('AreaRemoved')({id: areaId, actor: arbitraryActor()}),
84+
],
85+
deps: framework,
86+
})(),
87+
getRightOrFail,
88+
);
6989
expect(result).toStrictEqual(O.none);
7090
});
7191
});

0 commit comments

Comments
 (0)