|
| 1 | +import { fancy } from "fancy-test"; |
| 2 | +import { expect } from "@oclif/test"; |
| 3 | +import { |
| 4 | + ContentstackClient, |
| 5 | + configHandler, |
| 6 | + managementSDKClient, |
| 7 | +} from "@contentstack/cli-utilities"; |
| 8 | + |
| 9 | +import { getOrganizations } from "../../../src/util/common-utils"; |
| 10 | +import * as mock from "../mock/common.mock.json"; |
| 11 | +import { LogFn } from "../../../src/types"; |
| 12 | + |
| 13 | +const region: { cma: string; name: string; cda: string } = |
| 14 | + configHandler.get("region"); |
| 15 | + |
| 16 | +describe("common utils", () => { |
| 17 | + const log: LogFn = () => {}; |
| 18 | + let managementSdk: ContentstackClient; |
| 19 | + |
| 20 | + before(async () => { |
| 21 | + managementSdk = await managementSDKClient({ |
| 22 | + host: region.cma.replace("https://", ""), |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe("getOrganizations", () => { |
| 27 | + describe("Get list of organizations", () => { |
| 28 | + fancy |
| 29 | + .nock(region.cma, (api) => |
| 30 | + api |
| 31 | + .get( |
| 32 | + "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" |
| 33 | + ) |
| 34 | + .reply(200, { organizations: mock.organizations }) |
| 35 | + ) |
| 36 | + .it("Returns list of org", async () => { |
| 37 | + const [org1, org2] = await getOrganizations({ log, managementSdk }); |
| 38 | + expect(org1.uid).to.equal(mock.organizations[0].uid); |
| 39 | + expect(org2.uid).to.equal(mock.organizations[1].uid); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("Get list of organizations failure case", async () => { |
| 44 | + fancy |
| 45 | + .nock(region.cma, (api) => |
| 46 | + api |
| 47 | + .get( |
| 48 | + "/v3/organizations?limit=100&asc=name&include_count=true&skip=0" |
| 49 | + ) |
| 50 | + .reply(400) |
| 51 | + ) |
| 52 | + .do(async () => await getOrganizations({ log, managementSdk })) |
| 53 | + .catch((err) => { |
| 54 | + const { status }: { status: number } = JSON.parse(err.message); |
| 55 | + expect(status).to.equal(400); |
| 56 | + }) |
| 57 | + .it("API fails with status code 400"); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments