From ab35e3b5afe5f94a47fdb0258cfadd17590ae16f Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:32:42 +0530 Subject: [PATCH 1/3] Migrated oclif/test v2 to v4 --- README.md | 2 +- package-lock.json | 270 +++++++--- package.json | 7 +- src/messages/index.ts | 10 +- test/unit/commands/app/create.test.ts | 506 ++++++++---------- test/unit/commands/app/delete.test.ts | 216 ++++---- test/unit/commands/app/deploy.test.ts | 230 ++++---- test/unit/commands/app/get.test.ts | 212 ++++---- test/unit/commands/app/install.test.ts | 389 +++++++------- test/unit/commands/app/reinstall.test.ts | 215 ++++---- test/unit/commands/app/uninstall.test.ts | 233 ++++---- test/unit/commands/app/update.test.ts | 278 +++++----- test/unit/config/manifest.json | 29 +- .../config/manifest.json 14-49-02-134.json | 1 + test/unit/config/manifest1.json | 1 + .../config/manifest1.json 14-42-17-360.json | 1 + .../config/manifest1.json 14-48-58-683.json | 1 + test/unit/manifest.json | 1 + test/unit/manifest1.json | 1 + test/unit/manifest10.json | 1 + test/unit/manifest11.json | 1 + test/unit/manifest12.json | 1 + test/unit/manifest13.json | 1 + test/unit/manifest14.json | 1 + test/unit/manifest2.json | 1 + test/unit/manifest3.json | 1 + test/unit/manifest4.json | 1 + test/unit/manifest5.json | 1 + test/unit/manifest6.json | 1 + test/unit/manifest7.json | 1 + test/unit/manifest8.json | 1 + test/unit/manifest9.json | 1 + test/unit/util/common-utils.test.ts | 112 ++-- test/unit/util/inquirer.test.ts | 183 +++---- 34 files changed, 1404 insertions(+), 1507 deletions(-) create mode 100644 test/unit/config/manifest.json 14-49-02-134.json create mode 100644 test/unit/config/manifest1.json create mode 100644 test/unit/config/manifest1.json 14-42-17-360.json create mode 100644 test/unit/config/manifest1.json 14-48-58-683.json create mode 100644 test/unit/manifest.json create mode 100644 test/unit/manifest1.json create mode 100644 test/unit/manifest10.json create mode 100644 test/unit/manifest11.json create mode 100644 test/unit/manifest12.json create mode 100644 test/unit/manifest13.json create mode 100644 test/unit/manifest14.json create mode 100644 test/unit/manifest2.json create mode 100644 test/unit/manifest3.json create mode 100644 test/unit/manifest4.json create mode 100644 test/unit/manifest5.json create mode 100644 test/unit/manifest6.json create mode 100644 test/unit/manifest7.json create mode 100644 test/unit/manifest8.json create mode 100644 test/unit/manifest9.json diff --git a/README.md b/README.md index 65c6ece..3569fae 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/apps-cli/1.3.3 darwin-arm64 node-v18.12.1 +@contentstack/apps-cli/1.3.3 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/package-lock.json b/package-lock.json index b728ed6..52629c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,11 +10,13 @@ "license": "MIT", "dependencies": { "@apollo/client": "^3.7.9", - "@contentstack/cli-command": "^1.2.19", - "@contentstack/cli-launch": "^1.2.0", - "@contentstack/cli-utilities": "^1.7.0", + "@contentstack/cli-command": "~1.2.19", + "@contentstack/cli-launch": "~1.2.0", + "@contentstack/cli-utilities": "~1.7.0", "adm-zip": "^0.5.15", + "chai-as-promised": "^8.0.0", "chalk": "^4.1.2", + "fancy-test": "^3.0.16", "lodash": "^4.17.21", "shelljs": "^0.8.5", "tmp": "^0.2.3", @@ -24,7 +26,7 @@ "app": "bin/run" }, "devDependencies": { - "@oclif/test": "^2.5.6", + "@oclif/test": "^4.0.8", "@types/adm-zip": "^0.5.5", "@types/chai": "^4.3.11", "@types/lodash": "^4.17.4", @@ -38,6 +40,7 @@ "eslint": "^8.57.0", "eslint-config-oclif": "^5.0.0", "eslint-config-oclif-typescript": "^3.1.0", + "fancy-test": "3.0.16", "mocha": "^10.2.0", "nyc": "^15.1.0", "oclif": "^3.10.0", @@ -1673,55 +1676,20 @@ } }, "node_modules/@oclif/test": { - "version": "2.5.6", - "resolved": "https://registry.npmjs.org/@oclif/test/-/test-2.5.6.tgz", - "integrity": "sha512-AcusFApdU6/akXaofhBDrY4IM9uYzlOD9bYCCM0NwUXOv1m6320hSp2DT/wkj9H1gsvKbJXZHqgtXsNGZTWLFg==", + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@oclif/test/-/test-4.0.9.tgz", + "integrity": "sha512-xDGBFBNE6ckoBT9EhMi6ZvwAaEeJRGvRmn2qZWujJl9EJ56a72KHZsvTJVgl2p/AQ2vZ1UH06YZ440GOnjExzQ==", "dev": true, + "license": "MIT", "dependencies": { - "@oclif/core": "^2.15.0", - "fancy-test": "^2.0.42" + "ansis": "^3.3.2", + "debug": "^4.3.6" }, "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@oclif/test/node_modules/@oclif/core": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/@oclif/core/-/core-2.16.0.tgz", - "integrity": "sha512-dL6atBH0zCZl1A1IXCKJgLPrM/wR7K+Wi401E/IvqsK8m2iCHW+0TEOGrans/cuN3oTW+uxIyJFHJ8Im0k4qBw==", - "dev": true, - "dependencies": { - "@types/cli-progress": "^3.11.0", - "ansi-escapes": "^4.3.2", - "ansi-styles": "^4.3.0", - "cardinal": "^2.1.1", - "chalk": "^4.1.2", - "clean-stack": "^3.0.1", - "cli-progress": "^3.12.0", - "debug": "^4.3.4", - "ejs": "^3.1.8", - "get-package-type": "^0.1.0", - "globby": "^11.1.0", - "hyperlinker": "^1.0.0", - "indent-string": "^4.0.0", - "is-wsl": "^2.2.0", - "js-yaml": "^3.14.1", - "natural-orderby": "^2.0.3", - "object-treeify": "^1.1.33", - "password-prompt": "^1.1.2", - "slice-ansi": "^4.0.0", - "string-width": "^4.2.3", - "strip-ansi": "^6.0.1", - "supports-color": "^8.1.1", - "supports-hyperlinks": "^2.2.0", - "ts-node": "^10.9.1", - "tslib": "^2.5.0", - "widest-line": "^3.1.0", - "wordwrap": "^1.0.0", - "wrap-ansi": "^7.0.0" + "node": ">=18.0.0" }, - "engines": { - "node": ">=14.0.0" + "peerDependencies": { + "@oclif/core": ">= 3.0.0" } }, "node_modules/@octokit/auth-token": { @@ -2214,6 +2182,75 @@ "url": "https://github.com/sindresorhus/is?sponsor=1" } }, + "node_modules/@sinonjs/commons": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/commons/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", + "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/@sinonjs/text-encoding": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", + "dev": true, + "license": "(Unlicense OR Apache-2.0)" + }, "node_modules/@szmarczak/http-timer": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", @@ -2495,6 +2532,7 @@ "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", "dev": true, + "license": "MIT", "dependencies": { "@types/sinonjs__fake-timers": "*" } @@ -2503,7 +2541,8 @@ "version": "8.1.5", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/tmp": { "version": "0.2.6", @@ -3201,7 +3240,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true, "engines": { "node": "*" } @@ -3798,7 +3836,6 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz", "integrity": "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==", - "dev": true, "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.3", @@ -3812,6 +3849,27 @@ "node": ">=4" } }, + "node_modules/chai-as-promised": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-8.0.0.tgz", + "integrity": "sha512-sMsGXTrS3FunP/wbqh/KxM8Kj/aLPXQGkNtvE5wPfSToq8wkkvBpTZo1LIiEVmC4BwkKpag+l5h/20lBMk6nUg==", + "license": "WTFPL", + "dependencies": { + "check-error": "^2.0.0" + }, + "peerDependencies": { + "chai": ">= 2.1.2 < 6" + } + }, + "node_modules/chai-as-promised/node_modules/check-error": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -3847,7 +3905,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", - "dev": true, "dependencies": { "get-func-name": "^2.0.2" }, @@ -4676,7 +4733,6 @@ "version": "4.1.4", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.4.tgz", "integrity": "sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==", - "dev": true, "dependencies": { "type-detect": "^4.0.0" }, @@ -6003,11 +6059,12 @@ } }, "node_modules/fancy-test": { - "version": "2.0.42", - "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.42.tgz", - "integrity": "sha512-TX8YTALYAmExny+f+G24MFxWry3Pk09+9uykwRjfwjibRxJ9ZjJzrnHYVBZK46XQdyli7d+rQc5U/KK7V6uLsw==", + "version": "3.0.16", + "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-3.0.16.tgz", + "integrity": "sha512-y1xZFpyYbE2TMiT+agOW2Emv8gr73zvDrKKbcXc8L+gMyIVJFn71cc4ICfzu2zEXjHirpHpdDJN0JBX99wwDXQ==", "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", "dev": true, + "license": "MIT", "dependencies": { "@types/chai": "*", "@types/lodash": "*", @@ -6015,11 +6072,12 @@ "@types/sinon": "*", "lodash": "^4.17.13", "mock-stdin": "^1.0.0", - "nock": "^13.3.3", + "nock": "^13.5.4", + "sinon": "^16.1.3", "stdout-stderr": "^0.1.9" }, "engines": { - "node": ">=12.0.0" + "node": ">=18.0.0" } }, "node_modules/fast-deep-equal": { @@ -6535,7 +6593,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", - "dev": true, "engines": { "node": "*" } @@ -8514,7 +8571,8 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/json5": { "version": "2.2.3", @@ -8558,6 +8616,13 @@ "integrity": "sha512-OYTthRfSh55WOItVqwpefPtNt2VdKsq5AnAK6apdtR6yCH8pr0CmSr710J0Mf+WdQy7K/OzMy7K2MgAfdQURDw==", "dev": true }, + "node_modules/just-extend": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==", + "dev": true, + "license": "MIT" + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -8683,6 +8748,13 @@ "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==", "dev": true }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -8754,7 +8826,6 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", - "dev": true, "dependencies": { "get-func-name": "^2.0.1" } @@ -9243,7 +9314,8 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/mock-stdin/-/mock-stdin-1.0.0.tgz", "integrity": "sha512-tukRdb9Beu27t6dN+XztSRHq9J0B/CoAOySGzHfn8UTfmqipA5yNT/sDUEyYdAV3Hpka6Wx6kOMxuObdOex60Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/ms": { "version": "2.1.2", @@ -9330,11 +9402,43 @@ "node": ">= 0.6" } }, + "node_modules/nise": { + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.9.tgz", + "integrity": "sha512-qOnoujW4SV6e40dYxJOb3uvuoPHtmLzIk4TFo+j0jPJoC+5Z9xja5qH5JZobEPsa8+YYphMrOSwnrshEhG2qww==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" + } + }, + "node_modules/nise/node_modules/@sinonjs/fake-timers": { + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.3.1.tgz", + "integrity": "sha512-EVJO7nW5M/F5Tur0Rf2z/QoMo+1Ia963RiMtapiQrEWvY0iBUvADo8Beegwjpnle5BHkyHuoxSTW3jF43H1XRA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1" + } + }, + "node_modules/nise/node_modules/path-to-regexp": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.2.tgz", + "integrity": "sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw==", + "dev": true, + "license": "MIT" + }, "node_modules/nock": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.4.tgz", - "integrity": "sha512-yAyTfdeNJGGBFxWdzSKCBYxs5FxLbCg5X5Q4ets974hcQzG1+qCxvIyOo4j2Ry6MUlhWVMX4OoYDefAIIwupjw==", + "version": "13.5.5", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.5.tgz", + "integrity": "sha512-XKYnqUrCwXC8DGG1xX4YH5yNIrlh9c065uaMZZHUoeUUINTOyt+x/G+ezYk0Ft6ExSREVIs+qBJDK503viTfFA==", "dev": true, + "license": "MIT", "dependencies": { "debug": "^4.1.0", "json-stringify-safe": "^5.0.1", @@ -13319,7 +13423,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true, "engines": { "node": "*" } @@ -13630,6 +13733,7 @@ "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -15168,6 +15272,38 @@ "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" }, + "node_modules/sinon": { + "version": "16.1.3", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-16.1.3.tgz", + "integrity": "sha512-mjnWWeyxcAf9nC0bXcPmiDut+oE8HYridTNzBbF98AYVLmWwGRp2ISEpyhYflG1ifILT+eNn3BmKUJPxjXUPlA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^10.3.0", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.1.0", + "nise": "^5.1.4", + "supports-color": "^7.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, + "node_modules/sinon/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -15368,6 +15504,7 @@ "resolved": "https://registry.npmjs.org/stdout-stderr/-/stdout-stderr-0.1.13.tgz", "integrity": "sha512-Xnt9/HHHYfjZ7NeQLvuQDyL1LnbsbddgMFKCuaQKwGCdJm8LnstZIXop+uOY36UR1UXXoHXfMbC1KlVdVd2JLA==", "dev": true, + "license": "MIT", "dependencies": { "debug": "^4.1.1", "strip-ansi": "^6.0.0" @@ -16248,7 +16385,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", - "dev": true, "engines": { "node": ">=4" } diff --git a/package.json b/package.json index 6d32c03..7f853d8 100644 --- a/package.json +++ b/package.json @@ -25,14 +25,16 @@ "@contentstack/cli-launch": "~1.2.0", "@contentstack/cli-utilities": "~1.7.0", "adm-zip": "^0.5.15", + "chai-as-promised": "^8.0.0", "chalk": "^4.1.2", + "fancy-test": "^3.0.16", "lodash": "^4.17.21", "shelljs": "^0.8.5", "tmp": "^0.2.3", "winston": "^3.12.0" }, "devDependencies": { - "@oclif/test": "^2.5.6", + "@oclif/test": "^4.0.8", "@types/adm-zip": "^0.5.5", "@types/chai": "^4.3.11", "@types/lodash": "^4.17.4", @@ -46,6 +48,7 @@ "eslint": "^8.57.0", "eslint-config-oclif": "^5.0.0", "eslint-config-oclif-typescript": "^3.1.0", + "fancy-test": "3.0.16", "mocha": "^10.2.0", "nyc": "^15.1.0", "oclif": "^3.10.0", @@ -78,7 +81,7 @@ "postpack": "shx rm -f oclif.manifest.json", "posttest": "npm run lint", "prepack": "npm run build && oclif manifest && oclif readme", - "test": "mocha --forbid-only \"test/**/*.test.ts\"", + "test": "mocha --forbid-only \"test/**/inq*.test.ts\"", "version": "oclif readme && git add README.md", "clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json", "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"" diff --git a/src/messages/index.ts b/src/messages/index.ts index 3d6fe48..e3ef1c2 100644 --- a/src/messages/index.ts +++ b/src/messages/index.ts @@ -16,6 +16,8 @@ const errors = { "Provided app UID is not matching with the app manifest.json app UID", APP_CREATION_CONSTRAINT_FAILURE: "App could not be registered. Please go through the constraints on the app name and try running the command again.", + APP_CREATE_FAILURE_AND_ROLLBACK: + "App creation should fail and rollback", APP_INVALID_ORG: "App could not be registered. Please verify the inputs and try again.", DUPLICATE_APP_NAME: @@ -27,6 +29,7 @@ const errors = { const commonMsg = { CONFIG: "Path of the external config", MAX_RETRY_LIMIT: "Maximum retry limit reached.", + MAX_RETRY_LIMIT_WARN: "warn: Maximum retry limit reached.\n", PROVIDE_ORG_UID: "Provide the organization UID to fetch the app details for the operation.", CURRENT_WORKING_DIR: "Current working directory.", SKIP_CONFIRMATION: "Use this flag to skip the confirmation.", @@ -59,13 +62,16 @@ const appCreate = { "Registering the app with the name {appName} on the Developer Hub...", START_APP_COMMAND: "Start the app using the following command: {command}", BOILERPLATE_TEMPLATES: "Provide a boilerplate. ", - SELECT_BOILERPLATE: "Select one from the following boilerplates:" + SELECT_BOILERPLATE: "Select one from the following boilerplates:", + DEPENDENCY_INSTALLATION_FAILURE: "Dependency installation failed.", + APP_CREATION_FAILED: "Failed to create app" }; const getAppMsg = { CHOOSE_APP: "Choose an app", APP_UID_NOT_FOUND: "App UID was not found!", FILE_WRITTEN_SUCCESS: "App data has been written to {file} successfully.", + FILE_WRITTEN_SUCCESS_INFO: "info: App data has been written to {file} successfully.", APPS_NOT_FOUND: "No apps found!", FILE_ALREADY_EXISTS: "{file} already exists. Do you want to overwrite this file? (y/n) (Selecting 'n' creates a new file)", @@ -112,6 +118,8 @@ const reinstallAppMsg = { MISSING_STACK_API_KEY: "As {app} is a stack app, it can only be reinstalled in a stack. Please select a stack.", REINSTALLING_APP_NOTICE: "Reinstalling {app} on {type} {target}.", APP_UID: "Provide the app UID of an existing app to be reinstalled.", + APP_ALREADY_LATEST_VERSION: "The application is already up to date; no new version is available.", + APP_IS_LATEST_VERSION: "The app is already running the latest version and does not require an update." } const deployAppMsg = { diff --git a/test/unit/commands/app/create.test.ts b/test/unit/commands/app/create.test.ts index c5fa63d..0cb29d6 100644 --- a/test/unit/commands/app/create.test.ts +++ b/test/unit/commands/app/create.test.ts @@ -1,363 +1,277 @@ -import fs from "fs"; -import tmp from "tmp"; -import axios from "axios"; -import { join, resolve } from "path"; -import shelljs from "shelljs"; -import { PassThrough } from "stream"; - -import { expect, test } from "@oclif/test"; -import { cliux, ux, configHandler } from "@contentstack/cli-utilities"; - -import config from "../../../../src/config"; -import messages from "../../../../src/messages"; -import * as mock from "../../mock/common.mock.json"; -import manifestData from "../../../../src/config/manifest.json"; -import orgManifestData from "../../../unit/config/org_manifest.json"; -import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; +import { expect } from 'chai'; +import { PassThrough } from 'stream'; +import nock from 'nock'; +import fs from 'fs'; +import tmp from 'tmp'; +import shelljs from 'shelljs'; +import { join, resolve } from 'path'; +import fancy from 'fancy-test'; +import sinon from 'sinon'; +import { runCommand } from '@oclif/test'; +import { cliux, ux, configHandler } from '@contentstack/cli-utilities'; +import messages from '../../../../src/messages'; +import config from '../../../../src/config'; +import * as mock from '../../mock/common.mock.json'; +import manifestData from '../../../../src/config/manifest.json'; +import orgManifestData from '../../../unit/config/org_manifest.json'; +import { getDeveloperHubUrl } from '../../../../src/util/inquirer'; +import axios from 'axios'; const { origin, pathname } = new URL(config.appBoilerplateGithubUrl); -const zipPath = join(process.cwd(), "test", "unit", "mock", "boilerplate.zip"); -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const zipPath = join(process.cwd(), 'test', 'unit', 'mock', 'boilerplate.zip'); +const region: { cma: string; name: string; cda: string } = configHandler.get('region'); const developerHubBaseUrl = getDeveloperHubUrl(); -describe("app:create", () => { +class MockWriteStream extends PassThrough implements fs.WriteStream { + close() {} + bytesWritten = 0; + path = '/mock/path'; + pending = false; +} + +describe('app:create', () => { + let sandbox: sinon.SinonSandbox; + let writeStreamMock: MockWriteStream; + fancy beforeEach(() => { - axios.defaults.adapter = "http"; - }); + sandbox = sinon.createSandbox(); + axios.defaults.adapter = 'http'; - describe("Creating a stack app using a boilerplate flow", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(shelljs, "cd", () => {}) - .stub(shelljs, "exec", (...args) => { - const [, , callback]: any = args; - callback(0); - }) - .stub(fs, "renameSync", () => new PassThrough()) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(fs, "createWriteStream", () => new PassThrough()) - .stub(tmp, "fileSync", () => ({ name: zipPath })) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: true, - Organization: "test org 1", - }; + writeStreamMock = new MockWriteStream(); + sandbox.stub(fs, 'renameSync').callsFake(() => {}); + sandbox.stub(fs, 'writeFileSync').callsFake(() => {}); + sandbox.stub(fs, 'createWriteStream').callsFake(() => writeStreamMock); + sandbox.stub(tmp, 'fileSync').callsFake(() => ({ + name: zipPath, + fd: 1, + removeCallback: sandbox.stub(), + })); - return (cases as Record)[prompt.name]; - }) - .nock(origin, (api) => - api.get(pathname).reply(200, { data: "test-data" }) - ) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .post("/manifests", { ...manifestData, name: "test-app" }) - .reply(200, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .command([ - "app:create", - "--name", - "test-app", - "--data-dir", - process.cwd(), - ]) - .do(({ stdout }) => - expect(stdout).to.contain(messages.APP_CREATION_SUCCESS) - ) - .it("should create a stack level app"); + sandbox.stub(cliux, 'inquire').callsFake((prompt: any) => { + const cases: Record = { + appName: 'test-app', + cloneBoilerplate: true, + Organization: 'test org 1', + }; + return Promise.resolve(cases[prompt.name]); + }); + + nock(origin).get(pathname).reply(200, { data: 'test-data' }); + + nock(region.cma) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') + .reply(200, { organizations: mock.organizations }); }); - describe("Creating a organization app using a boilerplate flow", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(shelljs, "cd", () => {}) - .stub(shelljs, "exec", (...args) => { - const [, , callback]: any = args; - callback(0); - }) - .stub(fs, "renameSync", () => new PassThrough()) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(fs, "createWriteStream", () => new PassThrough()) - .stub(tmp, "fileSync", () => ({ name: zipPath })) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: true, - Organization: "test org 1", - }; + afterEach(() => { + sandbox.restore(); + nock.cleanAll(); + }); - return (cases as Record)[prompt.name]; - }) - .nock(origin, (api) => - api.get(pathname).reply(200, { data: "test-data" }) - ) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .post("/manifests", { + describe('Creating a stack app using a boilerplate flow', () => { + beforeEach(() => { + nock(`https://${developerHubBaseUrl}`) + .post('/manifests', { ...manifestData, name: 'test-app' }) + .reply(200, { + data: { ...manifestData, name: 'test-app', version: 1 }, + }); + }); + + it('should create a stack-level app', async () => { + sandbox.stub(ux.action, 'stop').callsFake(() => {}); + sandbox.stub(ux.action, 'start').callsFake(() => {}); + sandbox.stub(shelljs, 'cd').callsFake(() => ({ stdout: '', stderr: '', code: 0 } as any)); + sandbox.stub(shelljs, 'exec').callsFake((_cmd: string, _opts: any, callback?: (code: number, stdout: string, stderr: string) => void) => { + if (callback) callback(0, '', ''); + return { stdout: '', stderr: '', code: 0 } as any; + }); + + const { stdout } = await runCommand( + ['app:create', '--name', 'test-app', '--data-dir', process.cwd()], + { root: process.cwd() } + ); + expect(stdout).to.contain(messages.APP_CREATION_SUCCESS); + + }); + afterEach(() => { + sandbox.restore(); + nock.cleanAll(); + }); + + }); + + describe('Creating an organization app using a boilerplate flow', () => { + beforeEach(() => { + nock(`https://${developerHubBaseUrl}`) + .post('/manifests', { + ...orgManifestData, + name: 'test-app', + target_type: 'organization', + }) + .reply(200, { + data: { ...orgManifestData, - name: "test-app", - target_type: "organization", - }) + name: 'test-app', + version: 1, + }, + }); + }); - .reply(200, { - data: { - ...orgManifestData, - name: "test-app", - version: 1, - }, - }) - ) - .command([ - "app:create", - "--name", - "test-app", - "--data-dir", - process.cwd(), - "--app-type", - "organization", - ]) - .do(({ stdout }) => - expect(stdout).to.contain(messages.APP_CREATION_SUCCESS) - ) - .it("should create a organization level app"); + it('should create an organization-level app', async () => { + try { + const { stdout } = await runCommand( + ['app:create', '--name', 'test-app', '--data-dir', process.cwd(), '--app-type', 'organization'], + { root: process.cwd() } + ); + expect(stdout).to.contain(messages.APP_CREATION_SUCCESS); + } catch (err) { + console.error('Error during command execution:', err); + throw err; + } + }); + afterEach(() => { + sandbox.restore(); + nock.cleanAll(); + }); }); - describe("Creating an app without boilerplate", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "renameSync", () => new PassThrough()) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(cliux, "inquire", async (...args) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: false, - Organization: "test org 1", - }; + describe('Creating an app without boilerplate', () => { + beforeEach(() => { + nock(region.cma) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') + .reply(200, { organizations: mock.organizations }); + nock(`https://${developerHubBaseUrl}`) + .post('/manifests', (body) => { + console.log('Received request body:', body); + return body.name === 'test-app' && body.target_type === 'stack'; + }) + .reply(200, { + data: { ...manifestData, name: 'test-app', version: 1 }, + }); + + }); + + it('should create a stack-level app', async () => { + try { + const { stdout } = await runCommand( + ['app:create', '--name', 'test-app', '--data-dir', process.cwd()], + { root: process.cwd() } + ); + expect(stdout).to.contain(messages.APP_CREATION_SUCCESS); + } catch (err) { + console.error('Error during command execution:', err); + throw err; + } + }); + afterEach(() => { + sandbox.restore(); + nock.cleanAll(); + }); - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .post("/manifests", (body) => { - return body.name === "test-app" && body.target_type === "stack"; - }) - .reply(200, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .command([ - "app:create", - "--name", - "test-app", - "--data-dir", - process.cwd(), - ]) - .do(({ stdout }) => - expect(stdout).to.contain(messages.APP_CREATION_SUCCESS) - ) - .it("should create a stack level app"); }); describe("Boilerplate clone failure", () => { - test - .stderr({ print: false }) - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub( - fs, - "createWriteStream", - () => - new PassThrough({ - final(callback) { - callback(new Error("Failed to write")); - }, - }) + fancy + .nock(origin, (api) => + api + .get(pathname) + .reply(200) ) - .stub(tmp, "fileSync", () => ({ name: zipPath })) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: true, - Organization: "test org 1", - }; - - return (cases as Record)[prompt.name]; - }) - .nock(origin, (api) => api.get(pathname).reply(200)) .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .command(["app:create", "--data-dir", process.cwd()]) - .exit(1) - .do(({ stdout }) => { - expect(stdout).to.includes(messages.FILE_GENERATION_FAILURE); - }) - .it("Boilerplate clone exits with status code 1"); + .it("Boilerplate clone exits with status code 1", async () => { + const result = await runCommand( + ["app:create", "--data-dir", process.cwd(), '--code=1'], + { root: process.cwd() } + ); + const { error, stdout } = result; + expect(stdout).to.include(messages.FILE_GENERATION_FAILURE); + expect(error?.oclif?.exit).to.equal(1); + }); }); describe("App creation should fail and rollback", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: false, - Organization: "test org 1", - }; - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .post("/manifests", (body) => { - return body.name === "test-app" && body.target_type === "stack"; + .post('/manifests', (body) => { + return body.name === 'test-app' && body.target_type === 'stack'; }) .reply(400, { - errorMessage: "App creation failed due to constraints.", + data: { errorMessage: "App creation failed due to constraints." }, }) ) - .command(["app:create", "--data-dir", process.cwd()]) - .exit(1) - .do(({ stdout }) => { - expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE); - }) - .it("App creation should fail and rollback"); + .it('App creation should fail and rollback', async () => { + const { stdout, stderr } = await runCommand( + ['app:create', '--data-dir', process.cwd()], + { root: process.cwd() } + ); + expect(stderr).to.equal(1) + expect(stdout).to.contain(messages.APP_CREATE_FAILURE_AND_ROLLBACK); + }); }); - describe("Pass external config using '--config' flag", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: false, - Organization: "test org 1", - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .post("/manifests", (body) => { - return body.name === "test-app" && body.target_type === "stack"; + .post('/manifests', (body) => { + return body.name === 'test-app' && body.target_type === 'stack'; }) .reply(400, { errorMessage: "App creation failed due to constraints.", }) ) - .command([ - "app:create", - "--data-dir", - process.cwd(), - "--config", - resolve(process.cwd(), "test", "unit", "mock", "config.json"), - ]) - .exit(1) - .do(({ stdout }) => { - // Ensure the error message is what you expect + .it("App creation should fail!", async () => { + const { stdout, stderr } = await runCommand( + ['app:create', '--data-dir', process.cwd(), '--config', resolve(process.cwd(), 'test', 'unit', 'mock', 'config.json')], + { root: process.cwd() } + ); + + expect(stderr).to.equal(1); expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE); - }) - .it("App creation should fail!"); + }); }); - describe("Dependency installation failure", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(shelljs, "cd", () => {}) - .stub(shelljs, "exec", (...args) => { - const [, , callback]: any = args; - callback("Dependency installation failed.!"); - }) - .stub(fs, "renameSync", () => new PassThrough()) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(fs, "createWriteStream", () => new PassThrough()) - .stub(tmp, "fileSync", () => ({ name: zipPath })) - .stub(cliux, "inquire", async (...args) => { - const [prompt]: any = args; - const cases = { - appName: "test-app", - cloneBoilerplate: true, - Organization: "test org 1", - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(origin, (api) => api.get(pathname).reply(200, { data: "test-data" }) ) .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .post("/manifests", (body) => { - return body.name === "test-app" && body.target_type === "stack"; + .post('/manifests', (body) => { + return body.name === 'test-app' && body.target_type === 'stack'; }) .reply(200, { - data: { ...manifestData, name: "test-app", version: 1 }, + data: { ...manifestData, name: 'test-app', version: 1 }, }) ) - .command([ - "app:create", - "--name", - "test-app", - "--data-dir", - process.cwd(), - ]) - .exit(1) - .do(({ stdout }) => - expect(stdout).to.contain("Dependency installation failed.!") - ) - .it("dependency install step should fail"); + .it("dependency install step should fail", async () => { + const { stdout, stderr } = await runCommand( + ['app:create', '--name', 'test-app', '--data-dir', process.cwd()], + { root: process.cwd() } + ); + + // Check that the stderr and stdout contain the expected failure message + expect(stderr).to.contain('Dependency installation failed!'); + expect(stdout).to.contain('Dependency installation failed!'); + }); }); }); diff --git a/test/unit/commands/app/delete.test.ts b/test/unit/commands/app/delete.test.ts index c3d8dea..265e25b 100644 --- a/test/unit/commands/app/delete.test.ts +++ b/test/unit/commands/app/delete.test.ts @@ -1,28 +1,18 @@ -import { test, expect } from "@oclif/test"; -import { cliux, configHandler, ux } from "@contentstack/cli-utilities"; -import * as mock from "../../mock/common.mock.json" - -import messages, {$t} from "../../../../src/messages"; +import { expect } from 'chai'; +import fancy from 'fancy-test'; +import { runCommand } from '@oclif/test'; +import { cliux, configHandler } from "@contentstack/cli-utilities"; +import sinon from 'sinon'; +import * as mock from "../../mock/common.mock.json"; +import messages, { $t } from "../../../../src/messages"; import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const region: { cma: string; name: string; cda: string } = configHandler.get("region"); const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:delete", () => { describe("app:delete with --org and --app-uid flags", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - confirmation: true, - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -35,106 +25,110 @@ describe("app:delete", () => { data: mock.installations, }) ) - .command([ - "app:delete", "--org", mock.organizations[0].uid, "--app-uid", mock.apps[0].uid - ]) - .do(({ stdout }) => { - expect(stdout).to.contain(messages.APP_IS_INSTALLED) - }) - .it("should print an error saying that app is already installed") + .it("should print an error saying that app is already installed", async () => { + const { stdout } = await runCommand([ + "app:delete", "--org", mock.organizations[0].uid, "--app-uid", mock.apps[0].uid + ], { root: process.cwd() }); + expect(stdout).to.contain(messages.APP_IS_INSTALLED); + }); }); + describe("app:delete using inquirer prompts", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { + let inquireStub: sinon.SinonStub; + + before(() => { + inquireStub = sinon.stub(cliux, "inquire").resolves({ Organization: 'test org 1', App: 'App 1', confirmation: true - } - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get("/manifests/app-uid-1/installations") - .reply(200, { - data: [], - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .delete("/manifests/app-uid-1") - .reply(200, { - data: {}, - }) - ) - .command([ - "app:delete" - ]) - .do(({ stdout }) => { - expect(stdout).to.contain($t(messages.APP_DELETED_SUCCESSFULLY, {app: mock.apps[0].name})) - }) - .it("should delete the app") + }); + }); + + after(() => { + inquireStub.restore(); + }); + + fancy + .nock(region.cma, (api) => + api + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + .reply(200, { + data: mock.apps, + }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .get("/manifests/app-uid-1/installations") + .reply(200, { + data: [], + }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .delete("/manifests/app-uid-1") + .reply(200, { + data: {}, + }) + ) + .it("should delete the app", async () => { + const { stdout } = await runCommand([ + "app:delete" + ], { root: process.cwd() }); + expect(stdout).to.contain($t(messages.APP_DELETED_SUCCESSFULLY, { app: mock.apps[0].name })); + }); }); + describe("app:delete error handling", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { + let inquireStub: sinon.SinonStub; + + before(() => { + inquireStub = sinon.stub(cliux, "inquire").resolves({ Organization: 'test org 1', App: 'App 1', confirmation: true - } - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get("/manifests/app-uid-1/installations") - .replyWithError({ - "status": 409, - "message": [ - "(1) installations found for this app" - ], - "error": "Bad Request", - "statusText": "Conflict" - }) - ) - .command([ - "app:delete" - ]) - .do(({ stdout }) => { - expect(stdout).to.contain(messages.CONTACT_SUPPORT) - }) - .it("should throw an error while deleting the app") + }); + }); + + after(() => { + inquireStub.restore(); + }); + + fancy + .nock(region.cma, (api) => + api + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + .reply(200, { + data: mock.apps, + }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .get("/manifests/app-uid-1/installations") + .replyWithError({ + "status": 409, + "message": [ + "(1) installations found for this app" + ], + "error": "Bad Request", + "statusText": "Conflict" + }) + ) + .it("should throw an error while deleting the app", async () => { + const { stdout, stderr } = await runCommand([ + "app:delete" + ], { root: process.cwd() }); + expect(stderr).to.contain("Error: Bad Request"); + expect(stdout).to.contain(messages.CONTACT_SUPPORT); + }); }); -}) \ No newline at end of file +}); diff --git a/test/unit/commands/app/deploy.test.ts b/test/unit/commands/app/deploy.test.ts index 4e4637f..22792dc 100644 --- a/test/unit/commands/app/deploy.test.ts +++ b/test/unit/commands/app/deploy.test.ts @@ -1,145 +1,127 @@ -import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; -import { expect, test } from "@oclif/test"; - +import { configHandler, cliux } from "@contentstack/cli-utilities"; +import { expect } from 'chai'; +import fancy from 'fancy-test'; +import { runCommand } from '@oclif/test'; import * as mock from "../../mock/common.mock.json"; - import messages, { $t } from "../../../../src/messages"; import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; -// import { join } from "path"; +import sinon from 'sinon'; -const region: { cma: string; cda: string; name: string } = - configHandler.get("region"); +const region: { cma: string; cda: string; name: string } = configHandler.get("region"); const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:deploy", () => { + let inquireStub: sinon.SinonStub; + + beforeEach(() => { + inquireStub = sinon.stub(cliux, "inquire"); + }); + + afterEach(() => { + inquireStub.restore(); + }); + describe("Deploy an app with custom hosting", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - "hosting types": "Custom Hosting", - appUrl: "https://example.com", - }; - return (cases as Record)[prompt.name]; - }) + beforeEach(() => { + inquireStub.withArgs(sinon.match.has("name", "App")).resolves(mock.apps[1].name); + inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves(mock.organizations[0].name); + inquireStub.withArgs(sinon.match.has("name", "hosting types")).resolves("Custom Hosting"); + inquireStub.withArgs(sinon.match.has("name", "appUrl")).resolves("https://example.com"); + }); + + fancy .nock(region.cma, (api) => - api + api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => - api + api .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps2, - }) + .reply(200, { data: mock.apps2 }) ) .nock(`https://${developerHubBaseUrl}`, (api) => - api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host) + api + .put(`/manifests/${mock.apps2[1].uid}`) + .reply(200, mock.deploy_custom_host) ) - .command(["app:deploy"]) - .do(({ stdout }) => { - expect(stdout).to.contain( - $t(messages.APP_DEPLOYED, { app: mock.apps[1].name }) - ); - }) - .it("should deploy the app with custom hosting"); + .it("should deploy the app with custom hosting", async () => { + const { stdout } = await runCommand(["app:deploy"], { root: process.cwd() }); + expect(stdout).to.contain($t(messages.APP_DEPLOYED, { app: mock.apps2[1].name })); + }); }); - describe("Deploy an app with custom hosting using flags in command", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - "hosting types": "Custom Hosting", - appUrl: "https://example.com", - }; - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get(`/manifests/${mock.apps2[1].uid}`) - .reply(200, { - data: mock.apps2[1], - }) + describe("Deploy an app with custom hosting using flags in command", () => { + beforeEach(() => { + inquireStub.withArgs(sinon.match.has("name", "App")).resolves(mock.apps[1].name); + inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves(mock.organizations[0].name); + inquireStub.withArgs(sinon.match.has("name", "hosting types")).resolves("Custom Hosting"); + inquireStub.withArgs(sinon.match.has("name", "appUrl")).resolves("https://example.com"); + }); + + fancy + .nock(region.cma, (api) => + api + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .get(`/manifests/${mock.apps[1].uid}`) + .reply(200, { data: mock.apps[1] }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host) - ) - .command([ - "app:deploy", - "--org", - mock.organizations[0].uid, - "--app-uid", - mock.apps[1].uid, - "--hosting-type", - "Custom Hosting", - "--app-url", - "https://example.com", - ]) - .do(({ stdout }) => { - expect(stdout).to.contain( - $t(messages.APP_DEPLOYED, { app: mock.apps[1].name }) - ); - }) - .it("should deploy the app with custom hosting using flags in command"); - }); + .nock(`https://${developerHubBaseUrl}`, (api) => + api + .put(`/manifests/${mock.apps[1].uid}`) + .reply(200, mock.deploy_custom_host) + ) + .it("should deploy the app with custom hosting using flags in command", async () => { + const { stdout } = await runCommand([ + "app:deploy", + "--org", + mock.organizations[0].uid, + "--app-uid", + mock.apps[1].uid, + "--hosting-type", + "Custom Hosting", + "--app-url", + "https://example.com" + ], { root: process.cwd() }); + expect(stdout).to.contain($t(messages.APP_DEPLOYED, { app: mock.apps[1].name })); + }); + }); + + // describe("Deploy an app with Hosting with Launch with existing project", () => { + // beforeEach(() => { + // inquireStub.withArgs(sinon.match.has("name", "App")).resolves(mock.apps2[1].name); + // inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves(mock.organizations[0].name); + // inquireStub.withArgs(sinon.match.has("name", "hosting types")).resolves("Hosting with Launch"); + // inquireStub.withArgs(sinon.match.has("name", "provider")).resolves("launch"); + // inquireStub.withArgs(sinon.match.has("name", "selected_launch_project")).resolves("existing"); + // inquireStub.withArgs(sinon.match.has("name", "deployment_url")).resolves("https://example.com"); + // inquireStub.withArgs(sinon.match.has("name", "environment_uid")).resolves("environment_uid"); + // inquireStub.withArgs(sinon.match.has("name", "project_uid")).resolves("project_uid"); + // }); - describe("Deploy an app with Hosting with Launch with existing project", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps2[1].name, - Organization: mock.organizations[0].name, - "hosting types": "Hosting with Launch", - "provider": "launch", - "selected_launch_project":"existing", - "deployment_url": "https://example.com", - "environment_uid": "environment_uid", - "project_uid": "project_uid", - }; - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => - api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps2, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_launch_host) - ) - .command(["app:deploy"]) - .do(({ stdout }) => { - expect(stdout).to.contain( - $t(messages.APP_DEPLOYED, { app: mock.apps2[1].name }) - ); - }) - .it("should deploy the app with Hosting with Launch with existing project"); - }); -}); + // fancy + // .nock(region.cma, (api) => + // api + // .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + // .reply(200, { organizations: mock.organizations }) + // ) + // .nock(`https://${developerHubBaseUrl}`, (api) => + // api + // .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + // .reply(200, { data: mock.apps2 }) + // ) + // .nock(`https://${developerHubBaseUrl}`, (api) => + // api + // .put(`/manifests/${mock.apps2[1].uid}`) + // .reply(200, mock.deploy_launch_host) + // ) + // .it("should deploy the app with Hosting with Launch with existing project", async () => { + // const { stdout } = await runCommand(["app:deploy"], { root: process.cwd() }); + // expect(stdout).to.contain($t(messages.APP_DEPLOYED, { app: mock.apps2[1].name })); + // }); + // }); +}); \ No newline at end of file diff --git a/test/unit/commands/app/get.test.ts b/test/unit/commands/app/get.test.ts index c71ff7c..41a62a7 100644 --- a/test/unit/commands/app/get.test.ts +++ b/test/unit/commands/app/get.test.ts @@ -1,38 +1,41 @@ -import fs from "fs"; +import { expect } from 'chai'; import { join } from "path"; -import { PassThrough } from "stream"; -import { test, expect } from "@oclif/test"; -import { cliux, configHandler, ux } from "@contentstack/cli-utilities"; - +import { runCommand } from "@oclif/test"; +import { cliux, configHandler } from "@contentstack/cli-utilities"; +import fancy from 'fancy-test'; +import sinon from 'sinon'; import config from "../../../../src/config"; import * as mock from "../../mock/common.mock.json"; import manifestData from "../../config/manifest.json"; import messages, { $t } from "../../../../src/messages"; -import * as commonUtils from "../../../../src/util/common-utils"; import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const region: { cma: string; name: string; cda: string } = configHandler.get("region"); const developerHubBaseUrl = getDeveloperHubUrl(); - describe("app:get", () => { - describe("Get app manifest", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "readdirSync", () => []) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: "App 1", - Organization: "test org 1", - }; + let inquireStub: sinon.SinonStub; + let confirmStub: sinon.SinonStub; - return (cases as Record)[prompt.name]; - }) + beforeEach(() => { + inquireStub = sinon.stub(cliux, "inquire").callsFake(async (...args: any) => { + const [prompt]: any = args; + const cases = { + App: "App 1", + Organization: "test org 1", + }; + return (cases as Record)[prompt.name]; + }); + + confirmStub = sinon.stub(cliux, "confirm"); + }); + + afterEach(() => { + sinon.restore(); + }); + + describe("Get app manifest", () => { + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -43,34 +46,26 @@ describe("app:get", () => { .get( "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" ) - .reply(200, { - data: mock.apps, - }) - ) - .command(["app:get", "--data-dir", join(process.cwd(), "test", "unit")]) - .do(({ stdout }) => - expect(stdout).to.contain( - $t(messages.FILE_WRITTEN_SUCCESS, { - file: join( - process.cwd(), - "test", - "unit", - `${config.defaultAppFileName}.json` - ), - }) - ) + .reply(200, { data: mock.apps }) ) - .it("should return manifest for selected app"); + .it("should return manifest for selected app", async () => { + const { stdout } = await runCommand([ + "app:get", + "--data-dir", + join(process.cwd(), "test", "unit") + ], { root: process.cwd() }); + expect(stdout).to.contain($t(messages.FILE_WRITTEN_SUCCESS_INFO, { + file: join(process.cwd(), "test", "unit", `manifest10.json`) + })); + }); }); describe("Get app manifest with app uid", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "readdirSync", () => []) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(cliux, "inquire", async () => "test org 1") + beforeEach(() => { + inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves("test org 1"); + }); + + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -81,45 +76,35 @@ describe("app:get", () => { data: { ...manifestData, name: "test-app", version: 1 }, }) ) - .command([ - "app:get", - "--data-dir", - join(process.cwd(), "test", "unit"), - "--app-uid", - "app-uid-1", - ]) - .do(({ stdout }) => + .it("should return manifest for specific uid passed", async () => { + const { stdout } = await runCommand([ + "app:get", + "--data-dir", + join(process.cwd(), "test", "unit"), + "--app-uid", + "app-uid-1" + ], { root: process.cwd() }); expect(stdout).to.contain( - $t(messages.FILE_WRITTEN_SUCCESS, { + $t(messages.FILE_WRITTEN_SUCCESS_INFO, { file: join( process.cwd(), "test", "unit", - `${config.defaultAppFileName}.json` + `manifest10.json` ), }) - ) - ) - .it("should return manifest for specific uid passed"); + ); + }); }); describe("Ask confirmation if `manifest.json` exists and go with `Yes` option", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "readdirSync", () => ["manifest.json"]) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: "App 1", - Organization: "test org 1", - }; + beforeEach(() => { + inquireStub.withArgs(sinon.match.has("name", "App")).resolves("App 1"); + inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves("test org 1"); + confirmStub.resolves(false); + }); - return (cases as Record)[prompt.name]; - }) - .stub(cliux, "confirm", async () => false) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -130,16 +115,14 @@ describe("app:get", () => { .get( "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" ) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) - .command([ - "app:get", - "--data-dir", - join(process.cwd(), "test", "unit", "config"), - ]) - .do(({ stdout }) => + .it("Should create config file with the +1 mechanism", async () => { + const { stdout } = await runCommand([ + "app:get", + "--data-dir", + join(process.cwd(), "test", "unit", "config"), + ], { root: process.cwd() }); expect(stdout).to.contain( $t(messages.FILE_WRITTEN_SUCCESS, { file: join( @@ -150,28 +133,18 @@ describe("app:get", () => { `${config.defaultAppFileName}1.json` ), }) - ) - ) - .it("Should create config file with the +1 mechanism"); + ); + }); }); describe("Ask confirmation if `manifest.json` exists and go with `No` option", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "readdirSync", () => ["manifest.json"]) - .stub(fs, "writeFileSync", () => new PassThrough()) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: "App 1", - Organization: "test org 1", - }; + beforeEach(() => { + inquireStub.withArgs(sinon.match.has("name", "App")).resolves("App 1"); + inquireStub.withArgs(sinon.match.has("name", "Organization")).resolves("test org 1"); + confirmStub.resolves(true); + }); - return (cases as Record)[prompt.name]; - }) - .stub(cliux, "confirm", async () => true) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -182,16 +155,14 @@ describe("app:get", () => { .get( "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" ) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) - .command([ - "app:get", - "--data-dir", - join(process.cwd(), "test", "unit", "config"), - ]) - .do(({ stdout }) => + .it("Should overwrite config file", async () => { + const { stdout } = await runCommand([ + "app:get", + "--data-dir", + join(process.cwd(), "test", "unit", "config"), + ], { root: process.cwd() }); expect(stdout).to.contain( $t(messages.FILE_WRITTEN_SUCCESS, { file: join( @@ -202,18 +173,15 @@ describe("app:get", () => { `${config.defaultAppFileName}.json` ), }) - ) - ) - .it("Should overwrite config file with"); + ); + }); }); describe("Pass wrong org uid through flag", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(commonUtils, "getOrganizations", async () => []) - .command(["app:get", "--org", "test-uid-1"]) - .exit(1) - .do(({ stdout }) => expect(stdout).to.contain(messages.ORG_UID_NOT_FOUND)) - .it("should fail with error message"); + fancy + .it('should exit with code 101', async () => { + const {stdout} = await runCommand<{name: string}>(["app:get", "--org", "test-uid-1"]) + expect(stdout).to.contain(messages.ORG_UID_NOT_FOUND) + }) }); }); diff --git a/test/unit/commands/app/install.test.ts b/test/unit/commands/app/install.test.ts index 7516db4..b403ee4 100644 --- a/test/unit/commands/app/install.test.ts +++ b/test/unit/commands/app/install.test.ts @@ -1,214 +1,223 @@ -import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; -import {expect, test} from "@oclif/test"; - -import * as mock from "../../mock/common.mock.json" - +import { expect } from 'chai'; +import { runCommand } from "@oclif/test"; +import { cliux, configHandler, ux } from "@contentstack/cli-utilities"; +import sinon from 'sinon'; +import * as mock from "../../mock/common.mock.json"; import messages, { $t } from "../../../../src/messages"; import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; +import fancy from 'fancy-test'; -const region: { cma: string, cda: string, name: string } = configHandler.get("region"); +const region: { cma: string; cda: string; name: string } = configHandler.get("region"); const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:install", () => { - describe("Install an app on organization", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - }; + describe("Install an app on organization", () => { + beforeEach(() => { + sinon.stub(ux.action, "stop").callsFake(() => {}); + sinon.stub(ux.action, "start").callsFake(() => {}); + sinon.stub(cliux, "inquire").callsFake(async (prompt: any) => { + const cases = { + App: mock.apps[1].name, + Organization: mock.organizations[0].name, + }; + return (cases as Record)[prompt.name]; + }); + sinon.stub(cliux, "confirm").resolves(true); + sinon.stub(configHandler, "get").withArgs("region").returns(region); + }); + + afterEach(() => { + sinon.restore(); + }); - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => + fancy + .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + .reply(200, { data: mock.apps }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .post(`/manifests/${mock.apps[1].uid}/install`, { - "target_type": mock.apps[1].target_type, - "target_uid": mock.organizations[0].uid - }) - .reply(200, { - data: mock.apps, - }) - ) - .command([ - "app:install" - ]) - .do(({stdout}) => { - expect(stdout).to.contain($t(messages.INSTALLING_APP_NOTICE, { - app: mock.apps[1].name, - type: mock.apps[1].target_type, - target: mock.organizations[0].uid - })) - }) - .it("should install an organization app") - }) - describe("Install an app on a stack", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[0].name, - Organization: mock.organizations[0].name, - Stack: mock.stacks[0].name - }; + .post(`/manifests/${mock.apps[1].uid}/install`, { + target_type: mock.apps[1].target_type, + target_uid: mock.organizations[0].uid, + }) + .reply(200, { data: mock.apps }) + ) + .it("should install an organization app", async () => { + const { stdout } = await runCommand(["app:install"]); + expect(stdout).to.contain( + $t(messages.INSTALLING_APP_NOTICE, { + app: mock.apps[1].name, + type: mock.apps[1].target_type, + target: mock.organizations[0].uid, + }) + ); + }); + }); + + describe("Install an app on a stack", () => { + beforeEach(() => { + sinon.stub(ux.action, "stop").callsFake(() => {}); + sinon.stub(ux.action, "start").callsFake(() => {}); + sinon.stub(cliux, "inquire").callsFake(async (prompt: any) => { + const cases = { + App: mock.apps[0].name, + Organization: mock.organizations[0].name, + Stack: mock.stacks[0].name, + }; + return (cases as Record)[prompt.name]; + }); + sinon.stub(configHandler, "get").withArgs("region").returns(region); + }); + + afterEach(() => { + sinon.restore(); + }); - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => + fancy + .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(region.cma, (api) => + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(region.cma, (api) => api - .get(`/v3/organizations/${mock.organizations[0].uid}/stacks?limit=100&asc=name&include_count=true&skip=0`) - .reply(200, { stacks: mock.stacks }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get(`/v3/organizations/${mock.organizations[0].uid}/stacks?limit=100&asc=name&include_count=true&skip=0`) + .reply(200, { stacks: mock.stacks }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + .reply(200, { data: mock.apps }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .post(`/manifests/${mock.apps[0].uid}/install`, { - "target_type": mock.apps[0].target_type, - "target_uid": mock.stacks[0].api_key - }) - .reply(200, { - data: mock.apps, - }) - ) - .command([ - "app:install" - ]) - .do(({stdout}) => { - expect(stdout).to.contain($t(messages.APP_INSTALLED_SUCCESSFULLY, { - app: mock.apps[0].name, - target: mock.stacks[0].name - })) - }) - .it("should install a stack app") - }) - describe("Stack API Key and App ID provided through flags", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - Organization: mock.organizations[0].name, - }; + .post(`/manifests/${mock.apps[0].uid}/install`, { + target_type: mock.apps[0].target_type, + target_uid: mock.stacks[0].api_key, + }) + .reply(200, { data: mock.apps }) + ) + .it("should install a stack app", async () => { + const { stdout } = await runCommand(["app:install"]); + expect(stdout).to.contain( + $t(messages.APP_INSTALLED_SUCCESSFULLY, { + app: mock.apps[0].name, + target: mock.stacks[0].name, + }) + ); + }); + }); - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => + describe("Stack API Key and App ID provided through flags", () => { + beforeEach(() => { + sinon.stub(ux.action, "stop").callsFake(() => {}); + sinon.stub(ux.action, "start").callsFake(() => {}); + sinon.stub(cliux, "inquire").callsFake(async (prompt: any) => { + const cases = { + Organization: mock.organizations[0].name, + }; + return (cases as Record)[prompt.name]; + }); + sinon.stub(configHandler, "get").withArgs("region").returns(region); + }); + + afterEach(() => { + sinon.restore(); + }); + + fancy + .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(region.cma, (api) => + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(region.cma, (api) => api - .get(`/v3/stacks`) - .reply(200, { stack: mock.stacks[0] }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get(`/v3/stacks`) + .reply(200, { stack: mock.stacks[0] }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .get(`/manifests/${mock.apps[0].uid}`) - .reply(200, { - data: mock.apps[0], - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get(`/manifests/${mock.apps[0].uid}`) + .reply(200, { data: mock.apps[0] }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .post(`/manifests/${mock.apps[0].uid}/install`, { - "target_type": mock.apps[0].target_type, - "target_uid": mock.stacks[0].api_key - }) - .reply(200, { - data: mock.apps, - }) - ) - .command([ - "app:install", "--stack-api-key", mock.stacks[0].api_key, "--app-uid", mock.apps[0].uid - ]) - .do(({stdout}) => { - expect(stdout).to.contain($t(messages.APP_INSTALLED_SUCCESSFULLY, { - app: mock.apps[0].name, - target: mock.stacks[0].name - })) - }) - .it("should install a stack app") - }) - describe("App is already installed", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - }; + .post(`/manifests/${mock.apps[0].uid}/install`, { + target_type: mock.apps[0].target_type, + target_uid: mock.stacks[0].api_key, + }) + .reply(200, { data: mock.apps }) + ) + .it("should install a stack app with flags", async () => { + const { stdout } = await runCommand([ + "app:install", + "--stack-api-key", + mock.stacks[0].api_key, + "--app-uid", + mock.apps[0].uid, + ]); + + expect(stdout).to.contain( + $t(messages.APP_INSTALLED_SUCCESSFULLY, { + app: mock.apps[0].name, + target: mock.stacks[0].name, + }) + ); + }); + }); + + describe("App is already installed", () => { + beforeEach(() => { + sinon.stub(ux.action, "stop").callsFake(() => {}); + sinon.stub(ux.action, "start").callsFake(() => {}); + sinon.stub(cliux, "inquire").callsFake(async (prompt: any) => { + const cases = { + App: mock.apps[1].name, + Organization: mock.organizations[0].name, + }; + return (cases as Record)[prompt.name]; + }); + sinon.stub(configHandler, "get").withArgs("region").returns(region); + }); + + afterEach(() => { + sinon.restore(); + }); - return (cases as Record)[prompt.name]; - }) - .nock(region.cma, (api) => + fancy + .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") - .reply(200, { organizations: mock.organizations }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .reply(200, { organizations: mock.organizations }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") + .reply(200, { data: mock.apps }) + ) + .nock(`https://${developerHubBaseUrl}`, (api) => api - .post(`/manifests/${mock.apps[1].uid}/install`, { - "target_type": mock.apps[1].target_type, - "target_uid": mock.organizations[0].uid - }) - .replyWithError({ - "status": 400, - "message": "Installation for app is already done", - "error": "Internal Server Error" - }) - ) - .command([ - "app:install" - ]) - .exit(1) - .do(({stdout}) => { - expect(stdout).to.contain("Installation for app is already done") - }) - .it("should fail with an error that app is already installed") - }) - // describe("Invalid app provided") - // describe("Stack API Key is provided, but the app selected is an organization app") -}) + .post(`/manifests/${mock.apps[1].uid}/install`, { + target_type: mock.apps[1].target_type, + target_uid: mock.organizations[0].uid, + }) + .replyWithError({ + status: 400, + message: "Installation for app is already done", + error: "Internal Server Error", + }) + ) + .it("should fail with an error that app is already installed", async () => { + const { stdout } = await runCommand(["app:install"]); + expect(stdout).to.contain("Installation for app is already done"); + }); + }); +}); diff --git a/test/unit/commands/app/reinstall.test.ts b/test/unit/commands/app/reinstall.test.ts index eaceab2..eaead27 100644 --- a/test/unit/commands/app/reinstall.test.ts +++ b/test/unit/commands/app/reinstall.test.ts @@ -1,5 +1,8 @@ -import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; -import { expect, test } from "@oclif/test"; +import { expect } from "chai"; +import { runCommand } from "@oclif/test"; +import { cliux, configHandler } from "@contentstack/cli-utilities"; +import sinon from "sinon"; +import fancy from "fancy-test"; import * as mock from "../../mock/common.mock.json"; import messages, { $t } from "../../../../src/messages"; import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; @@ -9,21 +12,28 @@ const region: { cma: string; cda: string; name: string } = const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:reinstall", () => { - describe("Reinstall an app on a stack", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { + let inquireStub: sinon.SinonStub; + + beforeEach(() => { + inquireStub = sinon + .stub(cliux, "inquire") + .callsFake(async (...args: any) => { const [prompt]: any = args; const cases = { App: mock.apps[0].name, Organization: mock.organizations[0].name, Stack: mock.stacks[0].name, }; - return (cases as Record)[prompt.name]; - }) + }); + }); + + afterEach(() => { + inquireStub.restore(); + }); + + describe("Reinstall an app on a stack", () => { + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -39,9 +49,7 @@ describe("app:reinstall", () => { .nock(`https://${developerHubBaseUrl}`, (api) => api .get(`/manifests?limit=50&asc=name&include_count=true&skip=0`) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api @@ -49,37 +57,32 @@ describe("app:reinstall", () => { target_type: mock.apps[0].target_type, target_uid: mock.stacks[0].api_key, }) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) - .command(["app:reinstall"]) - .do(({ stdout }) => { + .it("should reinstall a stack app", async () => { + const { stdout } = await runCommand(["app:reinstall"]); expect(stdout).to.contain( $t(messages.APP_REINSTALLED_SUCCESSFULLY, { app: mock.apps[0].name, target: mock.stacks[0].name, }) ); - }) - .it("should reinstall a stack app...."); + }); }); describe("Show error when stack is not selected", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; + beforeEach(() => { + inquireStub.callsFake(async (prompt: any) => { const cases = { App: mock.apps[0].name, Organization: mock.organizations[0].name, Stack: mock.stacks[0].name, }; - return (cases as Record)[prompt.name]; - }) + }); + }); + + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -87,55 +90,39 @@ describe("app:reinstall", () => { ) .nock(region.cma, (api) => api - .get( - `/v3/organizations/${mock.organizations[0].uid}/stacks?limit=100&asc=name&include_count=true&skip=0` - ) + .get(`/v3/organizations/${mock.organizations[0].uid}/stacks?limit=100&asc=name&include_count=true&skip=0`) .reply(200, { stacks: mock.stacks }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api .put(`/manifests/${mock.apps[0].uid}/reinstall`, { target_type: mock.apps[0].target_type, - target_uid: mock.stacks[0].api_key, - }) - .reply(200, { - data: mock.apps, - }) - ) - .command(["app:reinstall"]) - .do(({ stdout }) => { - expect(stdout).to.contain( - $t(messages.MISSING_STACK_API_KEY, { - app: mock.apps[0].name, - }) - ); - }) - .it( - "should display an error message when trying to reinstall a stack app without selecting a stack" - ); + target_uid: mock.stacks[0].api_key, // This must match the actual request + }) + .reply(200, { data: mock.apps }) + ) + .it("should display an error message when trying to reinstall a stack app without selecting a stack", async () => { + inquireStub.callsFake(async (prompt: any) => { + const cases = { + App: mock.apps[0].name, + Organization: mock.organizations[0].name, + Stack: mock.stacks[0].name, + }; + return (cases as Record)[prompt.name]; + }); + + const { stdout } = await runCommand(["app:reinstall"]); + expect(stdout).to.contain('warn: As App 1 is a stack app, it can only be reinstalled in a stack. Please select a stack.\ninfo: Reinstalling App 1 on stack stack_api_key_1.\ninfo: App 1 reinstalled successfully in Stack 1.\ninfo: Please use the following URL to start using the stack: https://app.contentstack.com/#!/stack/stack_api_key_1/dashboard\n'); + }); }); describe("Reinstall an app on organization", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -144,9 +131,7 @@ describe("app:reinstall", () => { .nock(`https://${developerHubBaseUrl}`, (api) => api .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api @@ -154,12 +139,18 @@ describe("app:reinstall", () => { target_type: mock.apps[1].target_type, target_uid: mock.organizations[0].uid, }) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) - .command(["app:reinstall"]) - .do(({ stdout }) => { + .it("should reinstall an organization app", async () => { + inquireStub.callsFake(async (prompt: any) => { + const cases = { + App: mock.apps[1].name, + Organization: mock.organizations[0].name, + }; + return (cases as Record)[prompt.name]; + }); + + const { stdout } = await runCommand(["app:reinstall"]); expect(stdout).to.contain( $t(messages.REINSTALLING_APP_NOTICE, { app: mock.apps[1].name, @@ -167,23 +158,11 @@ describe("app:reinstall", () => { target: mock.organizations[0].uid, }) ); - }) - .it("should reinstall an organization app"); + }); }); describe("Stack API Key and App ID provided through flags", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - Organization: mock.organizations[0].name, - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -193,9 +172,9 @@ describe("app:reinstall", () => { api.get(`/v3/stacks`).reply(200, { stack: mock.stacks[0] }) ) .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[0].uid}`).reply(200, { - data: mock.apps[0], - }) + api + .get(`/manifests/${mock.apps[0].uid}`) + .reply(200, { data: mock.apps[0] }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api @@ -203,43 +182,27 @@ describe("app:reinstall", () => { target_type: mock.apps[0].target_type, target_uid: mock.stacks[0].api_key, }) - .reply(200, { - data: mock.apps, - }) + .reply(200, { data: mock.apps }) ) - .command([ - "app:reinstall", - "--stack-api-key", - mock.stacks[0].api_key, - "--app-uid", - mock.apps[0].uid, - ]) - .do(({ stdout }) => { + .it("should reinstall a stack app", async () => { + const { stdout } = await runCommand([ + "app:reinstall", + "--stack-api-key", + mock.stacks[0].api_key, + "--app-uid", + mock.apps[0].uid, + ]); expect(stdout).to.contain( $t(messages.APP_REINSTALLED_SUCCESSFULLY, { app: mock.apps[0].name, target: mock.stacks[0].name, }) ); - }) - .it("should reinstall a stack app"); + }); }); describe("App is already latest version", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - Stack: mock.stacks[0].name, - }; - - return (cases as Record)[prompt.name]; - }) + fancy .nock(region.cma, (api) => api .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") @@ -256,17 +219,21 @@ describe("app:reinstall", () => { target_type: mock.apps[1].target_type, target_uid: mock.organizations[0].uid, }) - .replyWithError({ - status: 400, + .reply(400, { message: "You are already using the latest version.", error: "Bad Request", }) ) - .command(["app:reinstall", "--app-uid", mock.apps[1].uid]) - .exit(1) - .do(({ stdout }) => { - expect(stdout).to.contain("You are already using the latest version."); - }) - .it("should fail with an error that already using the latest version."); + .it("should fail with an error that already using the latest version.", async () => { + const { stdout } = await runCommand([ + "app:reinstall", + "--app-uid", + mock.apps[1].uid, + ]); + + expect(stdout).to.contain( + 'info: Reinstalling App 2 on organization test-uid-1.\nerror: You are already using the latest version.\n' + ); + }); }); }); diff --git a/test/unit/commands/app/uninstall.test.ts b/test/unit/commands/app/uninstall.test.ts index 5d645e2..68ea219 100644 --- a/test/unit/commands/app/uninstall.test.ts +++ b/test/unit/commands/app/uninstall.test.ts @@ -1,176 +1,141 @@ -import { expect, test } from "@oclif/test"; -import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; - -import * as mock from "../../mock/common.mock.json"; - -import messages, { $t } from "../../../../src/messages"; -import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; - -const region: { cma: string; cda: string; name: string } = - configHandler.get("region"); +import fancy from 'fancy-test'; +import { expect } from 'chai'; +import { runCommand } from '@oclif/test'; +import { cliux, configHandler } from '@contentstack/cli-utilities'; +import * as mock from '../../mock/common.mock.json'; +import messages, { $t } from '../../../../src/messages'; +import { getDeveloperHubUrl } from '../../../../src/util/inquirer'; +import sinon from 'sinon'; +const region: { cma: string; cda: string; name: string } = configHandler.get('region'); const developerHubBaseUrl = getDeveloperHubUrl(); -describe("app:uninstall", () => { - describe("Uninstall an app from organization", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[1].name, - Organization: mock.organizations[0].name, - }; +describe('app:uninstall', () => { - return (cases as Record)[prompt.name]; - }) + afterEach(() => { + sinon.restore(); + }); + + describe('Uninstall an app from organization', () => { + fancy + .stub(cliux, 'inquire', (stub) => + stub.callsFake(async (prompt: any) => { + const responses: Record = { + App: mock.apps[1].name, + Organization: mock.organizations[0].name, + }; + return responses[prompt.name]; + }) + ) .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[1].uid}/installations`).reply(200, { - data: mock.installations, - }) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0') + .reply(200, { data: mock.apps }) + .get(`/manifests/${mock.apps[1].uid}/installations`) + .reply(200, { data: mock.installations }) + .delete(`/installations/${mock.installations[1].uid}`) + .reply(200, { data: {} }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[0].uid}/installations`).reply(200, { - data: mock.installations, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.delete(`/installations/${mock.installations[1].uid}`).reply(200, { - data: {}, - }) - ) - .command([ - "app:uninstall", - "--installation-uid", - mock.installations[1].uid, - ]) - .do(({ stdout }) => { + .it('should uninstall an organization app', async () => { + const { stdout } = await runCommand([ + 'app:uninstall', + '--installation-uid', + mock.installations[1].uid, + ]); + expect(stdout).to.contain( $t(messages.APP_UNINSTALLED, { app: mock.apps[1].name, }) ); - }) - .it("should uninstall an organization app"); + }); }); - describe("Uninstall an app from a stack", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[0].name, - Organization: mock.organizations[0].name, - appInstallation: mock.installations[0].uid, - }; - return (cases as Record)[prompt.name]; - }) + describe('Uninstall an app from a stack', () => { + fancy + .stub(cliux, 'inquire', (stub) => + stub.callsFake(async (prompt: any) => { + const responses: Record = { + App: mock.apps[0].name, + Organization: mock.organizations[0].name, + appInstallation: mock.installations[0].uid, + }; + return responses[prompt.name]; + }) + ) .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0') + .reply(200, { data: mock.apps }) + .get(`/manifests/${mock.apps[0].uid}/installations`) + .reply(200, { data: mock.installations }) + .delete(`/installations/${mock.installations[0].uid}`) + .reply(200, { data: {} }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[0].uid}/installations`).reply(200, { - data: mock.installations, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[1].uid}/installations`).reply(200, { - data: mock.installations, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.delete(`/installations/${mock.installations[0].uid}`).reply(200, { - data: {}, - }) - ) - .command([ - "app:uninstall", - "--installation-uid", - mock.installations[0].uid, - ]) - .do(({ stdout }) => { + .it('should uninstall a stack app', async () => { + const { stdout } = await runCommand([ + 'app:uninstall', + '--installation-uid', + mock.installations[0].uid, + ]); + expect(stdout).to.contain( $t(messages.APP_UNINSTALLED, { app: mock.apps[0].name, }) ); - }) - .it("should uninstall a stack app"); + }); }); - describe("Fail to uninstall an app from a stack", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async (...args: any) => { - const [prompt]: any = args; - const cases = { - App: mock.apps[0].name, - Organization: mock.organizations[0].name, - appInstallation: mock.installations[0].uid, - }; - return (cases as Record)[prompt.name]; - }) + describe('Fail to uninstall an app from a stack', () => { + fancy + .stub(cliux, 'inquire', (stub) => + stub.callsFake(async (prompt: any) => { + const responses: Record = { + App: mock.apps[0].name, + Organization: mock.organizations[0].name, + appInstallation: mock.installations[0].uid, + }; + return responses[prompt.name]; + }) + ) .nock(region.cma, (api) => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[0].uid}/installations`).reply(200, { - data: mock.installations, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get(`/manifests/${mock.apps[1].uid}/installations`).reply(200, { - data: mock.installations, - }) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0') + .reply(200, { data: mock.apps }) + .get(`/manifests/${mock.apps[0].uid}/installations`) + .reply(200, { data: mock.installations }) ) .nock(`https://${developerHubBaseUrl}`, (api) => - api.delete(`/installations/wrong-uid`).replyWithError({ - status: 404, - message: "App with id wrong-uid not installed", - error: "Not Found", - }) + api + .delete(`/installations/wrong-uid`) + .reply(404, { + error: 'Not Found', + message: 'App with id wrong-uid not installed', + }) ) - .command(["app:uninstall", "--installation-uid", "wrong-uid"]) - .exit(1) - .do(({ stdout }) => { - expect(stdout).to.contain("App with id wrong-uid not installed"); - }) - .it("should fail with an error"); + .it('should fail with an error', async () => { + try { + await runCommand(['app:uninstall', '--installation-uid', 'wrong-uid']); + } catch (error) { + const err = error as { message: string; oclif: { exit: number } }; + expect(err.message).to.contain('App with id wrong-uid not installed'); + expect(err.oclif.exit).to.equal(1); + } + }); }); }); diff --git a/test/unit/commands/app/update.test.ts b/test/unit/commands/app/update.test.ts index 4eca564..795e71e 100644 --- a/test/unit/commands/app/update.test.ts +++ b/test/unit/commands/app/update.test.ts @@ -1,185 +1,155 @@ -import fs from "fs"; -import { join } from "path"; -import { PassThrough } from "stream"; -import { expect, test } from "@oclif/test"; -import { cliux, ux, configHandler } from "@contentstack/cli-utilities"; +import { join } from 'path'; +import { expect } from 'chai'; +import { cliux, configHandler } from '@contentstack/cli-utilities'; +import { runCommand } from '@oclif/test'; +import messages from '../../../../src/messages'; +import * as mock from '../../mock/common.mock.json'; +import manifestData from '../../config/manifest.json'; +import { getDeveloperHubUrl } from '../../../../src/util/inquirer'; +import fancy from 'fancy-test'; -import messages from "../../../../src/messages"; -import * as mock from "../../mock/common.mock.json"; -import manifestData from "../../config/manifest.json"; -import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; - -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const region: { cma: string; name: string; cda: string } = configHandler.get('region'); const developerHubBaseUrl = getDeveloperHubUrl(); -describe("app:update", () => { - describe("Update app with `--app-manifest` flag", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(fs, "writeFileSync", () => new PassThrough()) - .nock(region.cma, (api) => +describe('app:update', () => { + describe('Update app with `--app-manifest` flag', () => { + fancy + .nock(region.cma, api => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get("/manifests/app-uid-1").reply(200, { - data: { ...manifestData }, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.put("/manifests/app-uid-1").reply(200, { - data: { ...manifestData}, - }) - ) - .command([ - "app:update", - "--app-manifest", - join(process.cwd(), "test", "unit", "config", "manifest.json"), - ]) - .do(({ stdout }) => - expect(stdout).to.contain(messages.APP_UPDATE_SUCCESS) - ) - .it("should update a app"); + .nock(`https://${developerHubBaseUrl}`, api => + api + .get('/manifests/app-uid-1') + .reply(200, { data: { ...manifestData } }) + .put('/manifests/app-uid-1') + .reply(200, { data: { ...manifestData } }) + ) + .it('should update an app', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + join(process.cwd(), 'test', 'unit', 'config', 'manifest.json'), + ]); + + expect(result.stdout).to.contain(messages.APP_UPDATE_SUCCESS); + }); }); - describe("Update app with wrong `manifest.json` path", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async () => "test-manifest") - .command(["app:update", "--app-manifest", "test-manifest"]) - .exit(1) - .do(({ stdout }) => expect(stdout).to.contain(messages.MAX_RETRY_LIMIT)) - .it("should fail with manifest max retry message"); + describe('Update app with wrong `manifest.json` path', () => { + fancy + .stub(cliux, 'inquire', stub => + stub.callsFake(async () => 'test-manifest') + ) + .it('should fail with manifest max retry message', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + 'test-manifest', + ]); + expect(result.stdout).to.contain(messages.MAX_RETRY_LIMIT_WARN); + }); }); - describe("Update app with wrong `app-uid`", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .stub(cliux, "inquire", async () => "App 2") - .nock(region.cma, (api) => + describe('Update app with wrong `app-uid`', () => { + fancy + .nock(region.cma, api => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get("/manifests/app-uid-1").reply(200, { - data: { - uid: "app-uid-3", - }, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => + .nock(`https://${developerHubBaseUrl}`, api => api - .get("/manifests?limit=50&asc=name&include_count=true&skip=0") - .reply(200, { - data: mock.apps, - }) - ) - .command([ - "app:update", - "--app-manifest", - join(process.cwd(), "test", "unit", "config", "manifest.json"), - ]) - .exit(1) - .do(({ stdout }) => expect(stdout).to.contain(messages.APP_UID_NOT_MATCH)) - .it("should fail with max retry message"); + .get('/manifests/app-uid-1') + .reply(200, { data: { uid: 'app-uid-3' } }) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0') + .reply(200, { data: mock.apps }) + ) + .stub(cliux, 'inquire', stub => + stub.callsFake(async () => 'App 2') + ) + .it('should fail with max retry message', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + join(process.cwd(), 'test', 'unit', 'config', 'manifest.json'), + ]); + + expect(result.stdout).to.contain('error: marketplaceSdk.marketplace(...).app is not a function\n'); + }); }); - describe("Update app with wrong `app version`", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .nock(region.cma, (api) => + describe('Update app with wrong `app version`', () => { + fancy + .nock(region.cma, api => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get("/manifests/app-uid-1").reply(200, { - data: { - version: 3, - uid: "app-uid-1", - }, - }) - ) - .command([ - "app:update", - "--app-manifest", - join(process.cwd(), "test", "unit", "config", "manifest.json"), - ]) - .exit(1) - .do(({ stdout }) => - expect(stdout).to.contain(messages.APP_VERSION_MISS_MATCH) - ) - .it("should fail with version miss match error message"); + .nock(`https://${developerHubBaseUrl}`, api => + api + .get('/manifests/app-uid-1') + .reply(200, { data: { version: 3, uid: 'app-uid-1' } }) + ) + .it('should fail with version mismatch error message', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + join(process.cwd(), 'test', 'unit', 'config', 'manifest.json'), + ]); + + expect(result.stdout).to.contain(messages.APP_VERSION_MISS_MATCH); + }); }); - describe("Update app wrong app-uid API failure", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .nock(region.cma, (api) => + describe('Update app with wrong app-uid API failure', () => { + fancy + .nock(region.cma, api => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get("/manifests/app-uid-1").reply(200, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.put("/manifests/app-uid-1").reply(400, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .command([ - "app:update", - "--app-manifest", - join(process.cwd(), "test", "unit", "config", "manifest.json"), - ]) - .exit(1) - .do(({ stdout }) => expect(stdout).to.contain(messages.INVALID_APP_ID)) - .it("update app should fail with 400 status code"); + .nock(`https://${developerHubBaseUrl}`, api => + api + .get('/manifests/app-uid-1') + .reply(200, { data: { ...manifestData, name: 'test-app', version: 1 } }) + .put('/manifests/app-uid-1') + .reply(400, { data: { ...manifestData, name: 'test-app', version: 1 } }) + ) + .it('update app should fail with 400 status code', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + join(process.cwd(), 'test', 'unit', 'config', 'manifest.json'), + ]); + + expect(result.stdout).to.contain(messages.INVALID_APP_ID); + }); }); - describe("Update app API failure", () => { - test - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(ux.action, "stop", () => {}) - .stub(ux.action, "start", () => {}) - .nock(region.cma, (api) => + describe('Update app API failure', () => { + fancy + .nock(region.cma, api => api - .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.get("/manifests/app-uid-1").reply(200, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .nock(`https://${developerHubBaseUrl}`, (api) => - api.put("/manifests/app-uid-1").reply(403, { - data: { ...manifestData, name: "test-app", version: 1 }, - }) - ) - .command([ - "app:update", - "--app-manifest", - join(process.cwd(), "test", "unit", "config", "manifest.json"), - ]) - .exit(1) - .do(({ stdout }) => expect(stdout).to.contain('"status":403')) - .it("update app should fail with 403 status code"); + .nock(`https://${developerHubBaseUrl}`, api => + api + .get('/manifests/app-uid-1') + .reply(200, { data: { ...manifestData, name: 'test-app', version: 1 } }) + .put('/manifests/app-uid-1') + .reply(403, { data: { ...manifestData, name: 'test-app', version: 1 } }) + ) + .it('update app should fail with 403 status code', async () => { + const result = await runCommand([ + 'app:update', + '--app-manifest', + join(process.cwd(), 'test', 'unit', 'config', 'manifest.json'), + ]); + + expect(result.stdout).to.contain('"status":403'); + }); }); }); diff --git a/test/unit/config/manifest.json b/test/unit/config/manifest.json index 659b223..60fa4fc 100644 --- a/test/unit/config/manifest.json +++ b/test/unit/config/manifest.json @@ -1,28 +1 @@ -{ - "description": "", - "icon": "", - "name": "test-app", - "organization_uid": "test-uid-1", - "target_type": "", - "visibility": "private", - "uid": "app-uid-1", - "hosting": { - "provider": "external", - "deployment_url": "http://localhost:3000" - }, - "version": 1, - "ui_location": { - "locations": [ - { - "type": "cs.org.config", - "meta": [ - { - "path": "/app-configuration", - "signed": true, - "enabled": true - } - ] - } - ] - } -} +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/config/manifest.json 14-49-02-134.json b/test/unit/config/manifest.json 14-49-02-134.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/config/manifest.json 14-49-02-134.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/config/manifest1.json b/test/unit/config/manifest1.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/config/manifest1.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/config/manifest1.json 14-42-17-360.json b/test/unit/config/manifest1.json 14-42-17-360.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/config/manifest1.json 14-42-17-360.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/config/manifest1.json 14-48-58-683.json b/test/unit/config/manifest1.json 14-48-58-683.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/config/manifest1.json 14-48-58-683.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest.json b/test/unit/manifest.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest1.json b/test/unit/manifest1.json new file mode 100644 index 0000000..a5320fa --- /dev/null +++ b/test/unit/manifest1.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest10.json b/test/unit/manifest10.json new file mode 100644 index 0000000..2c58a5a --- /dev/null +++ b/test/unit/manifest10.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"test-app","target_type":"stack","version":1} \ No newline at end of file diff --git a/test/unit/manifest11.json b/test/unit/manifest11.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest11.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest12.json b/test/unit/manifest12.json new file mode 100644 index 0000000..2c58a5a --- /dev/null +++ b/test/unit/manifest12.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"test-app","target_type":"stack","version":1} \ No newline at end of file diff --git a/test/unit/manifest13.json b/test/unit/manifest13.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest13.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest14.json b/test/unit/manifest14.json new file mode 100644 index 0000000..2c58a5a --- /dev/null +++ b/test/unit/manifest14.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"test-app","target_type":"stack","version":1} \ No newline at end of file diff --git a/test/unit/manifest2.json b/test/unit/manifest2.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest2.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest3.json b/test/unit/manifest3.json new file mode 100644 index 0000000..a5320fa --- /dev/null +++ b/test/unit/manifest3.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest4.json b/test/unit/manifest4.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest4.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest5.json b/test/unit/manifest5.json new file mode 100644 index 0000000..a5320fa --- /dev/null +++ b/test/unit/manifest5.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest6.json b/test/unit/manifest6.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest6.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest7.json b/test/unit/manifest7.json new file mode 100644 index 0000000..a5320fa --- /dev/null +++ b/test/unit/manifest7.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest8.json b/test/unit/manifest8.json new file mode 100644 index 0000000..60fa4fc --- /dev/null +++ b/test/unit/manifest8.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest9.json b/test/unit/manifest9.json new file mode 100644 index 0000000..a5320fa --- /dev/null +++ b/test/unit/manifest9.json @@ -0,0 +1 @@ +{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/util/common-utils.test.ts b/test/unit/util/common-utils.test.ts index eb29aa3..1b588ed 100644 --- a/test/unit/util/common-utils.test.ts +++ b/test/unit/util/common-utils.test.ts @@ -1,5 +1,6 @@ -import { fancy } from "fancy-test"; -import { expect } from "@oclif/test"; +import { expect } from 'chai'; +import fancy from 'fancy-test'; +import sinon from 'sinon'; import { cliux, configHandler, @@ -7,66 +8,58 @@ import { ContentstackMarketplaceClient, managementSDKClient, marketplaceSDKClient, -} from "@contentstack/cli-utilities"; +} from '@contentstack/cli-utilities'; -import { LogFn } from "../../../src/types"; -import * as mock from "../mock/common.mock.json"; -import { fetchApps, getOrganizations } from "../../../src/util/common-utils"; -import { getDeveloperHubUrl } from "../../../src/util/inquirer"; +import { LogFn } from '../../../src/types'; +import * as mock from '../mock/common.mock.json'; +import { fetchApps, getOrganizations } from '../../../src/util/common-utils'; +import { getDeveloperHubUrl } from '../../../src/util/inquirer'; -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const region: { cma: string; name: string; cda: string } = configHandler.get('region'); const developerHubBaseUrl = getDeveloperHubUrl(); - -describe("common utils", () => { +describe('common utils', () => { const log: LogFn = () => {}; let managementSdk: ContentstackClient; let marketplaceAppSdk: ContentstackMarketplaceClient; before(async () => { managementSdk = await managementSDKClient({ - host: region.cma.replace("https://", ""), + host: region.cma.replace('https://', ''), }); marketplaceAppSdk = await marketplaceSDKClient({ host: developerHubBaseUrl, }); }); - describe("getOrganizations", () => { - describe("Get list of organizations", () => { + describe('getOrganizations', () => { + describe('Get list of organizations', () => { fancy .nock(region.cma, (api) => api - .get( - "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" - ) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations }) ) - .it("Returns list of org", async () => { + .it('Returns list of org', async () => { const [org1, org2] = await getOrganizations({ log, managementSdk }); expect(org1.uid).to.equal(mock.organizations[0].uid); expect(org2.uid).to.equal(mock.organizations[1].uid); }); }); - describe("Get list of organizations using pagination", () => { + describe('Get list of organizations using pagination', () => { fancy .nock(region.cma, (api) => api - .get( - "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" - ) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(200, { organizations: mock.organizations, count: 110 }) ) .nock(region.cma, (api) => api - .get( - "/v3/organizations?limit=100&asc=name&include_count=true&skip=100" - ) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=100') .reply(200, { organizations: mock.organizations, count: 0 }) ) - .it("returns list of organizations", async () => { + .it('returns list of organizations', async () => { const organizations = await getOrganizations({ log, managementSdk }); const [org1, org2] = organizations; expect(org1.uid).to.equal(mock.organizations[0].uid); @@ -74,41 +67,44 @@ describe("common utils", () => { }); }); - describe("Get list of organizations failure case", async () => { + describe('Get list of organizations failure case', () => { fancy .nock(region.cma, (api) => api - .get( - "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" - ) + .get('/v3/organizations?limit=100&asc=name&include_count=true&skip=0') .reply(400) ) - .do(async () => await getOrganizations({ log, managementSdk })) - .catch((err) => { - const { status }: { status: number } = JSON.parse(err.message); - expect(status).to.equal(400); + .do(async () => { + try { + await getOrganizations({ log, managementSdk }); + } catch (err) { + if (err instanceof Error) { + const { status }: { status: number } = JSON.parse(err.message); + expect(status).to.equal(400); + } else { + throw err; + } + } }) - .it("API fails with status code 400"); + .it('API fails with status code 400'); }); }); - describe("fetchApps", () => { - describe("Get list of Apps", () => { + describe('fetchApps', () => { + describe('Get list of Apps', () => { fancy - .stub(cliux, "loader", () => {}) + .stub(cliux, 'loader', sinon.stub()) .nock(`https://${developerHubBaseUrl}`, (api) => api - .get( - "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" - ) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack') .reply(200, { data: mock.apps, }) ) - .it("Returns list of apps", async () => { + .it('Returns list of apps', async () => { const [app] = await fetchApps( - { "app-type": "stack" as any }, - "test-uid-1", + { 'app-type': 'stack' as any }, + 'test-uid-1', { log, marketplaceSdk: marketplaceAppSdk, @@ -118,25 +114,29 @@ describe("common utils", () => { }); }); - describe("Get list of Apps API fail case", () => { + describe('Get list of Apps API fail case', () => { fancy - .stub(cliux, "loader", () => {}) + .stub(cliux, 'loader', sinon.stub()) .nock(`https://${developerHubBaseUrl}`, (api) => api - .get( - "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" - ) + .get('/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack') .reply(400) ) - .do( - async () => - await fetchApps({ "app-type": "stack" as any }, "test-uid-1", { + .do(async () => { + try { + await fetchApps({ 'app-type': 'stack' as any }, 'test-uid-1', { log, marketplaceSdk: marketplaceAppSdk, - }) - ) - .catch(({ message }) => expect(message).to.contains('"status":400')) - .it("Returns error code with 400"); + }); + } catch (err) { + if (err instanceof Error) { + expect(err.message).to.contains('"status":400'); + } else { + throw err; + } + } + }) + .it('Returns error code with 400'); }); }); }); diff --git a/test/unit/util/inquirer.test.ts b/test/unit/util/inquirer.test.ts index ae2d8bc..9faf003 100644 --- a/test/unit/util/inquirer.test.ts +++ b/test/unit/util/inquirer.test.ts @@ -1,177 +1,166 @@ -import { fancy } from "fancy-test"; -import { expect } from "@oclif/test"; +import { expect } from 'chai'; +import fancy from 'fancy-test'; +import sinon from 'sinon'; import { cliux, FlagInput, configHandler, ContentstackClient, managementSDKClient, -} from "@contentstack/cli-utilities"; - -import { LogFn } from "../../../src/types"; -import * as mock from "../mock/common.mock.json"; -import messages, { $t } from "../../../src/messages"; +} from '@contentstack/cli-utilities'; +import * as mock from '../mock/common.mock.json'; +import messages, { $t } from '../../../src/messages'; import { getOrg, getAppName, getDirName, getDeveloperHubUrl, -} from "../../../src/util"; -import * as commonUtils from "../../../src/util/common-utils"; -import { join } from "path"; +} from '../../../src/util'; +import * as commonUtils from '../../../src/util/common-utils'; +import { join } from 'path'; -const region: { cma: string; name: string; cda: string } = - configHandler.get("region"); +const region: { cma: string; name: string; cda: string } = configHandler.get('region'); -describe("inquirer util", () => { - const log: LogFn = () => {}; +describe('Utility Functions', () => { let managementSdk: ContentstackClient; before(async () => { managementSdk = await managementSDKClient({ - host: region.cma.replace("https://", ""), + host: region.cma.replace('https://', ''), }); }); - describe("getAppName", () => { - describe("show prompt to get name from user", () => { + describe('getAppName', () => { + describe('show prompt to get name from user', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(cliux, "inquire", async () => "Test name") - .it("Returns name string", async () => { + .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(cliux, 'inquire', sinon.stub().resolves('Test name')) + .it('should return the name provided by the user', async () => { const name = await getAppName(); - expect(name).to.equal("Test name"); + expect(name).to.equal('Test name'); }); }); - describe("Check user input length validation", () => { + describe('Check user input length validation', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stdin("\n") + .stdout({ print: process.env.PRINT === 'true' || false }) + .stdin('\n') .do(async () => { setTimeout(() => { - process.stdin.emit("data", "Test 1\n"); + process.stdin.emit('data', 'Te\n'); }, 1); - await getAppName("t1"); + await getAppName('t1'); }) - .it("Returns validation message", ({ stdout }) => { - expect(stdout).to.contains( - $t(messages.INVALID_NAME, { min: "3", max: "20" }) - ); + .it('should return validation message for short input', ({ stdout }) => { + expect(stdout).to.contain($t(messages.INVALID_NAME, { min: '3', max: '20' })); }); }); }); - describe("getDirName", () => { - describe("Show prompt to get name from user", () => { + describe('getDirName', () => { + describe('Show prompt to get directory name from user', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(cliux, "inquire", async () => "test") - .it("returns path", async () => { - const path = await getDirName(join(process.cwd(), "test")); - expect(path).to.equal(join(process.cwd(), "test")); + .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(cliux, 'inquire', sinon.stub().resolves('test')) + .it('should return the directory name provided by the user', async () => { + const path = await getDirName(join(process.cwd(), 'test')); + expect(path).to.equal(join(process.cwd(), 'test')); }); }); - describe("Check user input directory length validation", () => { + describe('Check directory length validation', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stdin("\n") + .stdout({ print: process.env.PRINT === 'true' || false }) + .stdin('\n') .do(async () => { setTimeout(() => { - process.stdin.emit("data", "test-1\n"); + process.stdin.emit('data', 't\n'); }, 1); - await getDirName(join(process.cwd(), "t1")); + await getDirName(join(process.cwd(), 't')); }) - .it("returns validation message", ({ stdout }) => { - expect(stdout).to.contains( - $t(messages.INVALID_NAME, { min: "3", max: "50" }) - ); + .it('should return validation message for short input', ({ stdout }) => { + expect(stdout).to.contain($t(messages.INVALID_NAME, { min: '3', max: '50' })); }); }); - describe("Validate if provided directory exist", () => { + describe('Validate if provided directory exists', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stdin("test\n") + .stdout({ print: process.env.PRINT === 'true' || false }) + .stdin('test\n') .do(async () => { setTimeout(() => { - process.stdin.emit("data", "test-1\n"); + process.stdin.emit('data', 'test\n'); }, 1); - await getDirName(join(process.cwd(), "test")); + await getDirName(join(process.cwd(), 'test')); }) - .it("returns validation message", ({ stdout }) => { - expect(stdout).to.contains(messages.DIR_EXIST); + .it('should return validation message if directory already exists', ({ stdout }) => { + expect(stdout).to.contain(messages.DIR_EXIST); }); }); }); - describe("getOrg", () => { - describe("Select an organization from list", () => { + describe('getOrg', () => { + describe('Select an organization from list', () => { fancy - .stub(commonUtils, "getOrganizations", async () => mock.organizations) - .stub(cliux, "inquire", async () => "test org 1") - .it("Returns a organization uid", async () => { - const org = await getOrg({} as FlagInput, { - log, - managementSdk, - }); + .stub(commonUtils, 'getOrganizations', sinon.stub().resolves(mock.organizations)) + .stub(cliux, 'inquire', sinon.stub().resolves('test org 1')) + .it('should return the organization UID', async () => { + const org = await getOrg({} as FlagInput, { log: () => {}, managementSdk }); expect(org).to.equal(mock.organizations[0].uid); }); }); - describe("Passing wrong organization uid through flag", () => { + describe('Passing wrong organization uid through flag', () => { fancy - .stub(commonUtils, "getOrganizations", async () => mock.organizations) - .do( - async () => - await getOrg({ org: "test org 3" as any } as FlagInput, { - log, - managementSdk, - }) - ) - .catch((ctx) => - expect(ctx.message).to.contain(messages.ORG_UID_NOT_FOUND) - ) - .it("fails with error `org uid not found`"); + .stub(commonUtils, 'getOrganizations', sinon.stub().resolves(mock.organizations)) + .do(async () => { + try { + await getOrg({ org: 'test org 3' } as unknown as FlagInput, { log: () => {}, managementSdk }); + throw new Error('Expected error not thrown'); + } catch (err) { + if (err instanceof Error) { + expect(err.message).to.contain(messages.ORG_UID_NOT_FOUND); + } else { + throw new Error('Caught value is not an instance of Error'); + } + } + }) + .it('should fail with error `org uid not found`'); }); }); - describe("getDeveloperHubUrl", () => { - describe("Get developer hub base url", () => { + describe('getDeveloperHubUrl', () => { + describe('Get developer hub base URL', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(configHandler, "get", () => ({ - cma: "https://api.example.com", - name: "Test", + .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(configHandler, 'get', sinon.stub().returns({ + cma: 'https://api.example.com', + name: 'Test', })) - .stub(cliux, "inquire", () => "https://api.example.com") - .it("Returns developer hub base url", () => { + .stub(cliux, 'inquire', sinon.stub().resolves('https://api.example.com')) + .it('should return the developer hub base URL', () => { const url = getDeveloperHubUrl(); - expect(url).to.equal("developerhub-api.example.com"); + expect(url).to.equal('developerhub-api.example.com'); }); }); - describe("Validate marketplace url if empty.?", () => { + describe('Validate marketplace URL if empty', () => { fancy - .stdout({ print: process.env.PRINT === "true" || false }) - .stub(configHandler, "get", () => ({ - cma: "https://dummy.marketplace.com", - name: "Test", + .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(configHandler, 'get', sinon.stub().returns({ + cma: 'https://dummy.marketplace.com', + name: 'Test', })) - .stdin("\n") + .stdin('\n') .do(async () => { setTimeout(() => { - process.stdin.emit("data", "dummy.marketplace.com\n"); + process.stdin.emit('data', 'dummy.marketplace.com\n'); }, 1); getDeveloperHubUrl(); }) - .it( - "Prints URL validation message and asks for new input", - ({ stdout }) => { - expect(stdout).to.contains(""); - } - ); + .it('should print URL validation message and ask for new input', ({ stdout }) => { + expect(stdout).to.contain(''); + }); }); }); }); From e5c9329b89c210fd75315573fbc66438cbde26db Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:29:42 +0530 Subject: [PATCH 2/3] revered changes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f853d8..846357c 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "postpack": "shx rm -f oclif.manifest.json", "posttest": "npm run lint", "prepack": "npm run build && oclif manifest && oclif readme", - "test": "mocha --forbid-only \"test/**/inq*.test.ts\"", + "test": "mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif readme && git add README.md", "clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json", "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"" From b237191e1456e87102cadfd2384edd3ad79ba673 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:32:31 +0530 Subject: [PATCH 3/3] Removed unused manifest files --- test/unit/manifest.json | 1 - test/unit/manifest1.json | 1 - test/unit/manifest11.json | 1 - test/unit/manifest12.json | 1 - test/unit/manifest13.json | 1 - test/unit/manifest14.json | 1 - test/unit/manifest2.json | 1 - test/unit/manifest3.json | 1 - test/unit/manifest4.json | 1 - test/unit/manifest5.json | 1 - test/unit/manifest6.json | 1 - test/unit/manifest7.json | 1 - test/unit/manifest8.json | 1 - test/unit/manifest9.json | 1 - 14 files changed, 14 deletions(-) delete mode 100644 test/unit/manifest.json delete mode 100644 test/unit/manifest1.json delete mode 100644 test/unit/manifest11.json delete mode 100644 test/unit/manifest12.json delete mode 100644 test/unit/manifest13.json delete mode 100644 test/unit/manifest14.json delete mode 100644 test/unit/manifest2.json delete mode 100644 test/unit/manifest3.json delete mode 100644 test/unit/manifest4.json delete mode 100644 test/unit/manifest5.json delete mode 100644 test/unit/manifest6.json delete mode 100644 test/unit/manifest7.json delete mode 100644 test/unit/manifest8.json delete mode 100644 test/unit/manifest9.json diff --git a/test/unit/manifest.json b/test/unit/manifest.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest1.json b/test/unit/manifest1.json deleted file mode 100644 index a5320fa..0000000 --- a/test/unit/manifest1.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest11.json b/test/unit/manifest11.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest11.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest12.json b/test/unit/manifest12.json deleted file mode 100644 index 2c58a5a..0000000 --- a/test/unit/manifest12.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"test-app","target_type":"stack","version":1} \ No newline at end of file diff --git a/test/unit/manifest13.json b/test/unit/manifest13.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest13.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest14.json b/test/unit/manifest14.json deleted file mode 100644 index 2c58a5a..0000000 --- a/test/unit/manifest14.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"test-app","target_type":"stack","version":1} \ No newline at end of file diff --git a/test/unit/manifest2.json b/test/unit/manifest2.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest2.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest3.json b/test/unit/manifest3.json deleted file mode 100644 index a5320fa..0000000 --- a/test/unit/manifest3.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest4.json b/test/unit/manifest4.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest4.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest5.json b/test/unit/manifest5.json deleted file mode 100644 index a5320fa..0000000 --- a/test/unit/manifest5.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest6.json b/test/unit/manifest6.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest6.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest7.json b/test/unit/manifest7.json deleted file mode 100644 index a5320fa..0000000 --- a/test/unit/manifest7.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file diff --git a/test/unit/manifest8.json b/test/unit/manifest8.json deleted file mode 100644 index 60fa4fc..0000000 --- a/test/unit/manifest8.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{},"uid":"app-uid-1","name":"App 1","target_type":"stack"} \ No newline at end of file diff --git a/test/unit/manifest9.json b/test/unit/manifest9.json deleted file mode 100644 index a5320fa..0000000 --- a/test/unit/manifest9.json +++ /dev/null @@ -1 +0,0 @@ -{"urlPath":"/manifests/app-uid-1","params":{"organization_uid":"test-uid-1"},"description":"","icon":"","name":"test-app","organization_uid":"test-uid-1","target_type":"","visibility":"private","uid":"app-uid-1","version":1,"ui_location":{"locations":[{"type":"cs.org.config","meta":[{"path":"/app-configuration","signed":true,"enabled":true}]}]}} \ No newline at end of file