Skip to content

Commit

Permalink
Removed redundant inline projections in connection and storage e2e tests
Browse files Browse the repository at this point in the history
We have a dedicated set of e2e tests for projections. No need to keep the noise in the other places.
  • Loading branch information
oskardudycz committed Dec 18, 2024
1 parent 021db39 commit 3259540
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
assertIsNotNull,
assertNotEqual,
assertThrowsAsync,
projections,
STREAM_DOES_NOT_EXIST,
} from '@event-driven-io/emmett';
import {
Expand All @@ -15,20 +14,16 @@ import { v4 as uuid } from 'uuid';
import {
getMongoDBEventStore,
MongoDBEventStoreDefaultStreamVersion,
mongoDBInlineProjection,
toStreamCollectionName,
toStreamName,
type MongoDBEventStore,
type StreamType,
} from '.';
import {
type DiscountApplied,
type PricedProductItem,
type ProductItemAdded,
type ShoppingCartEvent,
} from '../testing/shoppingCart.domain';

const SHOPPING_CART_PROJECTION_NAME = 'shoppingCartShortInfo';
const streamType: StreamType = 'shopping_cart';

void describe('MongoDBEventStore connection', () => {
Expand All @@ -50,13 +45,6 @@ void describe('MongoDBEventStore connection', () => {
const eventStore = getMongoDBEventStore({
connectionString: mongodb.getConnectionString(),
clientOptions: { directConnection: true },
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});
try {
await assertCanAppend(eventStore);
Expand All @@ -70,13 +58,6 @@ void describe('MongoDBEventStore connection', () => {
const eventStore = getMongoDBEventStore({
connectionString: mongodb.getConnectionString(),
clientOptions: { directConnection: true },
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});
// and
await assertCanAppend(eventStore);
Expand All @@ -98,13 +79,6 @@ void describe('MongoDBEventStore connection', () => {
try {
const eventStore = getMongoDBEventStore({
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand All @@ -129,13 +103,6 @@ void describe('MongoDBEventStore connection', () => {
try {
const eventStore = getMongoDBEventStore({
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand All @@ -148,13 +115,6 @@ void describe('MongoDBEventStore connection', () => {
const eventStore = getMongoDBEventStore({
connectionString: mongodb.getConnectionString(),
clientOptions: { directConnection: true },
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});
try {
await assertCanAppend(eventStore);
Expand Down Expand Up @@ -184,33 +144,3 @@ const assertCanAppend = async (eventStore: MongoDBEventStore) => {
MongoDBEventStoreDefaultStreamVersion,
);
};

type ShoppingCartShortInfo = {
productItemsCount: number;
totalAmount: number;
};

const evolve = (
document: ShoppingCartShortInfo | null,
{ type, data: event }: ProductItemAdded | DiscountApplied,
): ShoppingCartShortInfo | null => {
document = document ?? { productItemsCount: 0, totalAmount: 0 };

switch (type) {
case 'ProductItemAdded':
return {
totalAmount:
document.totalAmount +
event.productItem.price * event.productItem.quantity,
productItemsCount:
document.productItemsCount + event.productItem.quantity,
};
case 'DiscountApplied':
return {
...document,
totalAmount: (document.totalAmount * (100 - event.percent)) / 100,
};
default:
return document;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
assertNotEqual,
assertOk,
assertThatArray,
projections,
STREAM_DOES_NOT_EXIST,
} from '@event-driven-io/emmett';
import {
Expand All @@ -17,7 +16,6 @@ import {
DefaultMongoDBEventStoreCollectionName,
getMongoDBEventStore,
MongoDBEventStoreDefaultStreamVersion,
mongoDBInlineProjection,
toStreamCollectionName,
toStreamName,
type EventStream,
Expand All @@ -32,7 +30,6 @@ import {
type ShoppingCartEvent,
} from '../testing/shoppingCart.domain';

const SHOPPING_CART_PROJECTION_NAME = 'shoppingCartShortInfo';
const streamType: StreamType = 'shopping_cart';

void describe('MongoDBEventStore storage resolution', () => {
Expand All @@ -58,13 +55,6 @@ void describe('MongoDBEventStore storage resolution', () => {
try {
const eventStore = getMongoDBEventStore({
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand Down Expand Up @@ -94,13 +84,6 @@ void describe('MongoDBEventStore storage resolution', () => {
collectionName: customCollectionName,
},
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand All @@ -127,13 +110,6 @@ void describe('MongoDBEventStore storage resolution', () => {
type: 'SINGLE_COLLECTION',
},
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand Down Expand Up @@ -169,13 +145,6 @@ void describe('MongoDBEventStore storage resolution', () => {
}),
},
client,
projections: projections.inline([
mongoDBInlineProjection({
name: SHOPPING_CART_PROJECTION_NAME,
canHandle: ['ProductItemAdded', 'DiscountApplied'],
evolve,
}),
]),
});

await assertCanAppend(eventStore);
Expand Down Expand Up @@ -235,33 +204,3 @@ const assertEventStoreSetUpCollection = async (
EventStream<ProductItemAdded | DiscountApplied>
>;
};

type ShoppingCartShortInfo = {
productItemsCount: number;
totalAmount: number;
};

const evolve = (
document: ShoppingCartShortInfo | null,
{ type, data: event }: ProductItemAdded | DiscountApplied,
): ShoppingCartShortInfo | null => {
document = document ?? { productItemsCount: 0, totalAmount: 0 };

switch (type) {
case 'ProductItemAdded':
return {
totalAmount:
document.totalAmount +
event.productItem.price * event.productItem.quantity,
productItemsCount:
document.productItemsCount + event.productItem.quantity,
};
case 'DiscountApplied':
return {
...document,
totalAmount: (document.totalAmount * (100 - event.percent)) / 100,
};
default:
return document;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void describe('MongoDBEventStore', () => {
);

eventStore = getMongoDBEventStore({
storage: { type: 'COLLECTION_PER_STREAM_TYPE' },
client,
projections: projections.inline([
mongoDBInlineProjection({
Expand Down

0 comments on commit 3259540

Please sign in to comment.