From d03d5e9cd3e8d7974da31c24c4ad287b389e5eb9 Mon Sep 17 00:00:00 2001 From: George Payne Date: Tue, 1 Feb 2022 12:24:33 +0100 Subject: [PATCH] Rename `getProjectionStatistics` to `getProjectionStatus` - Add tests - Update samples - Deprecated `getProjectionStatistics` - Will be removed in `v4.0.0` - Use `getProjectionStatus` --- samples/projection-management.ts | 2 +- ...etProjectionStatistics.deprecated.test.ts} | 0 .../projections/getProjectionStatus.test.ts | 54 +++++++++++++++++++ ...onStatistics.ts => getProjectionStatus.ts} | 28 ++++++++-- src/projections/index.ts | 2 +- 5 files changed, 79 insertions(+), 7 deletions(-) rename src/__test__/projections/{getProjectionStatistics.test.ts => getProjectionStatistics.deprecated.test.ts} (100%) create mode 100644 src/__test__/projections/getProjectionStatus.test.ts rename src/projections/{getProjectionStatistics.ts => getProjectionStatus.ts} (67%) diff --git a/samples/projection-management.ts b/samples/projection-management.ts index 1de317db..7bffd07f 100644 --- a/samples/projection-management.ts +++ b/samples/projection-management.ts @@ -264,7 +264,7 @@ describe("[sample] projection-management", () => { const name = await createTestProjection(); // region GetStatus - const projection = await client.getProjectionStatistics(name); + const projection = await client.getProjectionStatus(name); console.log( projection.name, diff --git a/src/__test__/projections/getProjectionStatistics.test.ts b/src/__test__/projections/getProjectionStatistics.deprecated.test.ts similarity index 100% rename from src/__test__/projections/getProjectionStatistics.test.ts rename to src/__test__/projections/getProjectionStatistics.deprecated.test.ts diff --git a/src/__test__/projections/getProjectionStatus.test.ts b/src/__test__/projections/getProjectionStatus.test.ts new file mode 100644 index 00000000..46dcc68e --- /dev/null +++ b/src/__test__/projections/getProjectionStatus.test.ts @@ -0,0 +1,54 @@ +import { createTestNode } from "@test-utils"; + +import { EventStoreDBClient, UnknownError } from "@eventstore/db-client"; + +describe("getProjectionStatus", () => { + const node = createTestNode(); + let client!: EventStoreDBClient; + + const basicProjection = ` + fromAll() + .when({ + $init: function (state, ev) { + return {}; + } + }); + `; + + const projections = ["projection-1", "projection-2", "projection-3"]; + + beforeAll(async () => { + await node.up(); + client = new EventStoreDBClient( + { endpoint: node.uri }, + { rootCertificate: node.rootCertificate }, + { username: "admin", password: "changeit" } + ); + + for (const name of projections) { + await client.createProjection(name, basicProjection); + } + }); + + afterAll(async () => { + await node.down(); + }); + + describe("gets Projection Status", () => { + test("gets status", async () => { + const REQUESTED_NAME = projections[2]; + + const details = await client.getProjectionStatus(REQUESTED_NAME); + + expect(details).toBeDefined(); + expect(details.name).toBe(REQUESTED_NAME); + }); + + test("non-existant", async () => { + const REQUESTED_NAME = "some-non-existant-projection"; + await expect( + client.getProjectionStatus(REQUESTED_NAME) + ).rejects.toThrowError(UnknownError); // https://github.com/EventStore/EventStore/issues/2732 + }); + }); +}); diff --git a/src/projections/getProjectionStatistics.ts b/src/projections/getProjectionStatus.ts similarity index 67% rename from src/projections/getProjectionStatistics.ts rename to src/projections/getProjectionStatus.ts index c9922590..b07811a8 100644 --- a/src/projections/getProjectionStatistics.ts +++ b/src/projections/getProjectionStatus.ts @@ -10,14 +10,30 @@ import { convertGrpcProjectionDetails, } from "../utils"; -export interface GetProjectionStatisticsOptions extends BaseOptions {} +export interface GetProjectionStatusOptions extends BaseOptions {} + +/** + * @deprecated Renamed to `GetProjectionStatusOptions`. + */ +export type GetProjectionStatisticsOptions = GetProjectionStatusOptions; declare module "../Client" { interface Client { /** - * Gets the result of a projection. + * Gets the current status of a projection. + * @param projectionName The name of the projection. + * @param options Get status options. + */ + getProjectionStatus( + projectionName: string, + options?: GetProjectionStatusOptions + ): Promise; + + /** + * Gets the current status of a projection. * @param projectionName The name of the projection. - * @param options Get state options. + * @param options Get statistics options. + * @deprecated Renamed to `getProjectionStatus`. */ getProjectionStatistics( projectionName: string, @@ -26,10 +42,10 @@ declare module "../Client" { } } -Client.prototype.getProjectionStatistics = async function ( +Client.prototype.getProjectionStatus = async function ( this: Client, projectionName: string, - baseOptions: GetProjectionStatisticsOptions = {} + baseOptions: GetProjectionStatusOptions = {} ): Promise { const req = new StatisticsReq(); const options = new StatisticsReq.Options(); @@ -67,3 +83,5 @@ Client.prototype.getProjectionStatistics = async function ( } ); }; + +Client.prototype.getProjectionStatistics = Client.prototype.getProjectionStatus; diff --git a/src/projections/index.ts b/src/projections/index.ts index ef9db88a..12bd01f0 100644 --- a/src/projections/index.ts +++ b/src/projections/index.ts @@ -4,7 +4,7 @@ export * from "./disableProjection"; export * from "./enableProjection"; export * from "./getProjectionResult"; export * from "./getProjectionState"; -export * from "./getProjectionStatistics"; +export * from "./getProjectionStatus"; export * from "./listProjections"; export * from "./resetProjection"; export * from "./restartSubsystem";