Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Protocol = "http" | "https";
type Domain = `${string}.${string}` | `localhost`;
type Domain = "localhost" | (string & {});
type Port = `:${number}`;
type Path = `/${string}${string}`;

Expand Down
22 changes: 3 additions & 19 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ describe("default configuration management", () => {

const config2 = configure({
apiKey: "api-key-2",
nodes: [
// @ts-expect-error - this host is invalid
{ host: "different-host", port: 8109, protocol: "https" },
],
nodes: [{ host: "different-host", port: 8109, protocol: "https" }],
});

setDefaultConfiguration(config1);
Expand Down Expand Up @@ -201,16 +198,12 @@ describe("default configuration management", () => {
it("should return provided config when given", () => {
const defaultConfig = configure({
apiKey: "default-key",
// @ts-expect-error - this host is invalid
nodes: [{ host: "default-host", port: 8108, protocol: "http" }],
});

const providedConfig = configure({
apiKey: "provided-key",
nodes: [
// @ts-expect-error - this host is invalid
{ host: "provided-host", port: 8109, protocol: "https" },
],
nodes: [{ host: "provided-host", port: 8109, protocol: "https" }],
});

setDefaultConfiguration(defaultConfig);
Expand All @@ -222,7 +215,6 @@ describe("default configuration management", () => {
it("should return default config when no config is provided", () => {
const defaultConfig = configure({
apiKey: "default-key",
// @ts-expect-error - this host is invalid
nodes: [{ host: "default-host", port: 8108, protocol: "http" }],
});

Expand All @@ -235,10 +227,7 @@ describe("default configuration management", () => {
it("should return default config when undefined is explicitly passed", () => {
const defaultConfig = configure({
apiKey: "default-key",
nodes: [
// @ts-expect-error - this host is invalid
{ host: "default-host", port: 8108, protocol: "http" },
],
nodes: [{ host: "default-host", port: 8108, protocol: "http" }],
});

setDefaultConfiguration(defaultConfig);
Expand Down Expand Up @@ -283,13 +272,11 @@ describe("default configuration management", () => {
it("should handle multiple configurations in sequence", () => {
const config1 = configure({
apiKey: "key-1",
// @ts-expect-error - invalid host
nodes: [{ host: "host-1", port: 8108, protocol: "http" }],
});

const config2 = configure({
apiKey: "key-2",
// @ts-expect-error - invalid host
nodes: [{ host: "host-2", port: 8109, protocol: "https" }],
});

Expand All @@ -310,12 +297,9 @@ describe("default configuration management", () => {
const config = configure({
apiKey: "complex-key",
nodes: [
// @ts-expect-error - invalid host
{ host: "node1", port: 8108, protocol: "http" },
// @ts-expect-error - invalid host
{ host: "node2", port: 8109, protocol: "https" },
],
// @ts-expect-error - invalid host
nearestNode: { url: "http://nearest-node" },
randomizeNodes: true,
connectionTimeoutSeconds: 10,
Expand Down
24 changes: 0 additions & 24 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,6 @@ describe("type tests", () => {
// @ts-expect-error This is erroring as expected
const _error: UrlString = "ftp://localhost:3000";
});
it("should only let a path be prefixed with a slash", () => {
const _config: UrlString = "http://localhost:3000/a";
// @ts-expect-error This is erroring as expected
const _error: UrlString = "http://localhost:3000api";
});
it("should only let ports be numbers", () => {
const _config: UrlString = "http://localhost:3000";
// @ts-expect-error This is erroring as expected
const _error: UrlString = "http://localhost:port";
});
it("should only let domains be strings", () => {
const _config: UrlString = "http://localhost";
// @ts-expect-error This is erroring as expected
const _error: UrlString = "http://23:3000";
});
it("should not end on an empty path", () => {
const _config: UrlString = "http://localhost:3000";
// @ts-expect-error This is erroring as expected
const _error: UrlString = "http://localhost:3000/";
});
it("should let an empty path", () => {
const _port: UrlString = "http://localhost:3000";
const _empty: UrlString = "http://localhost";
});
});
});
describe("function tests", () => {
Expand Down