Repository: serverless/serverless-azure-functions
Pull request #155 (2019-05-31 16:49:30)

test: Unit tests for Azure Index
Resolves [AB#18742]


Patch:
diff --git a/package-lock.json b/package-lock.json
index 679c8e2..9795f4d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3490,11 +3490,13 @@
         },
         "balanced-match": {
           "version": "1.0.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
+          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -3507,15 +3509,18 @@
         },
         "code-point-at": {
           "version": "1.1.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "concat-map": {
           "version": "0.0.1",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "console-control-strings": {
           "version": "1.1.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -3618,7 +3623,8 @@
         },
         "inherits": {
           "version": "2.0.3",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "ini": {
           "version": "1.3.5",
@@ -3628,6 +3634,7 @@
         "is-fullwidth-code-point": {
           "version": "1.0.0",
           "bundled": true,
+          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -3640,17 +3647,20 @@
         "minimatch": {
           "version": "3.0.4",
           "bundled": true,
+          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
         },
         "minimist": {
           "version": "0.0.8",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "minipass": {
           "version": "2.3.5",
           "bundled": true,
+          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.2",
             "yallist": "^3.0.0"
@@ -3667,6 +3677,7 @@
         "mkdirp": {
           "version": "0.5.1",
           "bundled": true,
+          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
@@ -3739,7 +3750,8 @@
         },
         "number-is-nan": {
           "version": "1.0.1",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -3749,6 +3761,7 @@
         "once": {
           "version": "1.4.0",
           "bundled": true,
+          "optional": true,
           "requires": {
             "wrappy": "1"
           }
@@ -3854,6 +3867,7 @@
         "string-width": {
           "version": "1.0.2",
           "bundled": true,
+          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
diff --git a/src/index.ts b/src/index.ts
index 05e9c21..d455073 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -17,7 +17,7 @@ import { AzureApimFunctionPlugin } from "./plugins/apim/apimFunctionPlugin";
 import { AzureFuncPlugin } from "./plugins/func/azureFunc";
 
 
-export class AzureIndex {
+export default class AzureIndex {
   public constructor(private serverless: Serverless, private options) {
     this.serverless.setProvider(AzureProvider.getProviderName(), new AzureProvider(serverless) as any);
 


Test patch:
diff --git a/src/index.test.ts b/src/index.test.ts
new file mode 100644
index 0000000..0547521
--- /dev/null
+++ b/src/index.test.ts
@@ -0,0 +1,31 @@
+import AzureIndex from "./index";
+import { MockFactory } from "./test/mockFactory"
+import { AzureInvoke } from "./plugins/invoke/azureInvoke";
+import { AzureLogs } from "./plugins/logs/azureLogs";
+import { AzureRemove } from "./plugins/remove/azureRemove";
+import { AzurePackage } from "./plugins/package/azurePackage";
+import { AzureDeployPlugin } from "./plugins/deploy/azureDeployPlugin";
+import { AzureLoginPlugin } from "./plugins/login/loginPlugin";
+import { AzureApimServicePlugin } from "./plugins/apim/apimServicePlugin";
+import { AzureApimFunctionPlugin } from "./plugins/apim/apimFunctionPlugin";
+import AzureProvider from "./provider/azureProvider";
+
+describe("Azure Index", () => {
+  it("contains all registered plugins", () => {
+    const sls = MockFactory.createTestServerless();
+    const options = MockFactory.createTestServerlessOptions();
+    const index = new AzureIndex(sls, options);
+    sls.setProvider = jest.fn();
+
+    expect(sls.setProvider).toBeCalledWith("azure", new AzureProvider(sls));
+
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzurePackage);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureInvoke);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureLogs);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureRemove);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureLoginPlugin);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureDeployPlugin);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureApimServicePlugin);
+    expect(sls.pluginManager.addPlugin).toBeCalledWith(AzureApimFunctionPlugin);
+  });
+});
\ No newline at end of file