Skip to content

Commit

Permalink
Merge pull request #21 from nitrictech/feature/nit-267
Browse files Browse the repository at this point in the history
Update contracts & Remove request id generation
  • Loading branch information
jyecusch authored Apr 9, 2021
2 parents 8b147f9 + ecd170c commit 953e0f9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 66 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"google-protobuf": "3.14.0",
"micro": "^9.3.4",
"path-parser": "^6.1.0",
"tslib": "^2.1.0",
"uuidv4": "6.2.3"
"tslib": "^2.1.0"
},
"license": "UNLICENSED",
"devDependencies": {
Expand Down
46 changes: 4 additions & 42 deletions src/api/event/event.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { EventClient } from "./event";
import { event } from "../../interfaces";
import { EventPublishResponse } from "../../interfaces/event";

// Extract the EventClient
const { EventClient: GrpcEventClient } = event;
Expand Down Expand Up @@ -57,7 +57,9 @@ describe("Event Client Tests", () => {
publishMock = jest
.spyOn(GrpcEventClient.prototype, "publish")
.mockImplementation((request, callback: any) => {
callback(null, new Empty());
const response = new EventPublishResponse();
response.setId(request.getEvent().getId())
callback(null, response);

return null as any;
});
Expand All @@ -84,45 +86,5 @@ describe("Event Client Tests", () => {
expect(publishMock).toBeCalledTimes(1);
});
});

describe("And a id is not provided", () => {
const MOCK_ERROR = {
code: 2,
message: "UNIMPLEMENTED",
};
let publishMock;

beforeAll(() => {
publishMock = jest
.spyOn(GrpcEventClient.prototype, "publish")
.mockImplementation((_, callback: any) => {
callback(null, new Empty());

return null as any;
});
});

afterAll(() => {
jest.resetAllMocks();
});

test("Then EventClient.publish should resolve with a generated UUID v4 requestID", () => {
const client = new EventClient();
expect(
client.publish("test", {
payloadType: "Test Payload",
payload: {
test: "test",
},
})
).resolves.toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i
);
});

test("The Grpc client for EventClient.publish should have been called exactly once", () => {
expect(publishMock).toBeCalledTimes(1);
});
});
});
});
5 changes: 2 additions & 3 deletions src/api/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SERVICE_BIND } from "../../constants";
import { event } from "../../interfaces";
import { Struct } from "google-protobuf/google/protobuf/struct_pb";
import * as grpc from "@grpc/grpc-js";
import { uuid } from "uuidv4";
import type { NitricEvent } from "../../types";

/**
Expand All @@ -20,7 +19,7 @@ export class EventClient {

async publish(
topic: string,
{ id = uuid(), payloadType = "none", payload }: NitricEvent
{ id, payloadType = "none", payload }: NitricEvent
): Promise<string> {
const request = new event.EventPublishRequest();
const evt = new event.NitricEvent();
Expand All @@ -37,7 +36,7 @@ export class EventClient {
if (error) {
reject(error);
} else {
resolve(id);
resolve(response.getId());
}
});
});
Expand Down
18 changes: 0 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,6 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==

"@types/[email protected]":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==

"@types/yargs-parser@*":
version "20.2.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9"
Expand Down Expand Up @@ -5232,11 +5227,6 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

[email protected]:
version "8.3.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==

uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
Expand All @@ -5247,14 +5237,6 @@ uuid@^8.3.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

[email protected]:
version "6.2.3"
resolved "https://registry.yarnpkg.com/uuidv4/-/uuidv4-6.2.3.tgz#b478932d508484fda8a6a964fe2b897cca5eede2"
integrity sha512-4hxGisl76Y6A7nkadg5gMrPGVYVGLmJ3fZHVvmnXsy+8DMA7n7YV/4Y72Fw38CCwpZpyPgOaa/4YxhkCYwyNNQ==
dependencies:
"@types/uuid" "8.3.0"
uuid "8.3.0"

v8-to-istanbul@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.1.0.tgz#5b95cef45c0f83217ec79f8fc7ee1c8b486aee07"
Expand Down

0 comments on commit 953e0f9

Please sign in to comment.