Skip to content

Commit

Permalink
Add tests for the remaining endpoint commands
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv committed Oct 3, 2023
1 parent b362679 commit 5d1a0b3
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 51 deletions.
116 changes: 112 additions & 4 deletions test/commands/endpoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect, test } from "@oclif/test";
import { ShellConfig, getRootConfigPath } from "../../src/lib/config";
import sinon, { SinonStub } from "sinon";
import AddEndpointCommand from "../../src/commands/add-endpoint";
import AddEndpointCommand from "../../src/commands/endpoint/add";
import ListEndpointCommand from "../../src/commands/endpoint/list";
import RemoveEndpointCommand from "../../src/commands/endpoint/remove";
import { Config } from "@oclif/core";

const rootConfigPath = getRootConfigPath();
Expand All @@ -18,7 +20,7 @@ const stubbedRootConfig = (
return config as any;
};

describe("add-endpoint", () => {
describe("endpoint:add", () => {
test
.add("config", () =>
stubbedRootConfig({
Expand All @@ -45,7 +47,7 @@ describe("add-endpoint", () => {
)
.it("adds an endpoint", (ctx) => {
expect(ctx.stdout).to.equal(
`Saved endpoint foobar to ${rootConfigPath}\n`
`Warning: could not connect to Fauna\nSaved endpoint foobar to ${rootConfigPath}\n`
);
expect(ctx.config.rootConfig).to.deep.equal({
defaultEndpoint: "my-endpoint",
Expand Down Expand Up @@ -96,7 +98,7 @@ describe("add-endpoint", () => {
)
.it("sets default endpoint", (ctx) => {
expect(ctx.stdout).to.equal(
`Saved endpoint foobar to ${rootConfigPath}\n`
`Warning: could not connect to Fauna\nSaved endpoint foobar to ${rootConfigPath}\n`
);
expect(ctx.config.rootConfig).to.deep.equal({
defaultEndpoint: "foobar",
Expand All @@ -120,3 +122,109 @@ describe("add-endpoint", () => {
expect(ctx.config.saveRootConfig.calledOnce).to.be.true;
});
});

describe("endpoint:list", () => {
test
.add("config", () =>
stubbedRootConfig({
default: "my-endpoint",
"my-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
"other-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
})
)
.stdout()
.do((ctx) =>
new ListEndpointCommand([], new Config({} as any)).execute(ctx.config)
)
.it("lists endpoints", (ctx) => {
expect(ctx.stdout).to.equal(
`Available endpoints:\n* my-endpoint\n other-endpoint\n`
);
expect(ctx.config.saveRootConfig.calledOnce).to.be.false;
});
});

describe("endpoint:remove", () => {
test
.add("config", () =>
stubbedRootConfig({
default: "my-endpoint",
"my-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
"other-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
})
)
.stdout()
.do((ctx) =>
new RemoveEndpointCommand(
["other-endpoint"],
new Config({} as any)
).execute(ctx.config)
)
.it("removes an endpoint", (ctx) => {
expect(ctx.stdout).to.equal(`Removed endpoint other-endpoint.\n`);
expect(ctx.config.rootConfig).to.deep.equal({
defaultEndpoint: "my-endpoint",
endpoints: {
"my-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
// These graphql bits are only saved if they differ from the
// default.
graphqlHost: "graphql.fauna.com",
graphqlPort: 443,
},
},
});
expect(ctx.config.saveRootConfig.calledOnce).to.be.true;
});

test
.add("config", () =>
stubbedRootConfig({
default: "my-endpoint",
"my-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
"other-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
},
})
)
.stdout()
.do((ctx) =>
new RemoveEndpointCommand(["my-endpoint"], new Config({} as any)).execute(
ctx.config
)
)
.it("clears the default if needed", (ctx) => {
expect(ctx.stdout).to.equal(`Removed endpoint my-endpoint.\n`);
expect(ctx.config.rootConfig).to.deep.equal({
defaultEndpoint: undefined,
endpoints: {
"other-endpoint": {
url: "http://bar.baz",
secret: "fn3333",
// These graphql bits are only saved if they differ from the
// default.
graphqlHost: "graphql.fauna.com",
graphqlPort: 443,
},
},
});
expect(ctx.config.saveRootConfig.calledOnce).to.be.true;
});
});
47 changes: 0 additions & 47 deletions test/commands/endpoints.test.js

This file was deleted.

0 comments on commit 5d1a0b3

Please sign in to comment.