|
1 | 1 | import { fancy } from "fancy-test"; |
2 | 2 | import { expect } from "@oclif/test"; |
3 | 3 | import { |
| 4 | + cliux, |
4 | 5 | configHandler, |
5 | 6 | ContentstackClient, |
6 | 7 | managementSDKClient, |
7 | 8 | } from "@contentstack/cli-utilities"; |
8 | 9 |
|
9 | | -import { getOrganizations } from "../../../src/util/common-utils"; |
10 | | -import * as mock from "../mock/common.mock.json"; |
| 10 | +import config from "../../../src/config"; |
11 | 11 | import { LogFn } from "../../../src/types"; |
| 12 | +import * as mock from "../mock/common.mock.json"; |
| 13 | +import { fetchApps, getOrganizations } from "../../../src/util/common-utils"; |
12 | 14 |
|
13 | 15 | const region: { cma: string; name: string; cda: string } = |
14 | 16 | configHandler.get("region"); |
| 17 | +const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[ |
| 18 | + region.cma |
| 19 | +]; |
15 | 20 |
|
16 | 21 | describe("common utils", () => { |
17 | 22 | const log: LogFn = () => {}; |
18 | 23 | let managementSdk: ContentstackClient; |
| 24 | + let managementAppSdk: ContentstackClient; |
19 | 25 |
|
20 | 26 | before(async () => { |
21 | 27 | managementSdk = await managementSDKClient({ |
22 | 28 | host: region.cma.replace("https://", ""), |
23 | 29 | }); |
| 30 | + managementAppSdk = await managementSDKClient({ |
| 31 | + host: developerHubBaseUrl, |
| 32 | + }); |
24 | 33 | }); |
25 | 34 |
|
26 | 35 | describe("getOrganizations", () => { |
@@ -81,4 +90,52 @@ describe("common utils", () => { |
81 | 90 | .it("API fails with status code 400"); |
82 | 91 | }); |
83 | 92 | }); |
| 93 | + |
| 94 | + describe("fetchApps", () => { |
| 95 | + describe("Get list of Apps", () => { |
| 96 | + fancy |
| 97 | + .stub(cliux, "loader", () => {}) |
| 98 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 99 | + api |
| 100 | + .get( |
| 101 | + "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" |
| 102 | + ) |
| 103 | + .reply(200, { |
| 104 | + data: mock.apps, |
| 105 | + }) |
| 106 | + ) |
| 107 | + .it("Returns list of apps", async () => { |
| 108 | + const [app] = await fetchApps( |
| 109 | + { "app-type": "stack" as any }, |
| 110 | + "test-uid-1", |
| 111 | + { |
| 112 | + log, |
| 113 | + managementSdk: managementAppSdk, |
| 114 | + } |
| 115 | + ); |
| 116 | + expect(app.uid).to.equal(mock.apps[0].uid); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + describe("Get list of Apps API fail case", () => { |
| 121 | + fancy |
| 122 | + .stub(cliux, "loader", () => {}) |
| 123 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 124 | + api |
| 125 | + .get( |
| 126 | + "/manifests?limit=50&asc=name&include_count=true&skip=0&target_type=stack" |
| 127 | + ) |
| 128 | + .reply(400) |
| 129 | + ) |
| 130 | + .do( |
| 131 | + async () => |
| 132 | + await fetchApps({ "app-type": "stack" as any }, "test-uid-1", { |
| 133 | + log, |
| 134 | + managementSdk: managementAppSdk, |
| 135 | + }) |
| 136 | + ) |
| 137 | + .catch(({ message }) => expect(message).to.contains('"status":400')) |
| 138 | + .it("Returns error code with 400"); |
| 139 | + }); |
| 140 | + }); |
84 | 141 | }); |
0 commit comments