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 assertions to not need to use built-in Node to make it compatible with browsers #79

Merged
merged 3 commits into from
Jun 12, 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
10 changes: 5 additions & 5 deletions src/docs/snippets/gettingStarted/webApi/simpleApi.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
assertEqual,
assertMatches,
assertOk,
getInMemoryEventStore,
type EventStore,
} from '@event-driven-io/emmett';
import { getApplication } from '@event-driven-io/emmett-expressjs';

import { type Application } from 'express';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { beforeEach, describe, it } from 'node:test';
import request from 'supertest';
Expand Down Expand Up @@ -78,7 +78,7 @@ void describe('Simple Api from getting started', () => {
await request(app)
.delete(`/clients/${clientId}/shopping-carts/current`)
.expect((response) => {
assert.equal(response.statusCode, 403);
assertEqual(response.statusCode, 403);
});

const shoppingCartId = getShoppingCartId(clientId);
Expand All @@ -87,8 +87,8 @@ void describe('Simple Api from getting started', () => {
getShoppingCartId(clientId),
);

assert.ok(result);
assert.equal(result.events.length, 4);
assertOk(result);
assertEqual(result.events.length, 4);

assertMatches(result?.events, [
{
Expand Down
50 changes: 25 additions & 25 deletions src/package-lock.json

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

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
assertEqual,
assertFails,
assertMatches,
assertOk,
getInMemoryEventStore,
type EventStore,
} from '@event-driven-io/emmett';
import { type Application } from 'express';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { beforeEach, describe, it } from 'node:test';
import request from 'supertest';
Expand Down Expand Up @@ -42,9 +44,9 @@ void describe('Application logic with optimistic concurrency', () => {
const current = createResponse.body;

if (!current.id) {
assert.fail();
assertFails();
}
assert.ok(current.id);
assertOk(current.id);

const shoppingCartId = current.id;

Expand Down Expand Up @@ -122,7 +124,7 @@ void describe('Application logic with optimistic concurrency', () => {
.delete(`/clients/${clientId}/shopping-carts/${shoppingCartId}`)
.set(HeaderNames.IF_MATCH, toWeakETag(currentRevision))
.expect((response) => {
assert.equal(response.statusCode, 403);
assertEqual(response.statusCode, 403);
assertMatches(response.body, {
detail: ShoppingCartErrors.CART_IS_ALREADY_CLOSED,
});
Expand All @@ -131,8 +133,8 @@ void describe('Application logic with optimistic concurrency', () => {
const result =
await eventStore.readStream<ShoppingCartEvent>(shoppingCartId);

assert.ok(result);
assert.equal(result.events.length, Number(currentRevision));
assertOk(result);
assertEqual(result.events.length, Number(currentRevision));

assertMatches(result?.events, [
{
Expand Down
11 changes: 7 additions & 4 deletions src/packages/emmett-expressjs/src/e2e/testing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { assertUnsignedBigInt } from '@event-driven-io/emmett';
import assert from 'node:assert/strict';
import {
assertMatches,
assertOk,
assertUnsignedBigInt,
} from '@event-driven-io/emmett';
import { Test, type Response } from 'supertest';
import { getWeakETagValue, type ETag } from '../etag';

Expand All @@ -15,8 +18,8 @@ export const expectNextRevisionInResponseEtag = <RequestBody>(
response: TestResponse<RequestBody>,
) => {
const eTagValue = response.headers['etag'];
assert.ok(eTagValue);
assert.match(eTagValue, /W\/"\d+.*"/);
assertOk(eTagValue);
assertMatches(eTagValue, /W\/"\d+.*"/);

const eTag = getWeakETagValue(eTagValue as ETag);

Expand Down
9 changes: 5 additions & 4 deletions src/packages/emmett-expressjs/src/testing/apiSpecification.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
assertEqual,
assertFails,
assertMatches,
type DefaultStreamVersionType,
type Event,
type EventStore,
} from '@event-driven-io/emmett';
import { type Application } from 'express';
import type { ProblemDocument } from 'http-problem-details';
import assert from 'node:assert/strict';
import type { Response, Test } from 'supertest';
import supertest from 'supertest';
import type TestAgent from 'supertest/lib/agent';
Expand Down Expand Up @@ -57,7 +58,7 @@ export const expectResponse =
) =>
(response: Response): void => {
const { body, headers } = options ?? {};
assert.equal(response.statusCode, statusCode);
assertEqual(response.statusCode, statusCode);
if (body) assertMatches(response.body, body);
if (headers) assertMatches(response.headers, headers);
};
Expand Down Expand Up @@ -115,14 +116,14 @@ export const ApiSpecification = {
if (typeof verify === 'function') {
const succeeded = verify(response);

if (succeeded === false) assert.fail();
if (succeeded === false) assertFails();
} else if (Array.isArray(verify)) {
const [first, ...rest] = verify;

if (typeof first === 'function') {
const succeeded = first(response);

if (succeeded === false) assert.fail();
if (succeeded === false) assertFails();
}

const events = typeof first === 'function' ? rest : verify;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
assertEqual,
assertFails,
assertMatches,
assertOk,
getInMemoryEventStore,
type EventStore,
} from '@event-driven-io/emmett';
import { type FastifyInstance } from 'fastify';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { beforeEach, describe, it } from 'node:test';
import { getApplication } from '../..';
Expand Down Expand Up @@ -34,9 +36,9 @@ void describe('Application logic with optimistic concurrency using Fastify', ()

const current = createResponse.json<{ id: string }>();
if (!current?.id) {
assert.fail();
assertFails();
}
assert.ok(current.id);
assertOk(current.id);

const shoppingCartId = current.id;
///////////////////////////////////////////////////
Expand All @@ -51,7 +53,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/product-items`,
body: twoPairsOfShoes,
});
assert.equal(response.statusCode, 204);
assertEqual(response.statusCode, 204);

///////////////////////////////////////////////////
// 3. Add T-Shirt
Expand All @@ -67,7 +69,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
body: tShirt,
});

assert.equal(response.statusCode, 204);
assertEqual(response.statusCode, 204);

///////////////////////////////////////////////////
// 4. Remove pair of shoes
Expand All @@ -82,7 +84,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
method: 'DELETE',
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/product-items?productId=${pairOfShoes.productId}&quantity=${pairOfShoes.quantity}&unitPrice=${pairOfShoes.unitPrice}`,
});
assert.equal(response.statusCode, 204);
assertEqual(response.statusCode, 204);

///////////////////////////////////////////////////
// 5. Confirm cart
Expand All @@ -93,7 +95,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/confirm`,
});

assert.equal(response.statusCode, 204);
assertEqual(response.statusCode, 204);

///////////////////////////////////////////////////
// 6. Try Cancel Cart
Expand All @@ -103,15 +105,15 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}`,
});

assert.equal(response.statusCode, 403);
assertEqual(response.statusCode, 403);
assertMatches(response.json(), {
detail: ShoppingCartErrors.CART_IS_ALREADY_CLOSED,
});
const result =
await eventStore.readStream<ShoppingCartEvent>(shoppingCartId);

assert.ok(result);
assert.equal(result.events.length, Number(5));
assertOk(result);
assertEqual(result.events.length, Number(5));

assertMatches(result?.events, [
{
Expand Down
6 changes: 3 additions & 3 deletions src/packages/emmett-fastify/src/e2e/testing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertMatches, assertOk } from '@event-driven-io/emmett';
import type { Response } from 'light-my-request';
import assert from 'node:assert/strict';
import type { Test } from 'supertest';

export type TestResponse<RequestBody> = Omit<
Expand All @@ -14,8 +14,8 @@ export const expectNextRevisionInResponseEtag = <RequestBody>(
response: TestResponse<RequestBody>,
) => {
const eTagValue = response.headers['etag'];
assert.ok(eTagValue);
assert.match(eTagValue, /W\/"\d+.*"/);
assertOk(eTagValue);
assertMatches(eTagValue, /W\/"\d+.*"/);
};

export const runTwice = (test: () => Promise<Response>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { jsonEvent } from '@eventstore/db-client';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { after, beforeEach, describe, it } from 'node:test';
import {
EventStoreDBContainer,
StartedEventStoreDBContainer,
} from './eventStoreDBContainer';
import { assertOk } from '@event-driven-io/emmett';

void describe('EventStoreDBContainer', () => {
let container: StartedEventStoreDBContainer;
Expand All @@ -22,7 +22,7 @@ void describe('EventStoreDBContainer', () => {
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
);

assert.ok(result.success);
assertOk(result.success);
});

after(async () => {
Expand Down
Loading
Loading