-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example of MongoDBInlineProjectionSpec in samples
- Loading branch information
1 parent
8d6c549
commit a5fc62b
Showing
12 changed files
with
218 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
samples/webApi/expressjs-with-mongodb/src/shoppingCarts/getDetails/index.int.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
)); | ||
}); |
75 changes: 75 additions & 0 deletions
75
samples/webApi/expressjs-with-mongodb/src/shoppingCarts/getShortInfo/index.int.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.