diff --git a/sdk/eventgrid/eventgrid/rollup.base.config.js b/sdk/eventgrid/eventgrid/rollup.base.config.js index 5e0261bd2ac6..d378e1695dcf 100644 --- a/sdk/eventgrid/eventgrid/rollup.base.config.js +++ b/sdk/eventgrid/eventgrid/rollup.base.config.js @@ -38,7 +38,7 @@ export function nodeConfig(test = false) { if (test) { // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"]; + baseConfig.input = ["dist-esm/test/internal/**/*.spec.js", "dist-esm/test/public/**/*.spec.js"]; baseConfig.plugins.unshift(multiEntry({ exports: false })); // different output file @@ -104,7 +104,7 @@ export function browserConfig(test = false, production = false) { if (test) { // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files - baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/browser/*.spec.js"]; + baseConfig.input = ["dist-esm/test/internal/**/*.spec.js", "dist-esm/test/public/**/*.spec.js"]; baseConfig.plugins.unshift(multiEntry({ exports: false })); baseConfig.output.file = "dist-test/index.browser.js"; diff --git a/sdk/eventgrid/eventgrid/test/cloudEventDistributedTracingEnricherPolicy.spec.ts b/sdk/eventgrid/eventgrid/test/internal/cloudEventDistributedTracingEnricherPolicy.spec.ts similarity index 97% rename from sdk/eventgrid/eventgrid/test/cloudEventDistributedTracingEnricherPolicy.spec.ts rename to sdk/eventgrid/eventgrid/test/internal/cloudEventDistributedTracingEnricherPolicy.spec.ts index b95ed22bdc81..386449c49a76 100644 --- a/sdk/eventgrid/eventgrid/test/cloudEventDistributedTracingEnricherPolicy.spec.ts +++ b/sdk/eventgrid/eventgrid/test/internal/cloudEventDistributedTracingEnricherPolicy.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; -import { cloudEventDistributedTracingEnricherPolicy } from "../src/cloudEventDistrubtedTracingEnricherPolicy"; +import { cloudEventDistributedTracingEnricherPolicy } from "../../src/cloudEventDistrubtedTracingEnricherPolicy"; import { PipelineRequest, PipelineResponse, diff --git a/sdk/eventgrid/eventgrid/test/internal/convertToWireModel.spec.ts b/sdk/eventgrid/eventgrid/test/internal/convertToWireModel.spec.ts new file mode 100644 index 000000000000..b1278d358345 --- /dev/null +++ b/sdk/eventgrid/eventgrid/test/internal/convertToWireModel.spec.ts @@ -0,0 +1,173 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +import { assert } from "chai"; + +import { + convertEventGridEventToModelType, + convertCloudEventToModelType +} from "../../src/eventGridClient"; + +describe("convertEventGridEventToModelType", function() { + it("sets a default ID if one is not provided", () => { + const convertedEvent = convertEventGridEventToModelType({ + dataVersion: "1.0", + eventType: "Azure.Sdk.TestEvent", + subject: "Test Event", + data: { hello: "world " } + }); + + assert.isDefined(convertedEvent.id); + }); + + it("sets a default event time if one is not provided", () => { + const convertedEvent = convertEventGridEventToModelType({ + dataVersion: "1.0", + eventType: "Azure.Sdk.TestEvent", + subject: "Test Event", + data: { hello: "world " } + }); + + assert.isDefined(convertedEvent.eventTime); + }); + + it("does not change set values", () => { + const time = new Date(); + const id = "272871ba-2496-4750-9a90-bedd1ea10191"; + + const convertedEvent = convertEventGridEventToModelType({ + id: id, + eventTime: time, + dataVersion: "1.0", + eventType: "Azure.Sdk.TestEvent", + subject: "Test Event", + data: { hello: "world " } + }); + + assert.strictEqual(convertedEvent.id, id); + assert.strictEqual(convertedEvent.eventTime, time); + }); +}); + +describe("convertCloudEventToModelType", function() { + it("sets a default ID if one is not provided", () => { + const convertedEvent = convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent" + }); + + assert.isDefined(convertedEvent.id); + }); + + it("sets a default event time if one is not provided", () => { + const convertedEvent = convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent" + }); + + assert.isDefined(convertedEvent.time); + }); + + it("does not change set values", () => { + const time = new Date(); + const id = "272871ba-2496-4750-9a90-bedd1ea10191"; + + const convertedEvent = convertCloudEventToModelType({ + id: id, + time: time, + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent" + }); + + assert.strictEqual(convertedEvent.id, id); + assert.strictEqual(convertedEvent.time, time); + }); + + it("promotes extension attributes", () => { + const traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; + const tracestate = + "rojo=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01,congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4"; + + const convertedEvent = convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + extensionAttributes: { + traceparent, + tracestate + } + }); + + // When converted to a model type to send over the wire, the extension attributes are promoted to be + // properties on the envelope itself. + assert.equal(convertedEvent["traceparent"], traceparent); + assert.equal(convertedEvent["tracestate"], tracestate); + }); + + it("base64 encodes binary data", () => { + const binaryData = new Uint8Array(10); + for (let i = 0; i < binaryData.length; i++) { + binaryData[i] = i; + } + + const convertedEvent = convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + data: binaryData, + datacontenttype: "application/binary" + }); + + assert.isUndefined(convertedEvent.data); + assert.strictEqual(convertedEvent.dataBase64, binaryData); + }); + + it("fails if data content type is missing for binary data", () => { + const binaryData = new Uint8Array(10); + for (let i = 0; i < binaryData.length; i++) { + binaryData[i] = i; + } + + assert.throws(() => { + convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + data: binaryData + }); + }, /data content type/); + }); + + it("fails if extenion attributes are invalid", () => { + const binaryData = new Uint8Array(10); + for (let i = 0; i < binaryData.length; i++) { + binaryData[i] = i; + } + + assert.throws(() => { + convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + extensionAttributes: { + source: "this-is-not-allowed" + } + }); + }, /invalid extension attribute name: source/); + + assert.throws(() => { + convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + extensionAttributes: { + MiXedCasE: "this-is-not-allowed" + } + }); + }, /invalid extension attribute name: MiXedCasE/); + + assert.throws(() => { + convertCloudEventToModelType({ + source: "/azure/sdk/tests", + type: "Azure.Sdk.TestEvent", + extensionAttributes: { + data_base64: "this-is-not-allowed" + } + }); + }, /invalid extension attribute name: data_base64/); + }); +}); diff --git a/sdk/eventgrid/eventgrid/test/util.spec.ts b/sdk/eventgrid/eventgrid/test/internal/util.spec.ts similarity index 92% rename from sdk/eventgrid/eventgrid/test/util.spec.ts rename to sdk/eventgrid/eventgrid/test/internal/util.spec.ts index fe0605149c86..bd9306378a7f 100644 --- a/sdk/eventgrid/eventgrid/test/util.spec.ts +++ b/sdk/eventgrid/eventgrid/test/internal/util.spec.ts @@ -3,7 +3,7 @@ import { assert } from "chai"; -import { dateToServiceTimeString } from "../src/util"; +import { dateToServiceTimeString } from "../../src/util"; describe("util", function() { describe("dateToServiceTimeString", () => { diff --git a/sdk/eventgrid/eventgrid/test/consumer.spec.ts b/sdk/eventgrid/eventgrid/test/public/consumer.spec.ts similarity index 99% rename from sdk/eventgrid/eventgrid/test/consumer.spec.ts rename to sdk/eventgrid/eventgrid/test/public/consumer.spec.ts index ddc4bf3e528b..968aa2731a7c 100644 --- a/sdk/eventgrid/eventgrid/test/consumer.spec.ts +++ b/sdk/eventgrid/eventgrid/test/public/consumer.spec.ts @@ -4,7 +4,7 @@ import { assert, use as chaiUse } from "chai"; import chaiPromises from "chai-as-promised"; -import { EventGridDeserializer } from "../src"; +import { EventGridDeserializer } from "../../src"; import * as testData from "./utils/testData"; chaiUse(chaiPromises); diff --git a/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts b/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts similarity index 69% rename from sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts rename to sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts index 7b9c98393f4b..5dda659e3ed7 100644 --- a/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts +++ b/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts @@ -9,12 +9,8 @@ import { createRecordedClient, testEnv } from "./utils/recordedClient"; import { TestTracer, setTracer } from "@azure/core-tracing"; -import { AzureKeyCredential, EventGridPublisherClient } from "../src/index"; +import { AzureKeyCredential, EventGridPublisherClient } from "../../src"; -import { - convertEventGridEventToModelType, - convertCloudEventToModelType -} from "../src/eventGridClient"; import { FullOperationResponse } from "@azure/core-client"; import { RestError } from "@azure/core-rest-pipeline"; @@ -403,171 +399,6 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { }); }); -describe("convertEventGridEventToModelType", function() { - it("sets a default ID if one is not provided", () => { - const convertedEvent = convertEventGridEventToModelType({ - dataVersion: "1.0", - eventType: "Azure.Sdk.TestEvent", - subject: "Test Event", - data: { hello: "world " } - }); - - assert.isDefined(convertedEvent.id); - }); - - it("sets a default event time if one is not provided", () => { - const convertedEvent = convertEventGridEventToModelType({ - dataVersion: "1.0", - eventType: "Azure.Sdk.TestEvent", - subject: "Test Event", - data: { hello: "world " } - }); - - assert.isDefined(convertedEvent.eventTime); - }); - - it("does not change set values", () => { - const time = new Date(); - const id = "272871ba-2496-4750-9a90-bedd1ea10191"; - - const convertedEvent = convertEventGridEventToModelType({ - id: id, - eventTime: time, - dataVersion: "1.0", - eventType: "Azure.Sdk.TestEvent", - subject: "Test Event", - data: { hello: "world " } - }); - - assert.strictEqual(convertedEvent.id, id); - assert.strictEqual(convertedEvent.eventTime, time); - }); -}); - -describe("convertCloudEventToModelType", function() { - it("sets a default ID if one is not provided", () => { - const convertedEvent = convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent" - }); - - assert.isDefined(convertedEvent.id); - }); - - it("sets a default event time if one is not provided", () => { - const convertedEvent = convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent" - }); - - assert.isDefined(convertedEvent.time); - }); - - it("does not change set values", () => { - const time = new Date(); - const id = "272871ba-2496-4750-9a90-bedd1ea10191"; - - const convertedEvent = convertCloudEventToModelType({ - id: id, - time: time, - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent" - }); - - assert.strictEqual(convertedEvent.id, id); - assert.strictEqual(convertedEvent.time, time); - }); - - it("promotes extension attributes", () => { - const traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; - const tracestate = - "rojo=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01,congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4"; - - const convertedEvent = convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - extensionAttributes: { - traceparent, - tracestate - } - }); - - // When converted to a model type to send over the wire, the extension attributes are promoted to be - // properties on the envelope itself. - assert.equal(convertedEvent["traceparent"], traceparent); - assert.equal(convertedEvent["tracestate"], tracestate); - }); - - it("base64 encodes binary data", () => { - const binaryData = new Uint8Array(10); - for (let i = 0; i < binaryData.length; i++) { - binaryData[i] = i; - } - - const convertedEvent = convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - data: binaryData, - datacontenttype: "application/binary" - }); - - assert.isUndefined(convertedEvent.data); - assert.strictEqual(convertedEvent.dataBase64, binaryData); - }); - - it("fails if data content type is missing for binary data", () => { - const binaryData = new Uint8Array(10); - for (let i = 0; i < binaryData.length; i++) { - binaryData[i] = i; - } - - assert.throws(() => { - convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - data: binaryData - }); - }, /data content type/); - }); - - it("fails if extenion attributes are invalid", () => { - const binaryData = new Uint8Array(10); - for (let i = 0; i < binaryData.length; i++) { - binaryData[i] = i; - } - - assert.throws(() => { - convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - extensionAttributes: { - source: "this-is-not-allowed" - } - }); - }, /invalid extension attribute name: source/); - - assert.throws(() => { - convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - extensionAttributes: { - MiXedCasE: "this-is-not-allowed" - } - }); - }, /invalid extension attribute name: MiXedCasE/); - - assert.throws(() => { - convertCloudEventToModelType({ - source: "/azure/sdk/tests", - type: "Azure.Sdk.TestEvent", - extensionAttributes: { - data_base64: "this-is-not-allowed" - } - }); - }, /invalid extension attribute name: data_base64/); - }); -}); - function removeApiEventsSuffix(endpoint: string): string { const suffix = "/api/events"; diff --git a/sdk/eventgrid/eventgrid/test/generateSharedAccessSignature.spec.ts b/sdk/eventgrid/eventgrid/test/public/generateSharedAccessSignature.spec.ts similarity index 98% rename from sdk/eventgrid/eventgrid/test/generateSharedAccessSignature.spec.ts rename to sdk/eventgrid/eventgrid/test/public/generateSharedAccessSignature.spec.ts index 85821849fb6a..8013a7ac9380 100644 --- a/sdk/eventgrid/eventgrid/test/generateSharedAccessSignature.spec.ts +++ b/sdk/eventgrid/eventgrid/test/public/generateSharedAccessSignature.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; -import { AzureKeyCredential, generateSharedAccessSignature } from "../src/index"; +import { AzureKeyCredential, generateSharedAccessSignature } from "../../src"; describe("generateSharedAccessSignature", function() { it("generates the correct signiture", async () => { diff --git a/sdk/eventgrid/eventgrid/test/utils/recordedClient.ts b/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts similarity index 96% rename from sdk/eventgrid/eventgrid/test/utils/recordedClient.ts rename to sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts index 609ef4fb05d5..4b34dddb1abe 100644 --- a/sdk/eventgrid/eventgrid/test/utils/recordedClient.ts +++ b/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts @@ -7,7 +7,7 @@ import * as dotenv from "dotenv"; import { env, Recorder, record, RecorderEnvironmentSetup } from "@azure/test-utils-recorder"; import { isNode } from "./testUtils"; -import { EventGridPublisherClient, InputSchema } from "../../src/index"; +import { EventGridPublisherClient, InputSchema } from "../../../src"; import { KeyCredential } from "@azure/core-auth"; if (isNode) { diff --git a/sdk/eventgrid/eventgrid/test/utils/testData.ts b/sdk/eventgrid/eventgrid/test/public/utils/testData.ts similarity index 100% rename from sdk/eventgrid/eventgrid/test/utils/testData.ts rename to sdk/eventgrid/eventgrid/test/public/utils/testData.ts diff --git a/sdk/eventgrid/eventgrid/test/utils/testUtils.ts b/sdk/eventgrid/eventgrid/test/public/utils/testUtils.ts similarity index 100% rename from sdk/eventgrid/eventgrid/test/utils/testUtils.ts rename to sdk/eventgrid/eventgrid/test/public/utils/testUtils.ts diff --git a/sdk/eventgrid/eventgrid/tests.yml b/sdk/eventgrid/eventgrid/tests.yml index eef5a6b48495..5c802ace4c1c 100644 --- a/sdk/eventgrid/eventgrid/tests.yml +++ b/sdk/eventgrid/eventgrid/tests.yml @@ -5,5 +5,3 @@ stages: parameters: PackageName: "@azure/eventgrid" ServiceDirectory: eventgrid - MatrixFilters: - - DependencyVersion=^$