Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example of MongoDBInlineProjectionSpec in samples #163

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions samples/webApi/expressjs-with-esdb/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions samples/webApi/expressjs-with-esdb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
},
"homepage": "https://github.com/event-driven-io/emmett#readme",
"dependencies": {
"@event-driven-io/emmett": "0.23.0-alpha.9",
"@event-driven-io/emmett-esdb": "0.23.0-alpha.9",
"@event-driven-io/emmett-expressjs": "0.23.0-alpha.9",
"@event-driven-io/emmett-testcontainers": "0.23.0-alpha.9"
"@event-driven-io/emmett": "0.23.0-alpha.10",
"@event-driven-io/emmett-esdb": "0.23.0-alpha.10",
"@event-driven-io/emmett-expressjs": "0.23.0-alpha.10",
"@event-driven-io/emmett-testcontainers": "0.23.0-alpha.10"
},
"devDependencies": {
"@types/node": "20.11.30",
Expand Down
28 changes: 14 additions & 14 deletions samples/webApi/expressjs-with-mongodb/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions samples/webApi/expressjs-with-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"homepage": "https://github.com/event-driven-io/emmett#readme",
"dependencies": {
"@event-driven-io/emmett": "0.23.0-alpha.9",
"@event-driven-io/emmett-expressjs": "0.23.0-alpha.9",
"@event-driven-io/emmett-mongodb": "0.23.0-alpha.9"
"@event-driven-io/emmett": "0.23.0-alpha.10",
"@event-driven-io/emmett-expressjs": "0.23.0-alpha.10",
"@event-driven-io/emmett-mongodb": "0.23.0-alpha.10"
},
"devDependencies": {
"@testcontainers/mongodb": "^10.10.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void describe('ShoppingCart', () => {
productItem,
addedAt: now,
},
metadata: { clientId },
},
]),
]);
Expand All @@ -64,6 +65,7 @@ void describe('ShoppingCart', () => {
productItem,
addedAt: oldTime,
},
metadata: { clientId },
},
]),
)
Expand All @@ -79,6 +81,7 @@ void describe('ShoppingCart', () => {
shoppingCartId,
confirmedAt: now,
},
metadata: { clientId },
},
]),
]);
Expand All @@ -97,10 +100,12 @@ void describe('ShoppingCart', () => {
productItem,
addedAt: oldTime,
},
metadata: { clientId },
},
{
type: 'ShoppingCartConfirmed',
data: { shoppingCartId, confirmedAt: oldTime },
metadata: { clientId },
},
]),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
expectInlineReadModel,
MongoDBInlineProjectionSpec,
} from '@event-driven-io/emmett-mongodb';
import {
MongoDBContainer,
StartedMongoDBContainer,
} from '@testcontainers/mongodb';
import { after, before, beforeEach, describe, it } from 'node:test';
import { v4 as uuid } from 'uuid';
import { shoppingCartDetailsProjection } from '.';
import { ShoppingCartId, type ShoppingCartEvent } from '../shoppingCart';

void describe('Shopping Cart Short Details Projection', () => {
let mongodb: StartedMongoDBContainer;
let connectionString: string;
let given: MongoDBInlineProjectionSpec<ShoppingCartId, ShoppingCartEvent>;
let shoppingCartId: ShoppingCartId;
let clientId: string;
const now = new Date();

before(async () => {
mongodb = await new MongoDBContainer().start();
connectionString = mongodb.getConnectionString();

given = MongoDBInlineProjectionSpec.for({
projection: shoppingCartDetailsProjection,
connectionString,
clientOptions: {
directConnection: true,
},
});
});

beforeEach(() => {
clientId = uuid();
shoppingCartId = ShoppingCartId(clientId);
});

after(async () => {
try {
await mongodb.stop();
} catch (error) {
console.log(error);
}
});

void it('adds product to empty shopping cart', () =>
given({ streamName: shoppingCartId, events: [] })
.when([
{
type: 'ProductItemAddedToShoppingCart',
data: {
shoppingCartId,
clientId,
productItem: { unitPrice: 100, productId: 'shoes', quantity: 100 },
addedAt: now,
},
metadata: {
clientId,
},
},
])
.then(
expectInlineReadModel.toHave({
status: 'Opened',
clientId,
openedAt: now,
totalAmount: 10000,
productItems: [{ quantity: 100, productId: 'shoes', unitPrice: 100 }],
productItemsCount: 100,
}),
));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
expectInlineReadModel,
MongoDBInlineProjectionSpec,
} from '@event-driven-io/emmett-mongodb';
import {
MongoDBContainer,
StartedMongoDBContainer,
} from '@testcontainers/mongodb';
import { after, before, beforeEach, describe, it } from 'node:test';
import { v4 as uuid } from 'uuid';
import {
shoppingCartShortInfoProjection,
shoppingCartShortInfoProjectionName,
} from '.';
import { ShoppingCartId, type ShoppingCartEvent } from '../shoppingCart';

void describe('Shopping Cart Short Info Projection', () => {
let mongodb: StartedMongoDBContainer;
let connectionString: string;
let given: MongoDBInlineProjectionSpec<ShoppingCartId, ShoppingCartEvent>;
let shoppingCartId: ShoppingCartId;
let clientId: string;
const now = new Date();

before(async () => {
mongodb = await new MongoDBContainer().start();
connectionString = mongodb.getConnectionString();

given = MongoDBInlineProjectionSpec.for({
projection: shoppingCartShortInfoProjection,
connectionString,
clientOptions: {
directConnection: true,
},
});
});

beforeEach(() => {
clientId = uuid();
shoppingCartId = ShoppingCartId(clientId);
});

after(async () => {
try {
await mongodb.stop();
} catch (error) {
console.log(error);
}
});

void it('adds product to empty shopping cart', () =>
given({ streamName: shoppingCartId, events: [] })
.when([
{
type: 'ProductItemAddedToShoppingCart',
data: {
shoppingCartId,
clientId,
productItem: { unitPrice: 100, productId: 'shoes', quantity: 100 },
addedAt: now,
},
metadata: {
clientId,
},
},
])
.then(
expectInlineReadModel
.withName(shoppingCartShortInfoProjectionName)
.toHave({
productItemsCount: 100,
totalAmount: 10000,
}),
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const getShortInfoById = (
});

export const shoppingCartShortInfoProjection = mongoDBInlineProjection({
name: shoppingCartShortInfoProjectionName,
evolve,
canHandle: [
'ProductItemAddedToShoppingCart',
Expand Down
Loading
Loading