Skip to content

0.16.0

Compare
Choose a tag to compare
@oskardudycz oskardudycz released this 09 Aug 18:05
· 242 commits to main since this release

🚀 What's New

1. Added PostgreSQL and Pongo Projection specification for integration testing

Now you can write your tests as:

const given = PostgreSQLProjectionSpec.for({
  projection: shoppingCartShortInfoProjection,
  connectionString,
});

test('with empty given and when eventsInStream', 
  given(
    eventsInStream<ProductItemAdded>(shoppingCartId, [
      {
        type: 'ProductItemAdded',
        data: {
          productItem: { price: 100, productId: 'shoes', quantity: 100 },
        },
      },
    ]),
 )
  .when(
    newEventsInStream(shoppingCartId, [
      {
        type: 'DiscountApplied',
        data: { percent: 10 },
      },
    ]),
  )
  .then(
    expectPongoDocuments
      .fromCollection(shoppingCartShortInfoCollectionName)
      .withId(shoppingCartId)
      .toBeEqual({
        productItemsCount: 100,
        totalAmount: 9000,
      }),
    );
});

There are also other helpers; you can also check raw projections using helpers like assertSQLQueryResultMatches.

by @oskardudycz in #105

2. Refactored Postgres projections registrations

  • Separated projection definition from registration. Thanks to that, projections will be able to switch their type in the future or be used in both (e.g., for rebuilds).
  • Refactored projections to take params object instead of a list of parameters. That will cut the number of permutations and make it easier to define them
  • Renamed pongoSingleProjection to pongoSingleStreamProjection to keep naming consistency.

Now, registration will look like this (notice projections.inline helper):

import { projections } from '@event-driven-io/emmett';

const eventStore = getPostgreSQLEventStore(connectionString, {
  projections: projections.inline(
    [shoppingCartShortInfoProjection, customProjection]
  ),
});

And Pongo projection definition as:

const shoppingCartShortInfoProjection = pongoSingleStreamProjection({
  collectionName: 'shoppingCartsShortInfo',
  evolve,
  canHandle: ['ProductItemAdded', 'DiscountApplied'],
});

by @oskardudycz in #104

📝 What’s Changed

Full Changelog: 0.15.0...0.16.0