Skip to content

Commit 6a18731

Browse files
committed
Updated API tests to use strongly-typed Event Store type
Previously it was always taking the Event Store implementation which was forcing to do casting while setting up, which was not great. Fixed also Event Store wrapper to just override the needed methods passing the rest as they are. Without it, event store extensions (like MongoDB projections api) wouldn't work. Removed event store wrapper usage from E2E tests, as it was redundant: checks are only made on responses.
1 parent cd245e9 commit 6a18731

File tree

11 files changed

+50
-62
lines changed

11 files changed

+50
-62
lines changed

src/docs/snippets/gettingStarted/webApi/apiBDD.e2e.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ShoppingCartStatus } from './shoppingCart';
44
import { shoppingCartApi } from './simpleApi';
55

66
// #region getting-started-e2e-tests
7-
import { type EventStore } from '@event-driven-io/emmett';
87
import { getEventStoreDBEventStore } from '@event-driven-io/emmett-esdb';
98
import {
109
ApiE2ESpecification,
@@ -29,8 +28,8 @@ void describe('ShoppingCart E2E', () => {
2928
esdbContainer = await new EventStoreDBContainer().start();
3029

3130
given = ApiE2ESpecification.for(
32-
(): EventStore => getEventStoreDBEventStore(esdbContainer.getClient()),
33-
(eventStore: EventStore) =>
31+
() => getEventStoreDBEventStore(esdbContainer.getClient()),
32+
(eventStore) =>
3433
getApplication({
3534
apis: [
3635
shoppingCartApi(

src/docs/snippets/gettingStarted/webApi/apiBDD.int.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { beforeEach, describe, it } from 'node:test';
22
import type { PricedProductItem, ShoppingCartEvent } from '../events';
33
import { shoppingCartApi } from './simpleApi';
44
// #region getting-started-integration-tests
5-
import {
6-
getInMemoryEventStore,
7-
type EventStore,
8-
} from '@event-driven-io/emmett';
5+
import { getInMemoryEventStore } from '@event-driven-io/emmett';
96
import {
107
ApiSpecification,
118
existingStream,
@@ -119,8 +116,8 @@ void describe('ShoppingCart', () => {
119116
const unitPrice = Math.random() * 10;
120117

121118
const given = ApiSpecification.for<ShoppingCartEvent>(
122-
(): EventStore => getInMemoryEventStore(),
123-
(eventStore: EventStore) =>
119+
() => getInMemoryEventStore(),
120+
(eventStore) =>
124121
getApplication({
125122
apis: [
126123
shoppingCartApi(

src/docs/snippets/gettingStarted/webApi/apiBDDE2EGiven.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ void describe('ShoppingCart E2E', () => {
2727
// #endregion test-container
2828

2929
// #region given
30-
import { type EventStore } from '@event-driven-io/emmett';
3130
import { getEventStoreDBEventStore } from '@event-driven-io/emmett-esdb';
3231
import {
3332
ApiE2ESpecification,
3433
getApplication,
3534
} from '@event-driven-io/emmett-expressjs';
3635

3736
const given = ApiE2ESpecification.for(
38-
(): EventStore => getEventStoreDBEventStore(esdbContainer.getClient()),
39-
(eventStore: EventStore) =>
37+
() => getEventStoreDBEventStore(esdbContainer.getClient()),
38+
(eventStore) =>
4039
getApplication({
4140
apis: [
4241
shoppingCartApi(

src/docs/snippets/gettingStarted/webApi/apiBDDE2ETest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type EventStore } from '@event-driven-io/emmett';
21
import {
32
ApiE2ESpecification,
43
getApplication,
@@ -15,8 +14,8 @@ const now = new Date();
1514
const unitPrice = Math.random() * 10;
1615

1716
const given = ApiE2ESpecification.for(
18-
(): EventStore => getEventStoreDBEventStore(esdbContainer.getClient()),
19-
(eventStore: EventStore) =>
17+
() => getEventStoreDBEventStore(esdbContainer.getClient()),
18+
(eventStore) =>
2019
getApplication({
2120
apis: [
2221
shoppingCartApi(

src/docs/snippets/gettingStarted/webApi/apiBDDIntGiven.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import type { ShoppingCartEvent } from '../events';
33
import { shoppingCartApi } from './simpleApi';
44

55
// #region given
6-
import {
7-
getInMemoryEventStore,
8-
type EventStore,
9-
} from '@event-driven-io/emmett';
6+
import { getInMemoryEventStore } from '@event-driven-io/emmett';
107
import {
118
ApiSpecification,
129
getApplication,
@@ -16,8 +13,8 @@ const unitPrice = 100;
1613
const now = new Date();
1714

1815
const given = ApiSpecification.for<ShoppingCartEvent>(
19-
(): EventStore => getInMemoryEventStore(),
20-
(eventStore: EventStore) =>
16+
() => getInMemoryEventStore(),
17+
(eventStore) =>
2118
getApplication({
2219
apis: [
2320
shoppingCartApi(

src/docs/snippets/gettingStarted/webApi/apiBDDIntTest.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
getInMemoryEventStore,
3-
type EventStore,
4-
} from '@event-driven-io/emmett';
1+
import { getInMemoryEventStore } from '@event-driven-io/emmett';
52
import {
63
ApiSpecification,
74
getApplication,
@@ -18,8 +15,8 @@ const now = new Date();
1815
const unitPrice = Math.random() * 10;
1916

2017
const given = ApiSpecification.for<ShoppingCartEvent>(
21-
(): EventStore => getInMemoryEventStore(),
22-
(eventStore: EventStore) =>
18+
() => getInMemoryEventStore(),
19+
(eventStore) =>
2320
getApplication({
2421
apis: [
2522
shoppingCartApi(

src/package-lock.json

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/emmett-expressjs/src/testing/apiE2ESpecification.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import supertest, { type Response } from 'supertest';
22

33
import type { EventStore } from '@event-driven-io/emmett';
4-
import { WrapEventStore } from '@event-driven-io/emmett';
54
import assert from 'assert';
65
import type { Application } from 'express';
76
import type { TestRequest } from './apiSpecification';
@@ -17,13 +16,13 @@ export type ApiE2ESpecification = (...givenRequests: TestRequest[]) => {
1716
};
1817

1918
export const ApiE2ESpecification = {
20-
for: (
21-
getEventStore: () => EventStore,
22-
getApplication: (eventStore: EventStore) => Application,
19+
for: <Store extends EventStore = EventStore>(
20+
getEventStore: () => Store,
21+
getApplication: (eventStore: Store) => Application,
2322
): ApiE2ESpecification => {
2423
{
2524
return (...givenRequests: TestRequest[]) => {
26-
const eventStore = WrapEventStore(getEventStore());
25+
const eventStore = getEventStore();
2726
const application = getApplication(eventStore);
2827

2928
return {

src/packages/emmett-expressjs/src/testing/apiSpecification.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export type ApiSpecification<EventType extends Event = Event> = (
8585
};
8686

8787
export const ApiSpecification = {
88-
for: <EventType extends Event = Event>(
89-
getEventStore: () => EventStore,
90-
getApplication: (eventStore: EventStore) => Application,
88+
for: <EventType extends Event = Event, Store extends EventStore = EventStore>(
89+
getEventStore: () => Store,
90+
getApplication: (eventStore: Store) => Application,
9191
): ApiSpecification<EventType> => {
9292
{
9393
return (...givenStreams: TestEventStream<EventType>[]) => {

src/packages/emmett-sqlite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@types/sqlite3": "^3.1.11"
7474
},
7575
"peerDependencies": {
76-
"@event-driven-io/emmett": "^0.23.0-alpha.7",
76+
"@event-driven-io/emmett": "0.23.0-alpha.7",
7777
"sqlite3": "^5.1.7"
7878
}
7979
}

src/packages/emmett/src/testing/wrapEventStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const WrapEventStore = <Store extends EventStore>(
3030
const appendedEvents = new Map<string, TestEventStream>();
3131

3232
const wrapped = {
33+
...eventStore,
3334
aggregateStream<State, EventType extends Event>(
3435
streamName: string,
3536
options: AggregateStreamOptions<State, EventType>,

0 commit comments

Comments
 (0)