diff --git a/package-lock.json b/package-lock.json index 8f27d8fc..0fb1b9b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "serverless-azure-functions", - "version": "1.0.0-6", + "version": "1.0.0-7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f8d38ce2..7f84b176 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-azure-functions", - "version": "1.0.0-6", + "version": "1.0.0-7", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Azure Functions.", "license": "MIT", "main": "./lib/index.js", diff --git a/src/services/apimService.test.ts b/src/services/apimService.test.ts index 028b8ec4..50131f2d 100644 --- a/src/services/apimService.test.ts +++ b/src/services/apimService.test.ts @@ -19,6 +19,7 @@ import { OperationContract, ApiPolicyCreateOrUpdateResponse, } from "@azure/arm-apimanagement/esm/models"; +import { Utils } from "../shared/utils"; describe("APIM Service", () => { const apimConfig = MockFactory.createTestApimConfig(); @@ -46,7 +47,6 @@ describe("APIM Service", () => { subscriptionId: "ABC123", }; }); - it("is defined", () => { expect(ApimService).toBeDefined(); }); @@ -56,6 +56,16 @@ describe("APIM Service", () => { expect(service).not.toBeNull(); }); + it("when generated, has a shorted region name in the resource name", () => { + // if APIM name is ommited, it should auto-generate one that contains a shortened region name + const apimConfigName = MockFactory.createTestApimConfig(true); + (serverless.service.provider as any).apim = apimConfigName; + + const service = new ApimService(serverless); + const expectedRegionName = Utils.createShortAzureRegionName(service.getRegion()); + expect(apimConfigName.name.includes(expectedRegionName)).toBeTruthy(); + }); + describe("Get service reference", () => { it("returns null when service doesn't exist", async () => { axios.request = jest.fn((requestConfig) => MockFactory.createTestAxiosResponse(requestConfig, apimGetService404, 404)); diff --git a/src/services/apimService.ts b/src/services/apimService.ts index 6126a70c..9257b132 100644 --- a/src/services/apimService.ts +++ b/src/services/apimService.ts @@ -10,6 +10,7 @@ import { } from "@azure/arm-apimanagement/esm/models"; import { Site } from "@azure/arm-appservice/esm/models"; import { Guard } from "../shared/guard"; +import { ApimResource } from "../armTemplates/resources/apim"; /** * APIM Service handles deployment and integration with Azure API Management @@ -28,7 +29,7 @@ export class ApimService extends BaseService { } if (!this.apimConfig.name) { - this.apimConfig.name = `${this.config.provider.prefix}-${this.config.provider.region}-${this.config.provider.stage}-apim` + this.apimConfig.name = ApimResource.getResourceName(this.config); } if (!this.apimConfig.backend) { @@ -325,4 +326,4 @@ export class ApimService extends BaseService { return xml(policy, { indent: "\t" }); } -} \ No newline at end of file +} diff --git a/src/test/mockFactory.ts b/src/test/mockFactory.ts index e453e20b..2d48e2f6 100644 --- a/src/test/mockFactory.ts +++ b/src/test/mockFactory.ts @@ -267,9 +267,9 @@ export class MockFactory { return (asYaml) ? yaml.dump(data) : data; } - public static createTestApimConfig(): ApiManagementConfig { + public static createTestApimConfig(generateName: boolean = false): ApiManagementConfig { return { - name: "test-apim-resource", + name: generateName ? null : "test-apim-resource", api: { name: "test-apim-api1", subscriptionRequired: false,