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

Add correlation ID to all use cases and send it to backbone #268

Merged
merged 10 commits into from
Sep 13, 2024
26 changes: 15 additions & 11 deletions packages/transport/test/core/backbone/CorrelationId.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import { IDatabaseConnection } from "@js-soft/docdb-access-abstractions";
import correlationIdLib from "correlation-id";
import { AccountController } from "../../../src";
import { RequestInterceptor } from "../../testHelpers/RequestInterceptor";
import { TestUtil } from "../../testHelpers/TestUtil";

describe("CorrelationId", function () {
test("should send correlation id to the backend when given", async function () {
// Arrange
const connection = await TestUtil.createDatabaseConnection();
let connection: IDatabaseConnection;
let testAccount: AccountController;
let interceptor: RequestInterceptor;
beforeAll(async function () {
connection = await TestUtil.createDatabaseConnection();
const transport = TestUtil.createTransport(connection);
await transport.init();
const accounts = await TestUtil.provideAccounts(transport, 1);
const testAccount = accounts[0];
const interceptor = new RequestInterceptor((testAccount as any).synchronization.client);
testAccount = accounts[0];
interceptor = new RequestInterceptor((testAccount as any).synchronization.client);
});

// Act
afterAll(async function () {
await testAccount.close();
await connection.close();
});
test("should send correlation id to the backend when given", async function () {
interceptor.start();
await correlationIdLib.withId("test-correlation-id", async () => {
await testAccount.syncEverything();
});

// Assert
const requests = interceptor.stop().requests;
expect(requests.at(-1)!.headers!["x-correlation-id"]).toBe("test-correlation-id");

// Cleanup
await testAccount.close();
await connection.close();
});
});
Loading